:root {
  --bg:        #0c0c0e;
  --panel:     #17171a;
  --panel-2:   #202024;
  --border:    #2c2c31;
  --text:      #f4f4f6;
  --text-dim:  #a2a2ab;
  --text-faint:#6e6e77;
  --accent:    #d09e52;   /* ochre: active tab, primary buttons, progress */
  --on-accent: #2f2410;
  --danger:    #c06a3e;   /* terracotta: destructive + wrong answers (with icon/label, never color-only) */
  --sage:      #b9b98f;   /* correct answers, positive counts */
  --radius: 14px;
  --bottom-chrome-h: calc(64px + env(safe-area-inset-bottom));
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

/* ---------- base reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

a { color: var(--accent); }

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.hidden { display: none !important; }

/* ---------- header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

#screen-title-slot {
  font-size: 20px;
  font-weight: 600;
  flex: 1;
  text-align: right;
}

/* ---------- main / screens ---------- */

main {
  min-height: 100vh;
}

main section {
  padding: 16px 16px var(--bottom-chrome-h);
}

/* ---------- tabbar ---------- */

.tabbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  z-index: 30;
  display: flex;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

body.mode-mock .tabbar { display: none; }

.tabbar-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: 8px 4px;
  border-radius: 16px;
  color: var(--text-faint);
}

.tabbar-icon { stroke: currentColor; }

.tabbar-label {
  font-size: 10px;
  font-weight: 500;
}

.tabbar-btn.active {
  color: var(--accent);
}

.tabbar-btn.active .tabbar-icon { stroke: var(--accent); }

/* ---------- cards ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-hero {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  margin-bottom: 16px;
}

.card-hero .hero-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.card-hero .hero-figure {
  font-size: 34px;
  font-weight: 700;
  margin-bottom: 14px;
}

/* ---------- buttons / chips ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  min-height: 48px;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ---------- rows / badges ---------- */

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.row:last-child { border-bottom: none; }

.row .row-label { font-size: 14px; }
.row .row-value { color: var(--text-dim); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.row .chevron { color: var(--text-faint); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
}

/* ---------- sheet / scrim / toast ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  transition: opacity 200ms var(--ease);
}

.scrim.open { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 6vh;
  z-index: 41;
  background: var(--panel);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  overflow-y: auto;
  transform: translateY(100%);
  opacity: 0;
  transition: transform 200ms var(--ease), opacity 200ms var(--ease);
}

.sheet.open {
  transform: translateY(0);
  opacity: 1;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-close {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-chrome-h) + 12px);
  transform: translateX(-50%) translateY(8px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  max-width: 90vw;
}

.toast.open {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- press feedback ---------- */

.press {
  transition: transform 160ms ease-out;
}

.press:active {
  transform: scale(0.97);
}

/* ---------- layout helpers ---------- */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 200ms var(--ease);
}

/* ---------- heatmap ---------- */

.heat {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-flow: column;
  gap: 3px;
}

.heat-cell {
  aspect-ratio: 1 / 1;
  border-radius: 3px;
  background: rgba(208, 158, 82, 0);
}

.heat-cell[data-level="0"] { background: rgba(208, 158, 82, 0.08); }
.heat-cell[data-level="1"] { background: rgba(208, 158, 82, 0.28); }
.heat-cell[data-level="2"] { background: rgba(208, 158, 82, 0.48); }
.heat-cell[data-level="3"] { background: rgba(208, 158, 82, 0.68); }
.heat-cell[data-level="4"] { background: rgba(208, 158, 82, 0.9); }

/* ---------- answer options ---------- */

.opt {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
  color: var(--text);
  transition: border-color 200ms var(--ease), background 200ms var(--ease);
}

.opt-correct {
  border-color: var(--sage);
  background: rgba(185, 185, 143, 0.12);
}

.opt-wrong {
  border-color: var(--danger);
  background: rgba(192, 106, 62, 0.12);
}

/* ---------- inputs ---------- */

input[type="text"],
input[type="number"],
input[type="search"],
textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

textarea {
  resize: vertical;
  min-height: 90px;
}

/* ---------- SRS rating buttons ---------- */

.srs-ratings {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.srs-rating-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 12px;
  font-weight: 600;
  min-height: 48px;
  text-align: center;
}

.srs-rating-again { background: rgba(192, 106, 62, 0.16); color: var(--danger); }
.srs-rating-hard { background: var(--panel-2); color: var(--text); }
.srs-rating-good { background: var(--panel-2); color: var(--text); }
.srs-rating-easy { background: rgba(185, 185, 143, 0.16); color: var(--sage); }

/* ---------- mock countdown ---------- */

.mock-countdown {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.mock-countdown.danger {
  color: var(--danger);
}

/* ---------- answer feedback flashes ---------- */

.feedback-correct {
  border-color: var(--sage) !important;
  transition: border-color 200ms var(--ease);
}

.feedback-wrong {
  border-color: var(--danger) !important;
  transition: border-color 200ms var(--ease);
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* integration: modal internals emitted by core.js */
.sheet-title {
  font-size: 17px;
  font-weight: 600;
}

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}
