:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --ink: #17201a;
  --muted: #627066;
  --panel: #fffdf8;
  --line: #ded8cc;
  --green: #1e6b4e;
  --green-2: #dceee6;
  --red: #a83b2d;
  --red-2: #f8dfda;
  --blue: #315f8f;
  --gold: #c59a28;
  --shadow: 0 18px 45px rgba(35, 42, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.55), rgba(255,255,255,0)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1.05;
  letter-spacing: 0;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--line);
  border-radius: 8px;
}

.score-strip div {
  min-width: 82px;
  padding: 12px 14px;
  background: var(--panel);
  text-align: center;
}

.score-strip span {
  display: block;
  font-size: 24px;
  font-weight: 850;
}

.score-strip small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.study-panel {
  border: 1px solid var(--line);
  background: rgba(255,253,248,0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 20px;
  border-radius: 8px;
  padding: 16px;
}

.study-panel {
  min-height: 620px;
  border-radius: 8px;
  padding: 22px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f0ece4;
}

.mode-button {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.mode-button.active {
  background: var(--ink);
  color: white;
}

.field-label,
.range-row label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
}

.toggle-row {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--ink);
  font-weight: 700;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.command-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  margin-bottom: 18px;
}

.sync-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.sync-input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
}

.sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sync-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.sync-status.good {
  color: var(--green);
}

.sync-status.bad {
  color: var(--red);
}

.sync-toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 50;
  width: min(420px, calc(100vw - 28px));
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  font-weight: 850;
  text-align: center;
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.sync-toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.sync-toast.good {
  background: var(--green);
}

.sync-toast.bad {
  background: var(--red);
}

.primary,
.secondary,
.icon-button,
.flip-button {
  min-height: 44px;
  border-radius: 7px;
  font-weight: 850;
}

.primary {
  background: var(--green);
  color: white;
}

.secondary,
.icon-button,
.flip-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.icon-button {
  font-size: 22px;
  line-height: 1;
}

.chapter-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.chapter-pill {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--muted);
  font-size: 13px;
}

.chapter-pill strong {
  color: var(--ink);
}

.question-meta,
.bottom-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.question-meta {
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 800;
}

.question-surface {
  min-height: 420px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.question-text {
  margin: 0 0 22px;
  font-size: 24px;
  line-height: 1.35;
  font-weight: 820;
}

.options-list {
  display: grid;
  gap: 10px;
}

.option-button {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
  color: var(--ink);
  text-align: left;
}

.option-letter {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 7px;
  background: #ebe6db;
  font-weight: 900;
}

.option-button:hover,
.option-button:focus-visible {
  border-color: var(--blue);
  outline: 0;
}

.option-button.correct {
  border-color: var(--green);
  background: var(--green-2);
}

.option-button.wrong {
  border-color: var(--red);
  background: var(--red-2);
}

.option-button.correct .option-letter {
  background: var(--green);
  color: white;
}

.option-button.wrong .option-letter {
  background: var(--red);
  color: white;
}

.flip-button {
  width: 100%;
  margin-top: 18px;
}

.feedback {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 8px;
  background: #eef3f7;
  border: 1px solid #cfdae5;
  color: var(--ink);
  font-weight: 750;
}

.feedback.good {
  background: var(--green-2);
  border-color: #b7dccb;
}

.feedback.bad {
  background: var(--red-2);
  border-color: #efc0b9;
}

.bottom-actions {
  margin-top: 18px;
}

.bottom-actions button {
  min-width: 148px;
}

.clear-missed {
  min-width: 180px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding: 16px 0;
  }

  .topbar,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 32px;
  }

  .control-panel {
    position: static;
  }

  .study-panel {
    min-height: auto;
    padding: 16px;
  }

  .question-surface {
    min-height: 360px;
    padding: 18px;
  }

  .question-text {
    font-size: 20px;
  }

  .bottom-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .bottom-actions button {
    min-width: 0;
  }
}
