:root{
  color-scheme: light;

  --bg: #ffffff;
  --fg: #111827;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #cbd5e1;
  --shadow: 0 8px 30px rgba(0,0,0,.06);
  --primary: #111827;
  --primary-contrast: #ffffff;
  --secondary: #f3f4f6;
  --surface: #f8fafc;
  --focus: rgba(37, 99, 235, .35);
  --chip: #f3f4f6;
  --chip-fg: #111827;
  --link: #1f2937;
  --toast-bg: rgba(17,24,39,.92);
  --toast-fg: #ffffff;
  --switch-track: #e5e7eb;
  --switch-track-active: #cbd5e1;
  --switch-knob: #ffffff;

  --radius: 16px;
  --radius-sm: 12px;
  --container: 1040px;

  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

:root[data-theme="dark"]{
  color-scheme: dark;

  --bg: #0b1220;
  --fg: #e5e7eb;
  --muted: #9ca3af;
  --card: #0f172a;
  --border: rgba(148,163,184,.22);
  --border-strong: rgba(148,163,184,.4);
  --shadow: 0 12px 38px rgba(0,0,0,.5);
  --primary: #f8fafc;
  --primary-contrast: #0b1220;
  --secondary: rgba(148,163,184,.16);
  --surface: rgba(148,163,184,.10);
  --focus: rgba(96, 165, 250, .35);
  --chip: rgba(148,163,184,.15);
  --chip-fg: #e5e7eb;
  --link: #e5e7eb;
  --toast-bg: rgba(229,231,235,.92);
  --toast-fg: #0b1220;
  --switch-track: rgba(148,163,184,.28);
  --switch-track-active: rgba(248,250,252,.35);
  --switch-knob: #f8fafc;
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

a{ color: inherit; text-decoration: none; }
a.link{ text-decoration: underline; text-underline-offset: 4px; color: var(--link); }
strong{ font-weight: 650; }

button,
input,
select,
textarea{
  font: inherit;
}

button,
.btn,
.icon-btn,
.seg,
.switch,
.shortcut-key,
.shortcut-action{
  color: var(--fg);
}

input[type="checkbox"],
input[type="radio"],
input[type="range"]{
  accent-color: var(--primary);
}

.app-header{
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in oklab, var(--bg) 84%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner{
  max-width: var(--container);
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 12px;
}
.brand:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}
.brand-mark{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--secondary);
  border: 1px solid var(--border);
  font-weight: 700;
}
.brand-text{
  font-weight: 700;
  letter-spacing: .2px;
}
.header-actions{
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-main{
  padding: 22px 0 60px;
}
.container{
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 18px;
}
.view{ display: none; }
.view.view-active{ display: block; }
.title{
  font-size: clamp(26px, 3vw, 34px);
  letter-spacing: -.02em;
  margin: 12px 0 18px;
}
.subtitle{
  font-size: 16px;
  margin: 0;
}
.muted{ color: var(--muted); }
.small{ font-size: 13px; }
.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.grid{
  display: grid;
  grid-template-columns: 1.12fr .88fr;
  gap: 16px;
  padding: 16px;
}
.stack{ display:flex; flex-direction: column; gap: 14px; }
.button-stack{ display:flex; flex-direction: column; gap: 10px; }
.button-stack .btn{ width: 100%; }
.gap-xs{ gap: 8px; }
.pad-top{ padding-top: 14px; }
.row{ display:flex; }
.wrap{ flex-wrap: wrap; }
.align-center{ align-items: center; }
.align-start{ align-items: flex-start; }
.space-between{ justify-content: space-between; }
.gap-sm{ gap: 10px; }
.spacer{ flex: 1; }
.footer{
  margin-top: 14px;
  padding: 0 4px;
}

.btn{
  border: 1px solid var(--border);
  background: transparent;
  padding: 10px 12px;
  border-radius: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
  user-select: none;
}
.btn:hover{ background: color-mix(in oklab, var(--secondary) 75%, transparent); }
.btn:active{ transform: translateY(1px); }
.btn:focus-visible{ outline:none; box-shadow: 0 0 0 4px var(--focus); }
.btn-primary{
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: color-mix(in oklab, var(--primary) 80%, var(--border));
}
.btn-primary:hover{
  background: color-mix(in oklab, var(--primary) 92%, white);
}
.btn-secondary{
  background: color-mix(in oklab, var(--secondary) 92%, transparent);
}
.btn-ghost{
  background: transparent;
}
.btn-sm{
  padding: 6px 9px;
  border-radius: 10px;
  font-size: 12px;
}

.icon-btn{
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 70%, transparent);
  cursor: pointer;
  transition: background .15s ease, transform .06s ease, border-color .15s ease;
}
.icon-btn:hover{ background: color-mix(in oklab, var(--secondary) 90%, transparent); }
.icon-btn:active{ transform: translateY(1px); }
.icon-btn:focus-visible{ outline:none; box-shadow: 0 0 0 4px var(--focus); }
.icon-btn svg{ width: 20px; height: 20px; fill: currentColor; opacity: .92; }
.icon-btn-big{
  width: 46px;
  height: 46px;
  border-radius: 16px;
}
.icon-btn.is-active{
  background: color-mix(in oklab, var(--primary) 12%, var(--secondary));
  border-color: color-mix(in oklab, var(--primary) 30%, var(--border));
}

.input{
  width: 120px;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
}
.input:focus-visible{ outline:none; box-shadow: 0 0 0 4px var(--focus); }
.field{ display:flex; flex-direction: column; gap: 8px; }
.field.is-hidden{ display: none; }
.select-input{
  width: 100%;
  min-width: 0;
}
.label{
  font-weight: 650;
  display:flex;
  align-items:center;
  justify-content: space-between;
}
.hint{ color: var(--muted); font-size: 13px; }

input[type="range"]{
  width: 100%;
}

.switch{
  position: relative;
  width: 52px;
  height: 30px;
  display: inline-block;
}
.switch input{
  position: absolute;
  inset: 0;
  opacity: 0;
}
.slider{
  position:absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--switch-track);
  border: 1px solid var(--border);
  transition: .2s;
}
.slider::after{
  content:"";
  position:absolute;
  top: 50%;
  left: 3px;
  width: 22px;
  height: 22px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--switch-knob);
  border: 1px solid color-mix(in oklab, var(--border) 75%, transparent);
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
  transition: .2s;
}
.switch input:focus-visible + .slider{
  box-shadow: 0 0 0 4px var(--focus);
}
.switch input:checked + .slider{
  background: var(--switch-track-active);
}
.switch input:checked + .slider::after{
  left: 25px;
}

.segmented{
  display:flex;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: transparent;
}
.seg{
  flex: 1;
  display:flex;
  align-items:center;
  justify-content: center;
  gap: 8px;
  padding: 10px 10px;
  cursor: pointer;
  user-select: none;
  background: transparent;
}
.seg input{ display:none; }
.seg span{ font-weight: 650; }
.seg:has(input:checked){
  background: color-mix(in oklab, var(--secondary) 78%, transparent);
}

.themes-grid{
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.theme-card{
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 80%, transparent);
  min-height: 112px;
}
.theme-card.is-selected{
  background: color-mix(in oklab, var(--secondary) 88%, transparent);
  border-color: color-mix(in oklab, var(--border) 70%, var(--primary));
}
.theme-card-header{
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.theme-check{
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--card);
  margin: 2px 0 0;
  flex: 0 0 auto;
  position: relative;
  cursor: pointer;
}
.theme-check:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}
.theme-check:checked{
  background: var(--primary);
  border-color: var(--primary);
}
.theme-check:checked::after{
  content:"";
  position:absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid var(--primary-contrast);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.theme-title-wrap{
  min-width: 0;
  flex: 1;
}
.theme-fold-btn{
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex: 0 0 auto;
}
.theme-fold-btn svg{
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-name{
  font-weight: 700;
  line-height: 1.3;
}
.theme-count{
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--secondary) 60%, transparent);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}
.theme-columns{
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.theme-subthemes{
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.theme-subhead{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.theme-subtitle{
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.subtheme-actions{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.subthemes-wrap{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.subtheme-chip{
  position: relative;
  max-width: 100%;
}
.subtheme-chip input{
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}
.subtheme-chip > span{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 78%, transparent);
  cursor: pointer;
  font-size: 13px;
}
.subtheme-label{
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subtheme-chip input:checked + span{
  background: color-mix(in oklab, var(--primary) 12%, var(--secondary));
  border-color: color-mix(in oklab, var(--primary) 28%, var(--border));
}
.subtheme-chip input:focus-visible + span{
  box-shadow: 0 0 0 4px var(--focus);
}
.subtheme-count{
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.session-top{
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.session-head{
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.session-meta-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.session-id-row{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.id-pill{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--secondary) 72%, transparent);
  font-family: var(--mono);
  font-size: 13px;
}
.session-chips{
  padding-top: 4px;
}
.session-card{ padding: 18px; }
.session-nav-buttons{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.session-nav-buttons .btn{
  white-space: nowrap;
}
.question{
  font-size: clamp(18px, 2.1vw, 22px);
  letter-spacing: -.01em;
  margin: 2px 0 10px;
  white-space: pre-wrap;
}
.answer{
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.answer-title{
  font-weight: 750;
  margin-bottom: 8px;
}
.answer-body{ white-space: pre-wrap; }
.hidden{ display: none; }
.source{ margin-top: 10px; }
.source-link{
  display:inline-flex;
  gap: 8px;
  align-items:center;
  text-decoration: underline;
  text-underline-offset: 4px;
  color: var(--link);
}
.source-link::after{
  content:"↗";
  font-family: var(--mono);
  font-size: 12px;
  opacity: .8;
}
.chips{ display:flex; flex-wrap: wrap; gap: 8px; }
.chip{
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--chip-fg);
  border: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--mono);
}
.progress{
  width: 100%;
  height: 10px;
  margin-top: 2px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--secondary) 55%, transparent);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-bar{
  height: 100%;
  background: color-mix(in oklab, var(--primary) 55%, transparent);
  border-right: 1px solid color-mix(in oklab, var(--primary) 55%, var(--border));
  transition: width .2s ease;
}
#sessionFooterHint:empty{ display: none; }

.dialog{
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 720px;
  width: calc(100% - 26px);
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow);
}
.dialog::backdrop{
  background: rgba(0,0,0,.35);
}
.dialog-inner{
  padding: 16px;
}
.dialog-actions{
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 14px;
}
.shortcuts-list{
  margin-top: 12px;
  display:flex;
  flex-direction: column;
  gap: 10px;
}
.shortcut-item{
  display:flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 80%, transparent);
}
.shortcut-action{ font-weight: 700; min-width: 200px; }
.shortcut-key{
  font-family: var(--mono);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--secondary) 60%, transparent);
}
.shortcut-change{ margin-left: auto; }
.help-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}
.help-block{
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 80%, transparent);
  border-radius: 14px;
  padding: 12px;
}
.help-title{
  font-weight: 750;
  margin-bottom: 8px;
}
.help-list{ margin: 0; padding-left: 18px; color: var(--muted); }
.help-list li{ margin: 6px 0; }

.toast{
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, var(--border) 45%, transparent);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: min(560px, calc(100% - 26px));
  text-align: center;
}
.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

@media (max-width: 980px){
  .grid{ grid-template-columns: 1fr; }
}

@media (max-width: 720px){
  .header-inner{
    padding: 12px 14px;
  }
  .container{
    padding: 0 14px;
  }
  .brand-text{
    font-size: 15px;
  }
  .themes-grid{
    grid-template-columns: 1fr;
  }
  .help-grid{
    grid-template-columns: 1fr;
  }
  .session-meta-row{
    align-items: flex-start;
  }
  .session-id-row{
    width: 100%;
    justify-content: flex-start;
  }
  .actions{
    flex-direction: column;
    align-items: stretch;
  }
  .actions .spacer{
    display: none;
  }
  .actions .btn{
    width: 100%;
  }
  .session-nav-buttons{
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
  }
  .session-nav-buttons .btn{
    min-height: 42px;
    padding: 9px 10px;
  }
}

@media (max-width: 560px){
  .theme-subhead{
    flex-direction: column;
    align-items: flex-start;
  }
  .shortcut-item{
    flex-direction: column;
    align-items: flex-start;
  }
  .shortcut-action{
    min-width: 0;
  }
  .shortcut-change{
    margin-left: 0;
  }
  .input{
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce){
  *{ transition: none !important; scroll-behavior: auto !important; }
}

.btn:disabled,
.icon-btn:disabled{
  opacity: .55;
  cursor: not-allowed;
  pointer-events: none;
}
select,
.select-input{
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  color-scheme: light dark;
}

select option,
.select-input option{
  background: var(--card);
  color: var(--fg);
}