:root {
  color-scheme: light;
  --bg: #f3f1ea;
  --panel: #fffdfa;
  --panel-soft: #edf3ef;
  --ink: #182521;
  --muted: #65736d;
  --line: #d9dfd8;
  --accent: #216a73;
  --accent-strong: #164e56;
  --accent-soft: #dcebed;
  --secondary: #7c4d62;
  --warn: #a13e37;
  --ok: #247451;
  --gold: #946b13;
  --focus: #3c7890;
  --shadow: 0 18px 46px rgba(38, 48, 43, 0.12);
  --shadow-soft: 0 8px 24px rgba(38, 48, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: 0;
}

body.drawer-active {
  overflow: hidden;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(24, 37, 33, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body.drawer-active .drawer-overlay {
  opacity: 1;
  pointer-events: auto;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfaf5;
  box-shadow: 8px 0 26px rgba(38, 48, 43, 0.04);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  color: var(--accent-strong);
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 44px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.search-block {
  display: grid;
  gap: 8px;
}

.search-block label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.search-block input,
.note-editor textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.search-block input {
  height: 40px;
  padding: 0 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.search-block input:focus,
.note-editor textarea:focus,
.note-summary-input:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 160, 0.18);
}

.subject-nav,
.topic-chips,
.segmented,
.storage-actions,
.quiz-actions,
.answer-actions,
.topbar-controls {
  display: flex;
  gap: 8px;
}

.subject-nav {
  flex-direction: column;
  overflow: auto;
}

.subject-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 46px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.subject-button span:first-child {
  overflow-wrap: anywhere;
}

.subject-button small {
  color: var(--muted);
}

.subject-button.active,
.subject-button:hover {
  border-color: rgba(33, 106, 115, 0.28);
  background: var(--accent-soft);
}

.subject-button:hover {
  transform: translateX(2px);
}

.storage-actions {
  margin-top: auto;
}

.storage-actions button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.file-button input {
  display: none;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 70px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.9);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}

.topbar-controls {
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.segmented {
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.segmented button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--accent);
  color: white;
}

.list-toggle,
.drawer-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.progress-summary {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(270px, 360px) minmax(0, 1fr);
  gap: 20px;
  min-height: 0;
  padding: 20px 22px 24px;
}

.content-grid.notes-view {
  grid-template-columns: minmax(0, 1fr);
}

.content-grid.notes-view .question-list-panel {
  display: none;
}

.question-list-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: calc(100vh - 110px);
}

.topic-chips {
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.topic-chip {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.topic-chip.active {
  border-color: rgba(33, 106, 115, 0.4);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.question-list {
  display: grid;
  align-content: start;
  gap: 9px;
  overflow: auto;
  padding-right: 2px;
}

.question-card {
  display: grid;
  gap: 7px;
  min-height: 94px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
  box-shadow: var(--shadow-soft);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.question-card.active {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.question-card:hover {
  transform: translateY(-1px);
  border-color: rgba(33, 106, 115, 0.36);
}

.question-card-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
}

.question-card-title span {
  overflow-wrap: anywhere;
}

.status-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--line);
}

.status-dot.correct {
  background: var(--ok);
}

.status-dot.incorrect {
  background: var(--warn);
}

.question-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef3ee;
  color: var(--muted);
  font-size: 12px;
}

.pill.flagged {
  background: #fff4d7;
  color: var(--gold);
}

.quiz-panel {
  min-width: 0;
  min-height: calc(100vh - 110px);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  color: var(--muted);
  text-align: center;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.quiz-header h2 {
  margin: 8px 0 0;
  font-size: 26px;
  line-height: 1.2;
  color: var(--accent-strong);
}

.quiz-actions button,
.answer-actions button,
.open-question {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.quiz-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.quiz-actions button.active {
  border-color: var(--gold);
  background: #fff4d7;
  color: var(--gold);
}

.quiz-actions button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.62;
}

.prompt {
  max-width: 86ch;
  margin-bottom: 18px;
  line-height: 1.68;
  white-space: pre-line;
  font-size: 16px;
}

.choices {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.choice {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf5;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.choice:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.choice input {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--accent);
}

.choice.correct {
  border-color: rgba(40, 121, 79, 0.6);
  background: #edf7f1;
}

.choice.incorrect {
  border-color: rgba(163, 61, 47, 0.55);
  background: #fff0ee;
}

.choice-label {
  font-weight: 700;
}

.choice-text {
  line-height: 1.48;
  white-space: pre-line;
}

.answer-actions {
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

.primary {
  border-color: var(--accent) !important;
  background: var(--accent) !important;
  color: #fff !important;
}

.primary:disabled {
  border-color: var(--line) !important;
  background: #dbe2dd !important;
  color: var(--muted) !important;
  cursor: not-allowed;
}

.result {
  font-weight: 700;
}

.result.correct {
  color: var(--ok);
}

.result.incorrect {
  color: var(--warn);
}

.explanation {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.explanation h3,
.note-editor h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.explanation p {
  max-width: 86ch;
  margin: 0;
  line-height: 1.58;
  white-space: pre-line;
}

.note-editor {
  margin-top: 22px;
}

.note-editor textarea,
.note-summary-input {
  min-height: 120px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

.notes-panel h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.notes-panel p {
  margin: 6px 0 0;
  color: var(--muted);
}

.notes-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.note-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf5;
  box-shadow: var(--shadow-soft);
}

.note-card-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.note-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.3;
}

.note-question {
  max-width: 100ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.note-summary-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

@media (max-width: 1180px) {
  .app-shell,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(340px, calc(100vw - 38px));
    height: 100dvh;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(-106%);
    transition: transform 190ms ease;
    box-shadow: 22px 0 52px rgba(24, 37, 33, 0.22);
  }

  body.subject-drawer-open .sidebar {
    transform: translateX(0);
  }

  .subject-nav {
    display: flex;
    flex-direction: column;
  }

  .storage-actions {
    margin-top: 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .drawer-toggle,
  .list-toggle {
    display: inline-flex;
  }

  .segmented {
    overflow: auto;
  }

  .content-grid {
    padding: 18px;
  }

  .question-list-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 42;
    width: min(420px, calc(100vw - 38px));
    height: 100dvh;
    min-height: 0;
    padding: 18px;
    border-right: 1px solid var(--line);
    background: var(--panel);
    box-shadow: 22px 0 52px rgba(24, 37, 33, 0.22);
    transform: translateX(-106%);
    visibility: hidden;
    transition: transform 190ms ease, visibility 190ms ease;
    overflow: auto;
  }

  body.list-drawer-open .question-list-panel {
    transform: translateX(0);
    visibility: visible;
  }

  .content-grid.list-collapsed .question-list-panel {
    transform: translateX(-106%);
    visibility: hidden;
  }

  .question-list {
    overflow: visible;
  }

  .quiz-panel {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .topbar,
  .content-grid,
  .quiz-panel {
    padding: 14px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .quiz-header {
    flex-direction: column;
  }

  .note-card-header {
    flex-direction: column;
  }

  .segmented button {
    padding: 0 10px;
  }
}
