/* ════════════════════════════════════════════════
   TOKENS — LIGHT
════════════════════════════════════════════════ */
:root,
[data-theme="light"] {
  --bg:          #faf9f7;
  --bg2:         #f3f1ee;
  --bg3:         #ebe8e3;
  --border:      #e0dbd4;
  --border2:     #c8c2bb;
  --space-xs:    4px;
  --space-sm:    8px;
  --space-md:    16px;
  --space-lg:    24px;
  --space-xl:    32px;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;

  --wine:        #7c1d2e;
  --wine-d:      #5a1220;
  --wine-l:      #f5eaec;
  --wine-m:      rgba(124,29,46,0.12);

  --ink:         #0f0f0f;
  --ink2:        #2a2a2a;
  --ink3:        #666258;
  --ink4:        #9c9890;

  --green:       #1a6b3a;
  --green-l:     rgba(26,107,58,0.06);
  --green-b:     rgba(26,107,58,0.2);

  --amber:       #b8860b;
  --amber-l:     rgba(184,134,11,0.08);
  --amber-b:     rgba(184,134,11,0.3);

  --shadow:      rgba(0,0,0,0.06);
  --shadow2:     rgba(0,0,0,0.12);

  --svg-wire:    #1a1a2e;
  --svg-wire-h:  #7c1d2e;
  --svg-wire-lo: #2a4a7a;
  --svg-res:     #7c1d2e;
  --svg-label:   #666258;
  --svg-val:     #7c1d2e;
  --svg-result:  #1a6b3a;
  --svg-bg:      #ffffff;
  --charge-col:  #c0392b;
  --charge-main: #e74c3c;
  --bat-glow:    rgba(200,50,50,0.12);
  --accent:      #7c1d2e;
  --paper:       #ffffff;
  --ink2:        #2a2a2a;
}

/* ════════════════════════════════════════════════
   TOKENS — DARK
════════════════════════════════════════════════ */
[data-theme="dark"] {
  --bg:          #0e0e10;
  --bg2:         #151519;
  --bg3:         #1e1e24;
  --border:      #2c2c38;
  --border2:     #3c3c4a;
  --space-xs:    4px;
  --space-sm:    8px;
  --space-md:    16px;
  --space-lg:    24px;
  --space-xl:    32px;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;

  --wine:        #c4364e;
  --wine-d:      #a82840;
  --wine-l:      rgba(196,54,78,0.12);
  --wine-m:      rgba(196,54,78,0.18);

  --ink:         #f0f0f4;
  --ink2:        #d0d0d8;
  --ink3:        #8888a0;
  --ink4:        #555568;

  --green:       #3ddc84;
  --green-l:     rgba(61,220,132,0.07);
  --green-b:     rgba(61,220,132,0.25);

  --amber:       #f0c040;
  --amber-l:     rgba(240,192,64,0.08);
  --amber-b:     rgba(240,192,64,0.3);

  --shadow:      rgba(0,0,0,0.3);
  --shadow2:     rgba(0,0,0,0.5);

  --svg-wire:    #c8c8e0;
  --svg-wire-h:  #ff6b8a;
  --svg-wire-lo: #6b8aff;
  --svg-res:     #c4364e;
  --svg-label:   #8888a0;
  --svg-val:     #c4364e;
  --svg-result:  #3ddc84;
  --svg-bg:      #141418;
  --charge-col:  #ff6b8a;
  --charge-main: #ff9ab0;
  --bat-glow:    rgba(255,107,138,0.15);
  --accent:      #c4364e;
  --paper:       #141418;
}

/* ════════════════════════════════════════════════
   RESET
════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.35s, color 0.35s;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }
button { cursor: pointer; font-family: inherit; }

/* ════════════════════════════════════════════════
   WELCOME
════════════════════════════════════════════════ */
/* Welcome / Login overlay */
.welcome-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem; gap: 0.75rem;
}
.welcome-box {
  max-width: 420px; width: 100%; text-align: center;
}
.welcome-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--wine), transparent);
  margin: 1.2rem 0;
  opacity: 0.5;
}
.welcome-kicker {
  font-size: 9px; letter-spacing: 0.4em; text-transform: uppercase;
  color: var(--ink4); margin-bottom: 0.4rem; font-family: 'DM Mono', monospace;
}
.welcome-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(3.2rem, 10vw, 5.5rem);
  font-weight: 900; color: var(--ink);
  letter-spacing: -0.02em; line-height: 0.95; margin-bottom: 0.4rem;
  white-space: nowrap;
}
.welcome-accent { color: var(--wine); }
.welcome-sub {
  font-size: 11px; color: var(--ink4); line-height: 1.8; margin-bottom: 1.8rem;
  font-family: 'DM Mono', monospace; letter-spacing: 0.02em;
}

/* Google button */
.welcome-btn-google {
  width: 100%; padding: 0.9rem 1rem;
  background: transparent; color: var(--ink);
  border: 1px solid var(--border); border-radius: 6px;
  font-family: 'DM Mono', monospace; font-size: 11px;
  font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  cursor: pointer; transition: border-color 0.25s, background 0.25s;
  margin-bottom: 0;
}
.welcome-btn-google:hover {
  border-color: var(--ink); background: var(--bg2);
}

/* Divider */
.welcome-divider {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 0.75rem 0; color: var(--ink4); font-size: 10px;
  font-family: 'DM Mono', monospace;
}
.welcome-divider::before, .welcome-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* Ghost button */
.welcome-btn-ghost {
  background: transparent; border: none;
  font-family: 'DM Mono', monospace; font-size: 10px;
  color: var(--ink4); letter-spacing: 0.1em; text-transform: uppercase;
  cursor: pointer; text-decoration: none;
  transition: color 0.2s; padding: 4px 0;
}
.welcome-btn-ghost:hover { color: var(--ink); }

/* Main enter button */
.welcome-btn {
  width: 100%; padding: 0.9rem;
  background: var(--wine); color: #fff; border: none; border-radius: 6px;
  font-family: 'DM Mono', monospace; font-size: 11px;
  font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase;
  cursor: pointer; transition: background 0.25s, transform 0.15s;
}
.welcome-btn:hover { background: var(--wine-d); transform: translateY(-1px); }

/* Temp form */
.welcome-temp-form { text-align: left; }
.welcome-form-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem; font-weight: 700; color: var(--ink);
  margin-bottom: 0.4rem; line-height: 1;
}
.welcome-input {
  width: 100%; padding: 0.75rem 1rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--ink);
  font-family: 'DM Mono', monospace; font-size: 12px;
  margin-bottom: 0.75rem; box-sizing: border-box;
  transition: border-color 0.2s;
}
.welcome-input:focus { outline: none; border-color: var(--wine); }
.welcome-back-btn {
  background: transparent; border: none; padding: 0;
  font-family: 'DM Mono', monospace; font-size: 11px;
  color: var(--ink3); cursor: pointer; margin-bottom: 1.2rem;
  display: block; transition: color 0.2s;
}
.welcome-back-btn:hover { color: var(--wine); }

/* Saved sessions - inline inside login box */
.saved-sessions {
  margin-bottom: 1.2rem;
}
.saved-sessions-title {
  font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink4); margin-bottom: 0.5rem; text-align: left;
}
.session-chip {
  display: flex; align-items: center; gap: 0.65rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.55rem 0.8rem;
  margin-bottom: 0.4rem; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.session-chip:hover { border-color: var(--wine); background: var(--bg3); }
.session-chip-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--wine); color: #fff;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-family: 'DM Mono', monospace; overflow: hidden;
}
.session-chip-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.session-chip-info { flex: 1; text-align: left; }
.session-chip-name { font-size: 11px; font-weight: 500; color: var(--ink); }
.session-chip-sub { font-size: 9px; color: var(--ink4); margin-top: 1px; }
.session-chip-arrow { color: var(--ink4); font-size: 13px; }
.chip-delete-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--ink4); font-size: 12px; padding: 4px 6px;
  border-radius: 4px; line-height: 1; flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.chip-delete-btn:hover { color: #ef4444; background: rgba(239,68,68,0.08); }


/* ════════════════════════════════════════════════
   EXPAND MODAL
════════════════════════════════════════════════ */
.expand-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 800;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem;
  backdrop-filter: blur(6px);
}
.expand-overlay.hidden { display: none; }
.expand-modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 960px; overflow: hidden;
  box-shadow: 0 32px 80px var(--shadow2);
}
.expand-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.4rem; border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.expand-title { font-family: 'Playfair Display', serif; font-size: 17px; font-weight: 700; color: var(--ink); }
.expand-controls { display: flex; align-items: center; gap: 1rem; }
.expand-info { font-size: 11px; color: var(--ink3); letter-spacing: 0.08em; }
.expand-close {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border);
  background: transparent; color: var(--ink3); font-size: 18px;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.expand-close:hover { border-color: var(--wine); color: var(--wine); }
.expand-body {
  padding: 2rem; background: var(--svg-bg); min-height: 340px;
  display: flex; align-items: center; justify-content: center;
}
#circuit-svg-expanded { width: 100%; height: auto; display: block; }
.expand-legend {
  display: flex; gap: 2rem; justify-content: center; align-items: center;
  padding: 0.85rem 1.4rem; border-top: 1px solid var(--border);
  background: var(--bg2);
}
.leg-item { display: flex; align-items: center; gap: 0.5rem; font-size: 11px; color: var(--ink3); }
.leg-dot { width: 10px; height: 10px; border-radius: 50%; }
.leg-charge { background: var(--charge-col); }
.leg-wire { background: var(--svg-wire); }
.leg-res { background: var(--svg-res); border-radius: 2px; }

/* ════════════════════════════════════════════════
   PANEL OVERLAY + SIDE PANELS
════════════════════════════════════════════════ */
.panel-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 300;
  backdrop-filter: blur(3px);
}
.panel-overlay.hidden { display: none; }
.side-panel {
  position: fixed; top: 0; height: 100vh; width: 300px;
  background: var(--bg); border-color: var(--border);
  z-index: 310; overflow-y: auto; display: flex; flex-direction: column;
  transition: background 0.35s;
}
.settings-panel { right: 0; border-left: 1px solid var(--border); transform: translateX(100%); }
.history-panel  { left:  0; border-right:1px solid var(--border); transform: translateX(-100%); }
.sp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border);
  background: var(--bg2); position: sticky; top: 0; z-index: 1;
}
.sp-title { font-family:'Playfair Display',serif; font-size: 17px; font-weight: 700; color: var(--ink); }
.sp-close {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border);
  background: transparent; color: var(--ink3); font-size: 17px;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.sp-close:hover { border-color: var(--wine); color: var(--wine); }
.sp-section { padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border); }
.sp-label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink4); margin-bottom: 0.65rem; }
.sp-row { display: flex; align-items: center; gap: 0.9rem; }
.sp-range { flex: 1; accent-color: var(--wine); }
.sp-range-val { font-size: 14px; font-weight: 500; color: var(--wine); min-width: 18px; text-align: right; }
.sp-toggle-group { display: flex; gap: 0.35rem; }
.sp-toggle {
  flex: 1; padding: 0.4rem 0.3rem;
  border: 1px solid var(--border2); border-radius: 5px;
  background: transparent; color: var(--ink3);
  font-family: 'DM Mono', monospace; font-size: 11px; transition: all 0.2s;
}
.sp-toggle.active { background: var(--wine); border-color: var(--wine); color: #fff; }
#accent-group .sp-toggle { color: #111; }
#accent-group .sp-toggle.active { color: #fff; }
.sp-switch { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; }
.sp-switch input { opacity: 0; width: 0; height: 0; }
.sp-slider {
  position: absolute; inset: 0; background: var(--border2);
  border-radius: 22px; transition: background 0.25s;
}
.sp-slider::before {
  content: ''; position: absolute; width: 16px; height: 16px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform 0.25s; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.sp-switch input:checked + .sp-slider { background: var(--wine); }
.sp-switch input:checked + .sp-slider::before { transform: translateX(18px); }
.sp-input {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid var(--border);
  border-radius: 5px; font-family: 'DM Mono', monospace; font-size: 12px;
  color: var(--ink); background: var(--bg2); outline: none; transition: border-color 0.2s;
}
.sp-input:focus { border-color: var(--wine); }
.sp-input::placeholder { color: var(--ink4); }
.sp-actions { padding: 1.2rem 1.4rem; }
.sp-save-btn {
  width: 100%; padding: 0.7rem; background: var(--wine); color: #fff;
  border: none; border-radius: 5px; font-family: 'DM Mono',monospace;
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; transition: background 0.2s;
}
.sp-save-btn:hover { background: var(--wine-d); }

/* History panel */
.hp-toolbar { display: flex; gap: 0.4rem; padding: 0.9rem 1.4rem; border-bottom: 1px solid var(--border); }
.hp-btn {
  flex: 1; padding: 0.45rem 0.3rem; border: 1px solid var(--border2);
  border-radius: 5px; background: transparent; color: var(--ink2);
  font-family: 'DM Mono',monospace; font-size: 11px; transition: all 0.2s;
}
.hp-btn:hover { border-color: var(--wine); color: var(--wine); }
.hp-btn-clear:hover { background: var(--wine-l); }
.history-list { flex:1; overflow-y:auto; padding: 0.9rem 1.4rem; display:flex; flex-direction:column; gap:0.65rem; }
.hp-empty { font-size: 12px; color: var(--ink4); text-align: center; padding: 2rem 0; }
.hist-card {
  border: 1px solid var(--border); border-radius: 7px; padding: 0.8rem 0.95rem;
  cursor: pointer; transition: border-color 0.2s, background 0.2s;
}
.hist-card:hover { border-color: var(--wine); background: var(--wine-l); }
.hist-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.3rem; }
.hist-card-mode { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--wine); font-weight: 500; }
.hist-card-date { font-size: 10px; color: var(--ink4); }
.hist-card-re { font-size: 13px; font-weight: 500; color: var(--ink); }
.hist-card-vals { font-size: 11px; color: var(--ink3); margin-top: 0.2rem; }
.hist-card-stmt { font-style: italic; color: var(--amber); }
.hist-card-actions { display: flex; gap: 0.4rem; margin-top: 0.55rem; }
.hist-action-btn {
  font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 0.22rem 0.55rem; border: 1px solid var(--border2); border-radius: 3px;
  background: transparent; color: var(--ink3); transition: all 0.18s;
}
.hist-action-btn:hover { border-color: var(--wine); color: var(--wine); }
.hist-del-btn { margin-left: auto; color: var(--ink4); font-size: 15px; border: none; background: transparent; transition: color 0.18s; }
.hist-del-btn:hover { color: var(--wine-d); }

/* ════════════════════════════════════════════════
   TOP BAR
════════════════════════════════════════════════ */
.topbar {
  position: sticky; top: 0; height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; z-index: 100;
  transition: background 0.35s, border-color 0.35s;
  box-shadow: 0 1px 0 var(--border), 0 2px 12px rgba(0,0,0,0.04);
}
.topbar-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent; color: var(--ink3);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s cubic-bezier(.4,0,.2,1);
}
.topbar-btn:hover {
  border-color: var(--wine); color: var(--wine);
  background: var(--wine-l);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(124,29,46,0.12);
}
.topbar-brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-name {
  font-family: 'Playfair Display',serif;
  font-size: 20px; font-weight: 900; color: var(--ink);
  letter-spacing: -0.02em;
}
.brand-accent { color: var(--wine); }
.brand-tag {
  font-size: 8px; letter-spacing: 0.18em; color: var(--ink4);
  border: 1px solid var(--border2); border-radius: 3px;
  padding: 2px 6px; text-transform: uppercase;
  background: var(--bg2);
}
.topbar-right { display: flex; gap: 0.35rem; align-items: center; }

/* ════════════════════════════════════════════════
   LAYOUT
════════════════════════════════════════════════ */
.main-layout {
  display: flex;                     /* resizer.js necesita flex */
  min-height: calc(100vh - 56px);
  align-items: stretch;
}
.col-left {
  width: 390px;                      /* resizer.js lo cambia inline */
  min-width: 280px;
  max-width: 640px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 0.85rem 0.85rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.6rem;
  position: sticky; top: 56px; height: calc(100vh - 56px);
  overflow-y: auto; overflow-x: hidden;
  transition: border-color 0.35s;
  background: var(--bg2);
  box-sizing: border-box;
}
.col-left::-webkit-scrollbar { width: 3px; }
.col-left::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.col-right {
  flex: 1;
  min-width: 0;
  padding: 1.5rem;
  overflow-y: auto;
  background: var(--bg);
  box-sizing: border-box;
}

/* ════════════════════════════════════════════════
   MODE TABS
════════════════════════════════════════════════ */
.mode-tabs {
  display: flex; position: relative;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 7px; padding: 3px; gap: 2px; transition: background 0.35s;
}
.mode-tab {
  flex: 1; padding: 0.5rem; border: none; background: transparent;
  color: var(--ink3); font-family: 'DM Mono',monospace;
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  border-radius: 5px; position: relative; z-index: 1; transition: color 0.25s;
}
.mode-tab.active { color: #fff; }
.mode-indicator {
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  border-radius: 5px; background: var(--wine);
  transition: all 0.32s cubic-bezier(0.4,0,0.2,1); z-index: 0;
}

/* ════════════════════════════════════════════════
   DIAGRAM CARD
════════════════════════════════════════════════ */
.diagram-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  overflow: hidden;
  flex-shrink: 0;
  /* sin max-height — el SVG con aspect-ratio controla el tamaño */
  transition: border-color 0.35s, background 0.35s;
  box-shadow: 0 1px 3px var(--shadow);
}
.diagram-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.9rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.diagram-label {
  font-size: 8px; letter-spacing: 0.24em; color: var(--ink4);
  text-transform: uppercase; font-weight: 600;
}
.expand-btn {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--wine); border: 1px solid var(--wine-l);
  background: var(--wine-l); border-radius: 4px;
  padding: 0.3rem 0.7rem; transition: all 0.2s;
  font-weight: 600;
}
.expand-btn:hover {
  background: var(--wine); color: #fff; border-color: var(--wine);
  box-shadow: 0 2px 8px rgba(124,29,46,0.2);
}
.diagram-wrap {
  padding: 0 !important;
  background: var(--svg-bg);
  transition: background 0.35s;
  overflow: hidden !important;
  flex-shrink: 0 !important;
  height: 170px !important;
  max-height: 170px !important;
  box-sizing: border-box !important;
}
#circuit-svg {
  width: 100% !important;
  height: 170px !important;
  max-height: 170px !important;
  display: block !important;
  overflow: hidden !important;
}

/* ════════════════════════════════════════════════
   STATEMENT CARD
════════════════════════════════════════════════ */
.statement-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg); overflow: hidden;
  transition: border-color 0.35s, background 0.35s;
  box-shadow: 0 1px 3px var(--shadow);
}
.statement-card:focus-within {
  border-color: color-mix(in srgb, var(--wine) 40%, transparent);
  box-shadow: 0 0 0 3px var(--wine-m);
}
.statement-header {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.6rem 0.9rem; cursor: pointer;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
.statement-header:hover { background: var(--bg2); }
.statement-label {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 8px; letter-spacing: 0.2em; color: var(--ink4);
  text-transform: uppercase; flex: 1; font-weight: 600;
}
.statement-opt {
  font-size: 8px; color: var(--ink4); letter-spacing: 0.06em;
  border: 1px solid var(--border2); border-radius: 3px; padding: 2px 6px;
  background: var(--bg2);
}
.statement-chevron {
  font-size: 13px; color: var(--ink4);
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}
.statement-chevron.collapsed { transform: rotate(-90deg); }
.statement-body { padding: 0.75rem; overflow: hidden; max-height: 120px; }
.statement-body.collapsed { display: none; }
/* Statement starts collapsed via JS (statementOpen=true animates in) */
.statement-textarea {
  width: 100%; resize: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: 'DM Mono', monospace; font-size: 12px;
  color: var(--ink); background: var(--bg2);
  padding: 0.75rem 0.9rem; outline: none;
  transition: border-color 0.2s, background 0.35s;
  line-height: 1.7; min-height: 72px; max-height: 120px;
  box-sizing: border-box;
}
.statement-textarea:focus {
  border-color: var(--wine); background: var(--bg);
  box-shadow: 0 0 0 3px var(--wine-m);
}
.statement-textarea::placeholder { color: var(--ink4); }

/* ════════════════════════════════════════════════
   INPUTS CARD
════════════════════════════════════════════════ */
.inputs-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: var(--bg);
  transition: border-color 0.35s, background 0.35s;
  box-shadow: 0 1px 3px var(--shadow);
}
.inputs-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}
.inputs-title {
  font-size: 8px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ink4); font-weight: 600;
}
.reset-btn {
  font-size: 10px; color: var(--ink4); border: none; background: none;
  letter-spacing: 0.06em; text-transform: uppercase;
  transition: color 0.2s; padding: 2px 6px; border-radius: 4px;
}
.reset-btn:hover { color: var(--wine); background: var(--wine-l); }
.inputs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
  width: 100%;
}
/* Resistor row with unit selector + remove button */
.ig-unit-select {
  font-size: 10px; color: var(--ink4); background: var(--bg2);
  border: none; border-left: 1px solid var(--border);
  padding: 0 0.35rem; font-family: 'DM Mono',monospace;
  color: var(--ink3); cursor: pointer; outline: none;
  transition: background 0.35s;
}
.ig-unit-select:focus { color: var(--wine); }
.ig-remove-btn {
  width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--border2);
  background: transparent; color: var(--ink4); font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s; flex-shrink: 0; align-self: flex-end; margin-bottom: 2px;
}
.ig-remove-btn:hover {
  border-color: var(--wine); color: var(--wine);
  background: var(--wine-l);
  transform: scale(1.1);
}
.add-resistor-btn {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem; border: 1px dashed var(--border2);
  border-radius: var(--radius-sm);
  background: transparent; color: var(--ink4);
  font-family: 'DM Mono',monospace; font-size: 9px; letter-spacing: 0.1em;
  text-transform: uppercase; transition: all 0.2s;
}
.add-resistor-btn:hover {
  border-color: var(--wine); color: var(--wine);
  background: var(--wine-l);
  border-style: solid;
}
.input-group { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; overflow: hidden; }
.ig-label {
  font-size: 9px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink4); font-weight: 600;
}
.ig-label sub { font-size: 8px; }
.ig-wrap {
  display: flex; align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden; width: 100%;
  transition: border-color 0.18s, box-shadow 0.18s;
  background: var(--bg);
}
.ig-wrap:focus-within {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px var(--wine-m);
}
.ig-field {
  flex: 1; min-width: 0; width: 0; border: none; background: transparent;
  font-family: 'DM Mono',monospace; font-size: 13px; color: var(--ink);
  padding: 0.48rem 0.55rem; outline: none;
}
.ig-unit {
  font-size: 9px; color: var(--ink4); background: var(--bg2);
  border-left: 1px solid var(--border); padding: 0 0.55rem;
  display: flex; align-items: center; white-space: nowrap; flex-shrink: 0;
  transition: background 0.35s; letter-spacing: 0.05em;
}

/* ════════════════════════════════════════════════
   SOLVE BUTTON
════════════════════════════════════════════════ */
.solve-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: var(--wine); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-family: 'DM Mono',monospace;
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  font-weight: 600;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 12px rgba(124,29,46,0.25), 0 1px 3px rgba(124,29,46,0.15);
}
.solve-btn:hover {
  background: var(--wine-d);
  box-shadow: 0 4px 20px rgba(124,29,46,0.35), 0 2px 8px rgba(124,29,46,0.2);
  transform: translateY(-1px);
}
.solve-btn:active { transform: scale(0.99) translateY(0); box-shadow: none; }
.solve-arrow { font-size: 16px; display: inline-block; transition: transform 0.2s; }
.solve-btn:hover .solve-arrow { transform: translateX(5px); }
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 0.35rem; margin-top: 0.6rem;
}
.qa-btn {
  padding: 0.5rem 0.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2); color: var(--ink3);
  font-family: 'DM Mono',monospace; font-size: 9px;
  letter-spacing: 0.05em; text-transform: uppercase;
  transition: all 0.18s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}
.qa-btn:hover {
  border-color: var(--wine); color: var(--wine);
  background: var(--wine-l);
  transform: translateY(-1px);
}

/* ════════════════════════════════════════════════
   STEPS AREA
════════════════════════════════════════════════ */
.steps-area { display: flex; flex-direction: column; gap: 1rem; }
.steps-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.25rem; padding: 5rem 2rem; text-align: center;
}
.ph-line {
  width: 40px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--wine), transparent);
}
.ph-text {
  font-size: 12px; color: var(--ink4); line-height: 1.8;
  max-width: 240px;
}
.ph-text strong { color: var(--wine); display: block; margin-top: 0.25rem; }

.step-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg); overflow: hidden;
  opacity: 0; transform: translateY(14px);
  transition: border-color 0.35s, background 0.35s, box-shadow 0.25s;
  box-shadow: 0 1px 4px var(--shadow);
}
.step-card:hover {
  border-color: var(--border2);
  box-shadow: 0 4px 16px var(--shadow2);
}
.step-card-head {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.85rem 1.2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.step-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--wine); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(124,29,46,0.3);
}
.step-title { font-family: 'Playfair Display',serif; font-size: 15px; font-weight: 700; color: var(--ink); }
.step-body { padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: 0.65rem; }
.f-row { display: flex; flex-direction: column; gap: 0.18rem; }
.f-tag { font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink4); }
.f-val {
  font-size: 13px; color: var(--ink2);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 5px; padding: 0.45rem 0.8rem;
}
.f-val.f-formula { color: var(--wine); border-color: var(--wine-l); background: var(--wine-l); }
.f-val.f-result  { color: var(--green); border-color: var(--green-b); background: var(--green-l); font-weight: 500; font-size: 14px; }
.sub-items { display: flex; flex-direction: column; gap: 0.5rem; }
.sub-item { border-left: 2px solid var(--wine); padding-left: 0.8rem; display: flex; flex-direction: column; gap: 0.18rem; }
.sub-item-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--wine); }
.sub-item-formula { font-size: 12px; color: var(--ink3); }
.sub-item-result { font-size: 13px; color: var(--green); font-weight: 500; }

.results-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden;
  opacity: 0; transform: translateY(14px);
  transition: border-color 0.35s;
  box-shadow: 0 1px 4px var(--shadow);
}
.results-head {
  padding: 0.75rem 1.2rem; background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: 8px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink3); font-weight: 600;
}
.res-table { width: 100%; border-collapse: collapse; font-family: 'DM Mono',monospace; font-size: 12px; }
.res-table th { padding: 0.55rem 1.2rem; text-align: left; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--wine); background: var(--wine-l); font-weight: 500; }
.res-table td { padding: 0.6rem 1.2rem; border-top: 1px solid var(--border); color: var(--ink); }
.res-table td:first-child { color: var(--ink3); }
.res-table td.highlight { color: var(--green); font-weight: 500; }
.res-table tbody tr:hover { background: var(--bg2); }

/* ════════════════════════════════════════════════
   KIRCHHOFF CARD
════════════════════════════════════════════════ */
.kirchhoff-card {
  border-radius: 10px; overflow: hidden;
  border: 2px solid var(--green-b); background: var(--green-l);
  transition: border-color 0.35s, background 0.35s;
}
.kf-header {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.75rem 1.2rem; background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.kf-badge {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 9px; letter-spacing: 0.15em; text-transform: uppercase;
  font-weight: 700; padding: 0.25rem 0.65rem; border-radius: 20px;
}
.kf-ok   { background: var(--green); color: #fff; }
.kf-fail { background: var(--wine); color: #fff; }
.kf-icon { font-size: 12px; }
.kf-status { font-size: 9px; }
.kf-title { font-family: 'Playfair Display',serif; font-size: 14px; font-weight: 700; color: var(--ink); }

.kf-body { padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.7rem; }
.kf-desc { font-size: 12px; color: var(--ink3); }
.kf-check-row { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.kf-formula-box { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 0.18rem; }
.kf-result-row {
  display: flex; align-items: flex-start; gap: 0.65rem;
  padding: 0.65rem 0.9rem; border-radius: 6px;
  border: 1px solid;
}
.kf-result-row.kf-ok {
  background: var(--green-l); border-color: var(--green-b); color: var(--green);
}
.kf-result-row.kf-fail {
  background: var(--wine-l); border-color: var(--wine-m); color: var(--wine);
}
.kf-result-icon { font-size: 16px; line-height: 1.4; }
.kf-result-text { font-size: 12px; line-height: 1.6; }
.kf-result-text strong { font-size: 12px; display: block; margin-top: 2px; }

/* ════════════════════════════════════════════════
   SVG CLASSES
════════════════════════════════════════════════ */
.svg-wire      { stroke: var(--svg-wire); stroke-width: 2; fill: none; }
.svg-wire-high { stroke: var(--svg-wire-h); stroke-width: 2.4; }
.svg-wire-low  { stroke: var(--svg-wire-lo); stroke-width: 2.4; }
.svg-resistor  { stroke: var(--svg-res); stroke-width: 2.5; fill: none; }
.svg-resistor-group { /* container for Joule GSAP tween */ }
.svg-res-shadow { fill: var(--svg-res); stroke: none; opacity: 0.08; }
.svg-res-zigzag { stroke: var(--svg-res); stroke-width: 1.5; fill: none; opacity: 0.65; }
.svg-label     { font-family: 'DM Mono',monospace; font-size: 11px; fill: var(--svg-label); }
.svg-val       { font-family: 'DM Mono',monospace; font-size: 11px; fill: var(--svg-val); font-weight: 500; }
.svg-result    { font-family: 'DM Mono',monospace; font-size: 10px; fill: var(--svg-result); font-weight: 500; }
.svg-bat-p     { stroke: var(--svg-wire); stroke-width: 3; }
.svg-bat-n     { stroke: var(--svg-wire); stroke-width: 1.5; }
.svg-node      { fill: var(--svg-wire); }
.svg-node-group { cursor: pointer; }
.svg-placeholder { stroke: var(--border2); stroke-width: 1.5; fill: none; stroke-dasharray: 4 3; }
.svg-wire-ph   { stroke: var(--border2); stroke-width: 1.5; fill: none; }

/* Node pulse rings — expand + fade on active nodes */
.svg-node-pulse {
  fill: none;
  stroke: var(--svg-wire-h);
  stroke-width: 1.5;
  animation: node-pulse 1.4s ease-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes node-pulse {
  0%   { r: 4.5px;  opacity: 0.8; }
  70%  { r: 11px;   opacity: 0.15; }
  100% { r: 14px;   opacity: 0; }
}

/* Battery glow pulse */
.svg-bat-glow {
  fill: var(--bat-glow);
  animation: bat-pulse 2.2s ease-in-out infinite;
}
@keyframes bat-pulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 1; }
}

/* Tooltip */
.svg-tooltip-bg   { fill: var(--bg2); stroke: var(--border); stroke-width: 1; }
.svg-tooltip-text { font-family: 'DM Mono',monospace; font-size: 10px; fill: var(--wine); font-weight: 500; text-anchor: middle; }
.svg-tooltip { pointer-events: none; transition: opacity 0.2s; }

/* Charge particles — neon glow */
.charge-particle {
  fill: #ff6b8a;
  filter: drop-shadow(0 0 4px #ff6b8a) drop-shadow(0 0 8px rgba(255,107,138,0.5));
}
.charge-particle.charge-main {
  fill: #fff;
  filter: drop-shadow(0 0 5px #fff) drop-shadow(0 0 12px rgba(255,180,200,0.7));
  r: 5;
}
.charge-trail {
  pointer-events: none;
}

/* ── Presentation expand button ──────────────────────── */
.pres-block-label-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.6rem;
}
.pres-expand-btn {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(255,255,255,0.55); border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08); border-radius: 4px;
  padding: 0.22rem 0.6rem; transition: all 0.2s; font-family: 'DM Mono',monospace;
}
.pres-expand-btn:hover { background: rgba(255,255,255,0.16); color: #fff; border-color: rgba(255,255,255,0.35); }

/* Fullscreen presentation diagram — feature removed */

/* ════════════════════════════════════════════════
   PRESENTATION MODE
════════════════════════════════════════════════ */
.pres-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: #0f0f0f;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.pres-overlay.hidden { display: none; }

.pres-topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem;
  background: #7c1d2e;
  color: #fff;
}
.pres-brand {
  font-family: 'Playfair Display', serif;
  font-size: 22px; font-weight: 900; color: #fff;
  display: flex; align-items: baseline; gap: 0.75rem;
}
.pres-brand span:first-child { color: rgba(255,255,255,0.7); }
.pres-tag {
  font-family: 'DM Mono', monospace;
  font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  border: 1px solid rgba(255,255,255,0.3); border-radius: 3px; padding: 2px 6px;
}
.pres-topbar-right { display: flex; align-items: center; gap: 1.5rem; }
.pres-meta { font-size: 12px; color: rgba(255,255,255,0.75); }
.pres-exit-btn {
  display: flex; align-items: center; gap: 0.4rem;
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px; color: #fff; padding: 0.4rem 0.9rem;
  font-family: 'DM Mono',monospace; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  transition: background 0.2s;
}
.pres-exit-btn:hover { background: rgba(255,255,255,0.25); }

.pres-body {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1.25rem;
  padding: 1.5rem 2.5rem;
  background: #0f0f0f;
}

/* Statement banner — wine on dark */
.pres-statement {
  background: rgba(124,29,46,0.18);
  border: 1px solid rgba(124,29,46,0.4);
  border-left: 5px solid #7c1d2e;
  border-radius: 8px; padding: 1rem 1.5rem;
}
.pres-statement-label {
  font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
  color: rgba(255,255,255,0.5); margin-bottom: 0.5rem; display: block;
}
.pres-statement-text {
  font-family: 'Playfair Display', serif;
  font-size: clamp(15px, 2vw, 22px);
  color: #f0f0f0; line-height: 1.6;
}

/* Top row */
.pres-top-row {
  display: grid; grid-template-columns: 1.7fr 1fr; gap: 1.25rem;
}
.pres-block-label {
  font-size: 9px; letter-spacing: 0.22em; text-transform: uppercase;
  color: rgba(255,255,255,0.35); margin-bottom: 0.6rem;
}
.pres-diagram-block {}
.pres-diagram-wrap {
  background: #1a1a1a; border: 1px solid #2a2a2a;
  border-radius: 10px; padding: 1rem;
}
#circuit-svg-pres { width: 100%; height: auto; display: block; }

.pres-summary-block {}
.pres-summary-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0.6rem; margin-bottom: 0.8rem;
}
.pres-summary-item {
  background: #1a1a1a; border: 1px solid #2a2a2a;
  border-radius: 8px; padding: 0.7rem 0.9rem;
}
.pres-summary-item.pres-sum-highlight {
  background: rgba(124,29,46,0.2); border-color: rgba(124,29,46,0.5);
}
.pres-sum-label { font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255,255,255,0.4); display: block; margin-bottom: 0.3rem; }
.pres-sum-val {
  font-size: clamp(14px, 1.8vw, 20px);
  font-weight: 600; color: #fff;
  display: block;
}
.pres-summary-item.pres-sum-highlight .pres-sum-val { color: #e8909a; }

/* Kirchhoff in presentation — no green */
.pres-kirchhoff-block {
  background: rgba(124,29,46,0.12); border: 1px solid rgba(124,29,46,0.35);
  border-radius: 8px; padding: 0.8rem 1rem; margin-top: 0.2rem;
}
.pres-kf-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(13px, 1.5vw, 16px); font-weight: 700; color: #f0f0f0;
  margin-bottom: 0.45rem;
}
.pres-kf-check {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.pres-kf-icon { font-size: clamp(18px, 2.5vw, 28px); }
.pres-kf-ok .pres-kf-icon   { color: #fff; }
.pres-kf-fail .pres-kf-icon { color: #e8909a; }
.pres-kf-formula { font-size: clamp(13px, 1.8vw, 18px); color: rgba(255,255,255,0.8); flex: 1; }
.pres-kf-verdict {
  font-size: clamp(11px, 1.4vw, 14px); font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 0.2rem 0.6rem; border-radius: 4px;
}
.pres-kf-ok .pres-kf-verdict   { background: #7c1d2e; color: #fff; }
.pres-kf-fail .pres-kf-verdict { background: #3a0a10; color: #e8909a; border: 1px solid #7c1d2e; }

/* Steps in presentation */
.pres-steps-wrap {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.85rem;
}
.pres-step-card {
  background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 10px;
  overflow: hidden;
}
.pres-step-head {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 1rem; background: #111; border-bottom: 1px solid #2a2a2a;
}
.pres-step-num {
  width: 28px; height: 28px; border-radius: 50%; background: #7c1d2e; color: #fff;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.pres-step-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(14px, 1.7vw, 18px); font-weight: 700; color: #f0f0f0;
}
.pres-step-body { padding: 0.8rem 1rem; }
.pres-step-result {
  font-size: clamp(15px, 2vw, 20px); font-weight: 600;
  color: #e8909a; line-height: 1.5;
}
.pres-step-items { display: flex; flex-direction: column; gap: 0.4rem; }
.pres-step-item {
  display: flex; justify-content: space-between; align-items: baseline;
  border-left: 2px solid #7c1d2e; padding-left: 0.6rem; gap: 0.5rem;
}
.pres-step-item-label  { font-size: clamp(11px, 1.3vw, 13px); color: rgba(255,255,255,0.5); }
.pres-step-item-result { font-size: clamp(13px, 1.6vw, 16px); font-weight: 600; color: #fff; }

.pres-footer {
  height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem;
  background: #111; border-top: 1px solid #2a2a2a;
  font-size: 11px; color: rgba(255,255,255,0.35);
}
.pres-legend { display: flex; gap: 1.2rem; }

/* ════════════════════════════════════════════════
   TOAST
════════════════════════════════════════════════ */
.toast {
  position: fixed; bottom: 1.4rem; left: 50%;
  transform: translateX(-50%) translateY(18px);
  background: var(--ink2); color: var(--bg);
  font-family: 'DM Mono',monospace; font-size: 11px; letter-spacing: 0.07em;
  padding: 0.6rem 1.4rem; border-radius: 100px;
  opacity: 0; pointer-events: none; white-space: nowrap; z-index: 9999;
}

/* ════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════ */
@media (max-width: 820px) {
  .main-layout { flex-direction: column; }
  .col-left { width: 100% !important; min-width: 0 !important; position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .pres-top-row { grid-template-columns: 1fr; }
  .pres-summary-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  :root { --panel-w: 88vw; }
  .side-panel { width: 88vw; }
  .pres-steps-wrap { grid-template-columns: 1fr; }
}

/* ════════════════════════════════════════════════
   NEW ADDITIONS — Edit button, New window, Sounds
════════════════════════════════════════════════ */
.qa-btn-edit {
  background: var(--wine);
  color: #fff !important;
  border-color: var(--wine-d);
  font-weight: 600;
}
.qa-btn-edit:hover { background: var(--wine-d) !important; color: #fff !important; }

.expand-newwin-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 5px;
  border: 1px solid var(--border2);
  background: var(--bg2); color: var(--ink2);
  font-family: 'DM Mono',monospace; font-size: 10px;
  letter-spacing: 0.06em; cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.expand-newwin-btn:hover { background: var(--wine); color: #fff; border-color: var(--wine); }

/* Fullscreen presentation diagram overlay — removed */

/* Sound toggle button */
.sound-toggle-btn {
  background: none; border: none; cursor: pointer;
  color: var(--ink3); padding: 6px 8px; border-radius: 6px;
  transition: color 0.18s, background 0.18s;
  display: flex; align-items: center;
}
.sound-toggle-btn:hover { background: var(--bg3); color: var(--wine); }
.sound-toggle-btn.sound-on { color: var(--wine); }

/* ═══════════════════════════════════════════════════
   GUÍA 6 — CAPACITORES, CONDUCTOR, RC
   ═══════════════════════════════════════════════════ */

/* Mode tabs — 3×2 grid for 6 tabs */
.mode-tabs {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  height: auto !important;
  background: var(--bg3) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
}
.mode-tab {
  flex: unset !important;
  font-size: 9px !important;
  padding: 7px 4px !important;
  letter-spacing: 0.08em !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  font-weight: 600;
  transition: all 0.18s !important;
  border-radius: 4px !important;
}
.mode-tab:hover:not(.active) {
  background: var(--bg) !important;
  color: var(--ink2) !important;
}
.mode-indicator { display: none !important; }
.mode-tab.active {
  background: var(--wine) !important;
  color: #fff !important;
  border-radius: 4px !important;
  box-shadow: 0 1px 4px rgba(124,29,46,0.3) !important;
}

/* Special input groups — fila completa solo cuando tienen select/wrap-full */
.special-input-group {
  grid-column: 1 / -1;
}
.ig-wrap-full { width: 100%; }
.ig-wrap-full select.ig-unit-select,
.special-sel {
  width: 100%; flex: 1; min-width: 0;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border, rgba(0,0,0,0.12));
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.77rem;
  font-family: 'DM Mono', monospace;
  cursor: pointer; outline: none;
  -webkit-appearance: none; appearance: none;
}
.special-sel:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Capacitor SVG elements */
.cap-plate { transition: opacity 0.4s; }
/* rect plates (capacitor diagram — fill based) */
rect.cap-plate-pos { fill: var(--accent); stroke: none; opacity: 0.88; filter: drop-shadow(0 0 5px var(--accent)); }
rect.cap-plate-neg { fill: var(--ink2, #2a2a2a); stroke: none; opacity: 0.72; }
/* line plates (circuit symbol — stroke based) */
line.cap-plate-pos { fill: none; stroke: var(--accent); stroke-linecap: round; }
line.cap-plate-neg { fill: none; stroke: var(--svg-wire); stroke-linecap: round; }
.cap-field-region { pointer-events: none; }
.cap-efield-arrow { stroke: var(--accent); stroke-width: 1.3; stroke-opacity: 0.72; stroke-dasharray: 3,2.5; }
.cap-efield-arrowhead { fill: var(--accent); opacity: 0.72; }
.cap-charge-sym { font-family: 'DM Mono', monospace; font-size: 11px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.cap-plus  { fill: var(--paper, #fff); }
.cap-minus { fill: var(--paper, #fff); }
.cap-charge-dot { pointer-events: none; }
.cap-dot-pos { fill: var(--accent); }
.cap-dot-neg { fill: var(--ink2, #2a2a2a); }

/* RC table */
.rc-table-wrap { margin-top: 8px; }
.rc-table      { width: 100%; }
.rc-table-note {
  font-size: 0.72rem;
  color: var(--ink3);
  margin-top: 6px;
  font-family: 'DM Mono', monospace;
  font-style: italic;
}

/* ═══════════════════════════════════════════════════
/* ═══════════════════════════════════════════════════
   AI SOLVER MODAL — v2 redesign
   ═══════════════════════════════════════════════════ */

/* Topbar AI button */
.ai-topbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--wine) !important;
  color: #fff !important;
  border-radius: 8px !important;
  padding: 5px 11px !important;
  font-size: 10px;
  letter-spacing: 0.08em;
  font-weight: 600;
  border: none !important;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s;
  position: relative;
  z-index: 101;
}
.ai-topbar-btn:hover { opacity: 0.85; transform: translateY(-1px); }
.ai-btn-text { font-family: 'DM Mono', monospace; }

/* Overlay */
.ai-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ai-overlay.hidden { display: none; }

/* Modal container */
.ai-modal {
  background: var(--paper);
  border-radius: 20px;
  width: 100%;
  max-width: 780px;
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.06),
    0 24px 64px rgba(0,0,0,0.22),
    0 4px 16px rgba(0,0,0,0.08);
}

/* Header */
.ai-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border, rgba(0,0,0,0.08));
  flex-shrink: 0;
  background: var(--paper);
}
.ai-modal-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ai-title-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--wine);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-title-text {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}
.ai-title-sub {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--ink3, #888);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.ai-badge {
  background: var(--wine);
  color: #fff;
  font-size: 9px;
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.14em;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
}

/* Close button — always visible X */
.ai-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1.5px solid var(--border, rgba(0,0,0,0.12));
  background: transparent;
  color: var(--ink3, #888);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.ai-close:hover {
  background: var(--wine);
  border-color: var(--wine);
  color: #fff;
  transform: scale(1.05);
}

/* Body — two column layout */
.ai-body {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

/* Left column */
.ai-col-left {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  border-right: 1px solid var(--border, rgba(0,0,0,0.07));
}

/* Right column */
.ai-col-right {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  background: color-mix(in srgb, var(--paper) 60%, var(--ink) 3%);
}

/* Mode detector chip */
.ai-mode-detector {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  background: color-mix(in srgb, var(--wine) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--wine) 20%, transparent);
  border-radius: 20px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--wine);
  font-weight: 600;
  letter-spacing: 0.04em;
  align-self: flex-start;
  animation: aiFadeIn 0.25s ease;
}
.ai-mode-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wine);
  animation: aiPulse 1.5s ease-in-out infinite;
}
@keyframes aiPulse {
  0%,100% { opacity:1; transform:scale(1); }
  50% { opacity:0.5; transform:scale(0.8); }
}

/* Textarea wrapper */
.ai-textarea-wrap {
  display: flex;
  flex-direction: column;
  border: 1.5px solid var(--border, rgba(0,0,0,0.12));
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--paper);
}
.ai-textarea-wrap:focus-within {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--wine) 10%, transparent);
}
.ai-textarea {
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  line-height: 1.75;
  resize: none;
  outline: none;
  min-height: 130px;
}
.ai-textarea::placeholder { color: var(--ink3, #aaa); opacity: 0.7; }
.ai-textarea-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-top: 1px solid var(--border, rgba(0,0,0,0.07));
  background: color-mix(in srgb, var(--paper) 80%, var(--ink) 4%);
}
.ai-char-count {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--ink3, #aaa);
}
.ai-clear-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border, rgba(0,0,0,0.1));
  background: transparent;
  color: var(--ink3, #888);
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-clear-btn:hover { background: #dc3545; color: #fff; border-color: #dc3545; }

/* Solve button */
.ai-solve-btn {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--wine);
  color: #fff;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.07em;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s, transform 0.12s, box-shadow 0.15s;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--wine) 35%, transparent);
  position: relative;
  overflow: hidden;
}
.ai-solve-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.14) 0%, transparent 55%);
}
.ai-solve-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--wine) 40%, transparent);
}
.ai-solve-btn:active:not(:disabled) { transform: translateY(0); }
.ai-solve-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* Status loading */
.ai-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--wine) 6%, transparent);
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--wine) 15%, transparent);
}
.ai-spinner-wrap {
  flex-shrink: 0;
}
.ai-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid color-mix(in srgb, var(--wine) 20%, transparent);
  border-top-color: var(--wine);
  border-radius: 50%;
  animation: aiSpin 0.65s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }
.ai-status-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#ai-status-text {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--wine);
  font-weight: 500;
}
.ai-status-bar {
  height: 3px;
  background: color-mix(in srgb, var(--wine) 15%, transparent);
  border-radius: 2px;
  overflow: hidden;
}
.ai-status-fill {
  height: 100%;
  background: var(--wine);
  border-radius: 2px;
  animation: aiProgress 2s ease-in-out infinite;
}
@keyframes aiProgress {
  0%   { width: 0%; margin-left: 0%; }
  50%  { width: 60%; margin-left: 20%; }
  100% { width: 0%; margin-left: 100%; }
}

/* Error */
.ai-error {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 12px 14px;
  background: rgba(192, 57, 43, 0.06);
  border-radius: 10px;
  border: 1px solid rgba(192, 57, 43, 0.18);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: #c0392b;
  line-height: 1.6;
}
.ai-error svg { flex-shrink: 0; margin-top: 1px; }

/* Result preview */
.ai-result-preview {
  background: color-mix(in srgb, #1a6b3a 6%, transparent);
  border: 1.5px solid color-mix(in srgb, #1a6b3a 22%, transparent);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: aiFadeIn 0.3s ease;
}
@keyframes aiFadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.ai-result-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-result-icon {
  width: 26px;
  height: 26px;
  background: #1a6b3a;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ai-result-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.ai-result-subtitle {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: #1a6b3a;
  margin-top: 1px;
}
.ai-result-params {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.ai-param-chip {
  background: var(--paper);
  border: 1px solid var(--border, rgba(0,0,0,0.1));
  border-radius: 20px;
  padding: 3px 10px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--ink3);
}
.ai-param-chip strong { color: var(--wine); }
.ai-apply-btn {
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  border: none;
  background: #1a6b3a;
  color: #fff;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: opacity 0.15s, transform 0.12s;
}
.ai-apply-btn:hover { opacity: 0.85; transform: translateY(-1px); }

/* Right column sections */
.ai-section { display: flex; flex-direction: column; gap: 8px; }
.ai-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ai-section-label {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink3, #aaa);
  font-family: 'DM Mono', monospace;
  font-weight: 500;
}
.ai-history-clear-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border, rgba(0,0,0,0.1));
  background: transparent;
  color: var(--ink3, #888);
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  cursor: pointer;
  transition: all 0.15s;
}
.ai-history-clear-btn:hover { background: #c0392b; color: #fff; border-color: #c0392b; }

/* Examples grid */
.ai-examples-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.ai-ex-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(0,0,0,0.1));
  background: var(--paper);
  color: var(--ink3);
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
  text-align: left;
}
.ai-ex-btn:hover {
  background: var(--wine);
  color: #fff;
  border-color: var(--wine);
  transform: translateY(-1px);
}
.ai-ex-icon {
  font-size: 12px;
  flex-shrink: 0;
}

/* History */
.ai-history-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 120px;
  overflow-y: auto;
}
.ai-history-item {
  padding: 6px 9px;
  border-radius: 7px;
  border: 1px solid var(--border, rgba(0,0,0,0.08));
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--ink3);
  cursor: pointer;
  transition: all 0.13s;
  line-height: 1.4;
  background: var(--paper);
}
.ai-history-item:hover {
  background: color-mix(in srgb, var(--wine) 8%, transparent);
  border-color: color-mix(in srgb, var(--wine) 25%, transparent);
  color: var(--wine);
}
.ai-history-tag {
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--wine);
  font-weight: 600;
  margin-bottom: 2px;
}

/* Tips */
.ai-tips-section { opacity: 0.85; }
.ai-tips {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-tips li {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--ink3);
  line-height: 1.5;
  padding-left: 12px;
  position: relative;
}
.ai-tips li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--wine);
  font-size: 9px;
}
.ai-tips strong { color: var(--ink); }

/* Model info */
.ai-model-info {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border, rgba(0,0,0,0.07));
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  color: var(--ink3);
  opacity: 0.7;
}
.ai-model-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #1a6b3a;
  flex-shrink: 0;
  animation: aiPulse 2s ease-in-out infinite;
}

/* Responsive — narrow screens */
@media (max-width: 620px) {
  .ai-body { grid-template-columns: 1fr; }
  .ai-col-right { display: none; }
  .ai-modal { max-width: 100%; border-radius: 16px 16px 0 0; align-self: flex-end; max-height: 92vh; }
}

/* ════════════════════════════════════════════════
   AI WHY BUTTON & BOX
════════════════════════════════════════════════ */
.ai-why-btn {
  width: 100%; padding: 0.65rem 1rem; margin-top: 0.5rem;
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--ink3);
  font-family: 'DM Mono', monospace; font-size: 11px;
  letter-spacing: 0.05em; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: border-color 0.2s, color 0.2s;
}
.ai-why-btn:hover { border-color: var(--wine); color: var(--wine); }
.ai-why-box {
  margin-top: 0.75rem;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.85rem 1rem;
  font-size: 12px; color: var(--ink2); line-height: 1.7;
  max-height: 220px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.ai-why-box::-webkit-scrollbar { width: 4px; }
.ai-why-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.ai-why-content p { margin: 0 0 0.5rem; }
.ai-why-content p:last-child { margin: 0; }
.ai-why-loading {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--ink4);
}
.ai-why-spinner {
  width: 12px; height: 12px; border: 2px solid var(--border);
  border-top-color: var(--wine); border-radius: 50%;
  animation: spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════════════
   N8N ALWAYS SEND TOGGLE
════════════════════════════════════════════════ */
.n8n-toggle-row {
  padding: 0.5rem 0 0.25rem;
}
.n8n-toggle-label {
  display: flex; align-items: center; gap: 0.6rem;
  font-family: 'DM Mono', monospace; font-size: 10px;
  color: var(--ink3); cursor: pointer; user-select: none;
}
.n8n-toggle-label input { display: none; }
.n8n-toggle-track {
  width: 28px; height: 16px; border-radius: 8px;
  background: var(--border); position: relative;
  transition: background 0.2s; flex-shrink: 0;
}
.n8n-toggle-label input:checked + .n8n-toggle-track { background: var(--wine); }
.n8n-toggle-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; transition: transform 0.2s;
}
.n8n-toggle-label input:checked + .n8n-toggle-track .n8n-toggle-thumb { transform: translateX(12px); }

/* ════════════════════════════════════════════════
   CELEBRATION OVERLAY
════════════════════════════════════════════════ */
.celebration-toast {
  position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--wine); color: #fff;
  font-family: 'DM Mono', monospace; font-size: 13px;
  padding: 0.7rem 1.4rem; border-radius: 30px;
  opacity: 0; pointer-events: none; z-index: 9998;
  white-space: nowrap; letter-spacing: 0.05em;
}

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile / Tablet / Desktop
   Breakpoints:
   - Mobile:  ≤ 640px
   - Tablet:  641px – 1024px
   - Desktop: ≥ 1025px (base styles)
════════════════════════════════════════════════════════════════ */

/* ── Touch targets ─────────────────────────────────────────── */
@media (max-width: 1024px) {
  .topbar-btn { width: 38px; height: 38px; }
  .qa-btn { padding: 0.65rem 0.4rem; font-size: 10px; }
  .solve-btn { padding: 1rem; font-size: 13px; }
}

/* ── Tablet (641–1024px) ───────────────────────────────────── */
@media (min-width: 641px) and (max-width: 1024px) {
  .col-left { width: 320px; height: calc(100vh - 56px); }
  .topbar-right .ai-btn-text { display: none; }
  .brand-name { font-size: 17px; }
}

/* ── Mobile (≤ 640px) ──────────────────────────────────────── */
@media (max-width: 640px) {

  /* Topbar */
  .topbar { padding: 0 0.75rem; height: 48px; }
  .brand-name { font-size: 16px; }
  .brand-tag { display: none; }
  .topbar-right { gap: 0.3rem; }
  .topbar-btn { width: 36px; height: 36px; border-radius: 8px; }
  .ai-btn-text { display: none; }
  /* Hide less critical topbar buttons on small screens */
  .sound-toggle-btn,
  .live-open-btn,
  .pres-open-btn { display: none; }

  /* Layout — stack vertically */
  .main-layout {
    flex-direction: column;
    min-height: auto;
  }
  .col-left {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    gap: 0.85rem;
    overflow-y: visible;
  }
  .col-right {
    width: 100%;
    padding: 1rem;
    min-height: 60vh;
  }

  /* Mode tabs — scrollable */
  .mode-tabs-outer { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .mode-tabs { width: max-content; min-width: 100%; }
  .mode-tab { font-size: 9px; padding: 0.45rem 0.7rem; white-space: nowrap; }

  /* Sub-tabs */
  .sub-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0.3rem; }
  .sub-tab { font-size: 9px; padding: 0.3rem 0.6rem; white-space: nowrap; flex-shrink: 0; }

  /* Inputs grid — single column en mobile */
  .inputs-grid { grid-template-columns: 1fr !important; gap: 0.6rem; }
  .input-group { width: 100%; }
  .ig-wrap { flex: 1; }

  /* Statement */
  .statement-textarea { min-height: 80px; font-size: 12px; }

  /* Solve button */
  .solve-btn { padding: 1rem; font-size: 12px; }
  .quick-actions { flex-wrap: wrap; gap: 0.4rem; }
  .qa-btn { flex: 1 1 calc(50% - 0.4rem); min-width: 100px; font-size: 10px; }

  /* Steps */
  .steps-area { gap: 0.75rem; }
  .step-card { padding: 0.85rem; }
  .step-header { font-size: 11px; }
  .kf-row { flex-wrap: wrap; gap: 0.5rem; }
  .kf-formula-box { min-width: 100%; }

  /* Summary table */
  .summary-table { font-size: 11px; }
  .summary-table td, .summary-table th { padding: 0.35rem 0.5rem; }

  /* Side panels */
  :root { --panel-w: 100vw; }
  .side-panel { width: 100vw !important; border-radius: 0; }
  .panel-overlay { backdrop-filter: blur(4px); }

  /* History panel */
  .hp-entry { padding: 0.75rem; }
  .hp-mode { font-size: 9px; }
  .hp-result { font-size: 12px; }
  .hp-actions { gap: 0.3rem; }
  .hp-btn { padding: 0.35rem 0.6rem; font-size: 9px; }

  /* AI modal */
  .ai-overlay { align-items: flex-end; }
  .ai-modal {
    max-width: 100%;
    width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    margin: 0;
  }
  .ai-body { flex-direction: column; gap: 0.75rem; }
  .ai-col-right { border-left: none; border-top: 1px solid var(--border); padding-top: 0.75rem; }
  .ai-textarea { min-height: 100px; font-size: 12px; }

  /* Expand modal */
  .expand-modal { width: 100vw; height: 100vh; border-radius: 0; max-width: 100%; max-height: 100%; }

  /* Circuit SVG area */
  .circuit-box { padding: 0.75rem; }
  #circuit-svg { height: 200px; }

  /* Welcome */
  .welcome-overlay { padding: 1.5rem 1.25rem; gap: 0.5rem; }
  .welcome-box { max-width: 100%; }
  .welcome-title { font-size: clamp(2.8rem, 14vw, 4rem); }
  .welcome-btn-google { font-size: 11px; padding: 0.85rem; }
  .welcome-input { font-size: 14px; padding: 0.85rem 1rem; }
  .welcome-btn { font-size: 11px; padding: 0.9rem; }

  /* Session chips */
  .session-chip { padding: 0.6rem 0.75rem; }
  .session-chip-avatar { width: 30px; height: 30px; font-size: 12px; }
  .session-chip-name { font-size: 12px; }
  .session-chip-sub { font-size: 9px; }

  /* Settings panel adjustments */
  .sp-section { padding: 0.85rem 1rem; }
  .sp-input { font-size: 14px; padding: 0.65rem 0.75rem; }

  /* Toast */
  .toast { font-size: 11px; padding: 0.55rem 1rem; bottom: 1rem; }

  /* Presentation mode */
  .pres-overlay { padding: 1rem; }
  .pres-top-row { grid-template-columns: 1fr; gap: 0.75rem; }
  .pres-summary-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .pres-metric-val { font-size: clamp(22px, 6vw, 36px); }
  .pres-steps-wrap { grid-template-columns: 1fr; }

  /* n8n confirm toast */
  #n8n-confirm-toast { left: 1rem; right: 1rem; transform: none; white-space: normal; flex-wrap: wrap; }

  /* PIN overlay */
  #pin-overlay { padding: 1.5rem 1rem; gap: 1.25rem; }
  #pin-overlay .pin-key { width: 64px !important; height: 64px !important; font-size: 18px !important; }
  #pin-dots { gap: 10px; }

  /* Add resistor button */
  .add-resistor-btn { font-size: 10px; padding: 0.55rem; }
}

/* ── Very small (≤ 360px) ─────────────────────────────────── */
@media (max-width: 360px) {
  .topbar-btn { width: 32px; height: 32px; }
  .welcome-title { font-size: clamp(2.4rem, 15vw, 3.2rem); }
  .qa-btn { font-size: 9px; }
  #pin-overlay .pin-key { width: 56px !important; height: 56px !important; }
}

/* ── Landscape mobile ─────────────────────────────────────── */
@media (max-width: 640px) and (orientation: landscape) {
  .main-layout { flex-direction: row; }
  .col-left {
    width: 280px !important;
    position: sticky; top: 48px;
    height: calc(100vh - 48px);
    border-right: 1px solid var(--border);
    border-bottom: none;
    overflow-y: auto;
  }
  .welcome-title { font-size: clamp(2rem, 10vw, 3rem); }
  .welcome-overlay { flex-direction: row; flex-wrap: wrap; align-content: center; gap: 1rem; }
  .welcome-box { max-width: 380px; }
}

/* ── High DPI / Retina ─────────────────────────────────────── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .topbar { -webkit-font-smoothing: antialiased; }
  .step-card, .inputs-card, .statement-card { backface-visibility: hidden; }
}

/* ── Safe area (iPhone notch/home bar) ────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .toast { bottom: calc(1rem + env(safe-area-inset-bottom)); }
  .topbar { padding-left: max(0.75rem, env(safe-area-inset-left)); padding-right: max(0.75rem, env(safe-area-inset-right)); }
}

/* mode-tabs-outer scrollable wrapper */
.mode-tabs-outer {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mode-tabs-outer::-webkit-scrollbar { display: none; }
