/* =====================================================================
   ML·Lab — sistem desain bergaya Material Design 3 untuk platform belajar.
   Grid spasi 8dp (token --sp-*), peran warna tonal, elevasi berlapis,
   state-layer pada interaksi. Tema terang & gelap.
   Palet: emerald/teal (nuansa "belajar") + aksen amber.
   Tipografi: Bricolage Grotesque (display) · Lexend (teks) · JetBrains Mono.
   ===================================================================== */

:root {
  /* --- skala spasi 8dp (4dp untuk penyetelan halus) --- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  /* --- bentuk (Material 3: radius lebih besar) --- */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-full: 999px;
  --radius: var(--r-md); /* alias lama */

  /* --- elevasi (Material elevation 1..4) --- */
  --e1: 0 1px 2px rgba(16, 40, 34, 0.08), 0 1px 3px rgba(16, 40, 34, 0.06);
  --e2: 0 1px 2px rgba(16, 40, 34, 0.08), 0 3px 8px rgba(16, 40, 34, 0.08);
  --e3: 0 4px 10px rgba(16, 40, 34, 0.1), 0 12px 28px rgba(16, 40, 34, 0.08);
  --e4: 0 8px 18px rgba(16, 40, 34, 0.14), 0 24px 48px rgba(16, 40, 34, 0.12);
  --shadow: var(--e2); /* alias lama */

  /* --- peran warna (Material tonal, tema terang) --- */
  --bg: #f3f7f5;
  --bg-tint: radial-gradient(1200px 600px at 85% -10%, rgba(15, 125, 99, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(217, 138, 43, 0.06), transparent 55%);
  --panel: #ffffff;
  --panel-2: #eef4f1;
  --surface-3: #e6efeb;
  --border: #d8e4df;
  --border-strong: #c2d3cc;
  --text: #11201b;
  --muted: #566b63;
  --primary: #0f7d63;
  --primary-2: #0b6450;
  --primary-container: #bdeede;
  --on-primary-container: #00382a;
  --accent: #c47a1a;
  --accent-container: #f8e6c8;
  --good: #1f7a3a;
  --bad: #c33636;
  --warn: #d99016;
  --hi: rgba(15, 125, 99, 0.1);
  --state: rgba(17, 32, 27, 0.06); /* state-layer hover netral */
  --ring: #14b8a6;

  --mono: "JetBrains Mono", "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Bricolage Grotesque", "Lexend", system-ui, sans-serif;

  --maxw: 1240px;
  --bar-h: 64px;
}

[data-theme="dark"] {
  --bg: #0e1513;
  --bg-tint: radial-gradient(1200px 600px at 85% -10%, rgba(20, 184, 166, 0.1), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(217, 138, 43, 0.07), transparent 55%);
  --panel: #161d1b;
  --panel-2: #1d2624;
  --surface-3: #232e2b;
  --border: #2b3633;
  --border-strong: #3a4844;
  --text: #e3ebe7;
  --muted: #9baba4;
  --primary: #57d6b0;
  --primary-2: #7ce4c4;
  --primary-container: #0d4a3a;
  --on-primary-container: #bdeede;
  --accent: #e7b15f;
  --accent-container: #4a3917;
  --good: #6fcf85;
  --bad: #ef7676;
  --warn: #e7c06b;
  --hi: rgba(87, 214, 176, 0.16);
  --state: rgba(227, 235, 231, 0.08);
  --ring: #2dd4bf;

  --e1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --e2: 0 2px 6px rgba(0, 0, 0, 0.45), 0 6px 16px rgba(0, 0, 0, 0.35);
  --e3: 0 8px 22px rgba(0, 0, 0, 0.5), 0 18px 40px rgba(0, 0, 0, 0.4);
  --e4: 0 12px 28px rgba(0, 0, 0, 0.55), 0 30px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
html {
  scroll-behavior: smooth;
}
body {
  background-color: var(--bg);
  background-image: var(--bg-tint);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.6;
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

/* ====== Top app bar (Material) ====== */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.app-bar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  height: var(--bar-h);
  padding: 0 var(--sp-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
  color: inherit;
  border-radius: var(--r-full);
  padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-1);
}
.brand:hover {
  background: var(--state);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(150deg, var(--primary), var(--primary-2));
  box-shadow: var(--e2), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.brand-mark svg circle {
  fill: rgba(255, 255, 255, 0.55);
}
.brand-mark svg .mark-accent {
  fill: #ffffff;
}
.brand-mark svg path {
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 2.2;
  fill: none;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-title {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.brand-dot {
  color: var(--primary);
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.app-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.course-chip {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--on-primary-container);
  background: var(--primary-container);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
}
.icon-btn {
  appearance: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--r-full);
  font-size: 1.15rem;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
}
.icon-btn:hover {
  background: var(--state);
  box-shadow: var(--e1);
}
.icon-btn:active {
  transform: scale(0.94);
}

/* utilitas: hanya untuk pembaca layar (heading a11y/SEO) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ====== Tabs (Material primary navigation tabs) ====== */
.tabs {
  position: sticky;
  top: var(--bar-h);
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 12px -10px rgba(16, 40, 34, 0.5);
}
.tabs-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--sp-5);
  display: flex;
  gap: var(--sp-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-inner::-webkit-scrollbar {
  display: none;
}
.tab {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) - 3px);
  cursor: pointer;
  position: relative;
  border-bottom: 3px solid transparent;
  border-radius: var(--r-xs) var(--r-xs) 0 0;
  transition: color 0.18s, background 0.18s;
}
.tab:hover {
  color: var(--text);
  background: var(--state);
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 0;
  height: 3px;
  background: var(--primary);
  border-radius: 3px;
  transform: translateX(-50%);
  animation: tabline 0.25s ease forwards;
}
@keyframes tabline {
  to {
    width: 70%;
  }
}

/* ====== Konten ====== */
.content {
  /* jeda secukupnya di bawah bar tab yang sticky (#3) */
  padding: var(--sp-5) var(--sp-5) var(--sp-7);
  max-width: var(--maxw);
  margin: 0 auto;
}

/* switcher mode tingkat-atas (mis. RL: Navigasi & Nilai | Belajar TD) butuh
   jarak ke konten di bawahnya */
.sim-root > .seg {
  margin-bottom: var(--sp-5);
}
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
  animation: rise 0.32s cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* ====== Layout simulator ====== */
.sim-layout {
  display: grid;
  /* minmax(0,1fr) penting: tanpa ini kolom 1fr melebar mengikuti SVG lebar
     (min-content) sehingga diagram lebar membobol layout. Dengan 0 sebagai
     batas bawah, .svg-wrap bisa men-scroll/diagram menyusut di dalam kolom. */
  grid-template-columns: 340px minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}
@media (max-width: 920px) {
  .sim-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* panel kontrol "lengket" di layar lebar agar selalu terlihat */
@media (min-width: 921px) {
  .col-controls {
    position: sticky;
    top: calc(var(--bar-h) + 56px);
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--e1);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
  transition: box-shadow 0.2s;
}
.panel:hover {
  box-shadow: var(--e2);
}
.panel h3 {
  margin: 0 0 var(--sp-4);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.panel h3::before {
  content: "";
  width: 14px;
  height: 3px;
  border-radius: 3px;
  background: var(--primary);
}
.panel h4 {
  font-family: var(--display);
  margin: var(--sp-5) 0 var(--sp-2);
  font-size: 1rem;
  font-weight: 700;
}

/* ====== Kontrol form ====== */
.field {
  margin-bottom: var(--sp-4);
}
.field > label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: var(--sp-2);
  color: var(--text);
}
.field .hint {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 400;
}
select,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: var(--sp-3) var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--panel);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus,
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--hi);
}
input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}
.range-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.range-row output {
  font-family: var(--mono);
  font-size: 0.85rem;
  min-width: 42px;
  text-align: right;
  color: var(--primary);
}

/* segmented buttons (Material 3) */
.seg {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  overflow: hidden;
  background: var(--panel);
}
.seg button {
  flex: 1;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.83rem;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button:last-child {
  border-right: none;
}
.seg button:hover {
  background: var(--state);
  color: var(--text);
}
.seg button.active {
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 700;
}
.seg.seg-sm button {
  font-size: 0.78rem;
  padding: var(--sp-2) var(--sp-1);
}

/* ====== Tombol ====== */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.86rem;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  transition: background 0.14s, box-shadow 0.14s, transform 0.05s, border-color 0.14s;
}
.btn:hover {
  background: var(--state);
  box-shadow: var(--e1);
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--e1);
}
[data-theme="dark"] .btn-primary {
  color: #06241c;
}
.btn-primary:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
  box-shadow: var(--e2);
}
.btn-primary.playing {
  background: var(--warn);
  border-color: var(--warn);
  color: #2a1c00;
}
.theme-btn {
  font-size: 1.1rem;
  padding: var(--sp-2) var(--sp-3);
}

/* ====== Step controls ====== */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  box-shadow: var(--e1);
  margin-bottom: var(--sp-4);
}
.step-indicator {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--on-primary-container);
  background: var(--primary-container);
  font-weight: 700;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  margin-left: var(--sp-1);
}
.speed {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
}
.speed input {
  width: 110px;
}

/* ====== Panel rumus ====== */
.formula-panel .step-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin-bottom: var(--sp-1);
}
.formula-panel .step-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: var(--sp-4);
}
.formula-box {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--r-xs);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-2) 0;
  overflow-x: auto;
}
.formula-box + .formula-box {
  margin-top: var(--sp-2);
}
.formula-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: var(--sp-1);
}

/* fallback math (tanpa KaTeX) */
.fallback-math {
  font-family: var(--mono);
  font-size: 1.02rem;
}
.mfrac {
  display: inline-flex;
  flex-direction: column;
  text-align: center;
  vertical-align: middle;
  margin: 0 2px;
}
.mfrac .mnum {
  border-bottom: 1px solid currentColor;
  padding: 0 4px;
}
.mfrac .mden {
  padding: 0 4px;
}

/* ====== Tabel nilai / vektor ====== */
.vtable {
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.85rem;
  margin: var(--sp-2) 0;
}
.vtable th,
.vtable td {
  border: 1px solid var(--border);
  padding: var(--sp-1) var(--sp-3);
  text-align: right;
}
.vtable th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
}
.vtable td.active,
.vtable th.active {
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 700;
}

/* ====== Diagram RNN/LSTM (kartu sel) ====== */
.cell-track {
  display: flex;
  gap: var(--sp-4);
  overflow-x: auto;
  padding: var(--sp-3) var(--sp-1);
}
.tcell {
  min-width: 120px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  background: var(--panel-2);
  text-align: center;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
.tcell.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--hi);
  transform: translateY(-2px);
}
.tcell .t-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.tcell .t-val {
  font-family: var(--mono);
  font-size: 0.8rem;
}
.gate-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}
.gate {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-3);
  background: var(--panel-2);
  opacity: 0.5;
  transition: opacity 0.2s, border-color 0.2s, transform 0.12s, box-shadow 0.2s;
}
.gate.on {
  opacity: 1;
  border-color: var(--accent);
}
.gate.current {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--hi);
  transform: translateY(-2px);
}
.gate .g-name {
  font-weight: 700;
  font-size: 0.9rem;
}
.gate .g-sub {
  font-size: 0.75rem;
  color: var(--muted);
}
.gate .g-val {
  font-family: var(--mono);
  font-size: 0.82rem;
  margin-top: var(--sp-2);
}

/* ====== Attention heatmap ====== */
.heat {
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.heat td,
.heat th {
  border: 1px solid var(--border);
  width: 52px;
  height: 40px;
  text-align: center;
  color: #0b1f18;
}
.heat th {
  color: var(--muted);
  background: var(--panel-2);
  font-weight: 600;
}
.bars {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: var(--sp-2) 0;
}
.bar-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--mono);
  font-size: 0.82rem;
}
.bar-row .bar-label {
  min-width: 60px;
  color: var(--muted);
}
.bar-track {
  flex: 1;
  background: var(--panel-2);
  border-radius: var(--r-full);
  overflow: hidden;
  height: 18px;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--r-full);
  transition: width 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.bar-row .bar-val {
  min-width: 46px;
  text-align: right;
}

/* ====== Gridworld RL ====== */
.grid-wrap {
  display: inline-block;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--e2);
}
.grid {
  display: grid;
  gap: 0;
}
.gcell {
  position: relative;
  width: 96px;
  height: 96px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  font-family: var(--mono);
  transition: background 0.2s;
}
.gcell .q {
  position: absolute;
  color: var(--text);
  opacity: 0.85;
}
.gcell .q.up {
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
}
.gcell .q.down {
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
}
.gcell .q.left {
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
}
.gcell .q.right {
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
}
.gcell .q.best {
  color: var(--primary);
  font-weight: 700;
}
.gcell .policy {
  font-size: 1.3rem;
  color: var(--primary);
  opacity: 0.5;
}
.gcell.goal {
  background: color-mix(in srgb, var(--good) 22%, transparent);
}
.gcell.trap {
  background: color-mix(in srgb, var(--bad) 22%, transparent);
}
.gcell.wall {
  background: var(--border-strong);
}
.gcell .robot {
  position: absolute;
  font-size: 1.7rem;
  z-index: 2;
  transition: all 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.gcell .vlabel {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.6rem;
  color: var(--muted);
}
.gcell.curr {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
}
.gcell.next {
  outline: 3px dashed var(--accent);
  outline-offset: -3px;
}

.legend {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: var(--sp-3);
}
.legend .sw {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  vertical-align: -2px;
  margin-right: var(--sp-1);
  border: 1px solid var(--border);
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 700;
  margin-left: var(--sp-2);
}
.note {
  font-size: 0.84rem;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: var(--sp-3) var(--sp-3);
  margin-top: var(--sp-3);
}

/* ====== Footer ====== */
.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: var(--sp-6) var(--sp-5);
  border-top: 1px solid var(--border);
  margin-top: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
#katex-status {
  font-family: var(--mono);
}

/* ====== Diagram SVG (dipakai semua tab) ====== */
.svg-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: var(--sp-1) 0;
  scrollbar-width: thin;
}
.diagram {
  display: block;
  /* menyusut mengikuti lebar kontainer (viewBox menjaga rasio) bila terlalu
     lebar -> tak pernah membobol panel & otomatis responsif di mobile.
     max-width saja (bukan width:100%) agar diagram kecil tak ikut membesar. */
  max-width: 100%;
  height: auto;
  color: var(--text);
  font-family: var(--mono);
}
.diagram .lbl {
  fill: var(--muted);
}
.diagram .node-active {
  filter: drop-shadow(0 0 5px var(--primary));
}
.ring-active {
  stroke: var(--ring);
  stroke-width: 3.5;
  fill: none;
}

/* ====== RL: views / commentary / terms / markov ====== */
.rl-views {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}
.commentary {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--r-xs);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-4);
  font-size: 0.9rem;
  color: var(--text);
  min-height: 40px;
}
.commentary strong {
  color: var(--primary);
}
.terms-panel .term-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--r-xs);
  padding: var(--sp-3) var(--sp-3);
  margin-bottom: var(--sp-2);
  transition: box-shadow 0.18s, transform 0.18s;
}
.terms-panel .term-card:hover {
  box-shadow: var(--e1);
  transform: translateX(2px);
}
.term-card .term-name {
  font-size: 0.84rem;
  font-weight: 700;
  margin-bottom: 2px;
}
.term-card .term-val {
  font-size: 0.82rem;
  color: var(--text);
  font-family: var(--mono);
}
.term-card .term-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 2px;
}
.val-gradient {
  height: 12px;
  width: 120px;
  border-radius: var(--r-full);
  background: linear-gradient(to right, #312e81, #1d4ed8, #0891b2, #059669, #16a34a);
  display: inline-block;
  vertical-align: middle;
}
.markov-grids {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}
@media (max-width: 680px) {
  .markov-grids {
    grid-template-columns: 1fr;
  }
}
.verdict {
  background: color-mix(in srgb, var(--good) 16%, transparent);
  border: 1px solid var(--good);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-4);
  text-align: center;
  font-size: 0.9rem;
}
.verdict strong {
  color: var(--good);
}

/* ====== Transformer: blok arsitektur klik ====== */
.diagram [data-comp] {
  cursor: pointer;
  transition: opacity 0.15s;
}
.diagram [data-comp]:hover {
  opacity: 0.82;
}
.comp-info {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-xs);
  padding: var(--sp-3) var(--sp-3);
  margin-top: var(--sp-3);
  font-size: 0.86rem;
  min-height: 38px;
}
.comp-info strong {
  color: var(--accent);
}

/* grid kontrol 2 kolom utk panel kontrol yang padat */
.ctl-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}

/* ====== Responsif: tablet ====== */
@media (max-width: 720px) {
  :root {
    --bar-h: 58px;
  }
  .content {
    padding: var(--sp-5) var(--sp-4) var(--sp-6);
  }
  .app-bar-inner,
  .tabs-inner {
    padding-left: var(--sp-4);
    padding-right: var(--sp-4);
  }
  .panel {
    padding: var(--sp-4);
  }
  .gcell {
    width: 64px;
    height: 64px;
  }
}

/* ====== Responsif: ponsel ====== */
@media (max-width: 480px) {
  .brand-sub {
    display: none;
  }
  .brand-title {
    font-size: 1.05rem;
  }
  .course-chip {
    display: none;
  }
  .brand-mark {
    width: 38px;
    height: 38px;
  }
  .icon-btn {
    width: 38px;
    height: 38px;
  }
  .tab {
    font-size: 0.9rem;
    padding: var(--sp-3) var(--sp-3) calc(var(--sp-3) - 3px);
  }
  /* stepper menumpuk rapi; slider kecepatan turun ke baris baru */
  .stepper {
    border-radius: var(--r-md);
  }
  .speed {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
  .speed input {
    width: 60%;
  }
  .ctl-2,
  .markov-grids,
  .gate-grid {
    grid-template-columns: 1fr;
  }
  .gcell {
    width: 54px;
    height: 54px;
    font-size: 0.58rem;
  }
  .gcell .robot {
    font-size: 1.3rem;
  }
  .gcell .policy {
    font-size: 1rem;
  }
}

/* ====== Aksesibilitas: hormati prefers-reduced-motion ====== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
