:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-muted: #f5f7fb;
  --text: #172033;
  --muted: #7a8496;
  --line: #e5eaf2;
  --accent: #6676ff;
  --accent-dark: #4355d9;
  --danger: #b8463e;
  --ok: #1d8a5d;
  --shadow: 0 10px 30px rgba(34, 45, 80, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: 70px minmax(0, calc(100vh - 70px));
  height: 100vh;
  overflow: hidden;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: 0 1px 12px rgba(34, 45, 80, 0.04);
  z-index: 10;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  color: #526079;
  font-size: 22px;
}

.icon-button:hover,
.answer-tools button:hover,
.translation-controls button:hover {
  background: #edf1ff;
  color: var(--accent-dark);
}

.header-divider {
  width: 1px;
  height: 30px;
  background: var(--line);
}

.title-block {
  min-width: 0;
}

.eyebrow {
  display: none;
}

.app-header h1 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 22px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #fbfcff;
  padding: 18px;
  transition: margin-left 180ms ease, opacity 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .sidebar {
  margin-left: -300px;
  opacity: 0;
  pointer-events: none;
}

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

.brand h2 {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  line-height: 1.25;
}

.form-hint {
  color: var(--muted);
}

.sort-controls {
  display: flex;
}

.sort-controls button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: #fff;
  color: #526079;
  font-size: 17px;
  line-height: 1;
}

.sort-controls button:hover,
.sort-controls button:focus-visible {
  border-color: rgba(102, 118, 255, 0.42);
  background: #eef1ff;
  color: var(--accent-dark);
}

.access-form {
  margin: 18px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.access-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.access-row {
  display: flex;
  gap: 8px;
}

.access-row input {
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.access-row button,
.answer-actions button,
.section-heading button {
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
}

.form-hint {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.45;
}

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

.year-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.year-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 10px 11px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.year-header span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.text-list {
  display: grid;
  gap: 6px;
  padding: 0 9px 9px;
}

.text-button {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  width: 100%;
  border-radius: 8px;
  padding: 9px;
  background: var(--panel-muted);
  color: var(--text);
  text-align: left;
}

.text-button.is-active {
  outline: 2px solid rgba(102, 118, 255, 0.32);
  background: #eef1ff;
}

.text-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

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

.score-badge {
  border-radius: 999px;
  padding: 2px 7px;
  background: #e9edf6;
  color: var(--muted);
  font-size: 12px;
}

.score-badge.done {
  background: #e1f5ec;
  color: var(--ok);
}

.main {
  min-width: 0;
  min-height: 0;
  padding: 14px 16px 16px;
  overflow: hidden;
}

.notice {
  margin-bottom: 10px;
  border: 1px solid #eed59c;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff8e5;
  color: #89610c;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 0.95fr);
  gap: 16px;
  min-height: 0;
  height: 100%;
}

.reading-panel,
.answer-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-toolbar,
.answer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  padding: 13px 16px;
  background: rgba(255, 255, 255, 0.94);
}

.panel-toolbar h2,
.answer-head h2 {
  margin: 0;
  font-size: 16px;
}

.panel-toolbar p,
.answer-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.translation-controls,
.answer-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.translation-menu {
  position: relative;
}

.translation-controls button,
.answer-tools button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  background: #fff;
  color: #526079;
  box-shadow: 0 2px 8px rgba(34, 45, 80, 0.05);
}

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

.translation-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  display: grid;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.translation-dropdown button {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  text-align: left;
}

.translation-dropdown button + button {
  border-top: 1px solid var(--line);
}

.passage-content {
  min-height: 0;
  overflow-y: auto;
  padding: 24px 22px 32px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  line-height: 1.65;
}

.passage-block {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  margin-bottom: 26px;
}

.paragraph-index {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: #1e2a40;
  color: #fff;
  font-family: Inter, ui-sans-serif, system-ui;
  font-size: 14px;
  font-weight: 700;
}

.paragraph-body p {
  margin: 0 0 11px;
}

.sentence-row {
  margin-bottom: 16px;
}

.translation-line {
  color: #657086;
  font-family: Inter, ui-sans-serif, system-ui;
  font-size: 16px;
  line-height: 1.7;
}

.answer-form {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}

.question-list {
  display: grid;
  gap: 16px;
  padding: 18px 22px;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.question-card.is-correct {
  border-color: rgba(29, 138, 93, 0.45);
}

.question-card.is-wrong {
  border-color: rgba(184, 70, 62, 0.45);
}

.question-title {
  display: flex;
  gap: 10px;
  margin: 0 0 13px;
  color: #1e283a;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.5;
}

.question-number {
  display: inline-grid;
  min-width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 999px;
  background: #1e2a40;
  color: #fff;
  font-family: Inter, ui-sans-serif, system-ui;
  font-size: 13px;
}

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

.option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  color: #344052;
}

.option input {
  margin-top: 4px;
}

.option.correct {
  border-color: rgba(29, 138, 93, 0.5);
  background: #edf8f1;
}

.option.selected-wrong {
  border-color: rgba(184, 70, 62, 0.5);
  background: #fff0ee;
}

.question-analysis {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.analysis-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  color: var(--accent-dark);
}

.analysis-detail {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  color: #354055;
  line-height: 1.7;
}

.answer-summary {
  display: flex;
  gap: 2ch;
  flex-wrap: wrap;
}

.answer-value.correct {
  color: var(--ok);
  font-weight: 700;
}

.answer-value.wrong {
  color: var(--danger);
  font-weight: 700;
}

.answer-value.muted {
  color: var(--muted);
  font-weight: 700;
}

.analysis-section {
  display: grid;
  gap: 6px;
}

.analysis-label {
  color: var(--accent-dark);
}

.analysis-section p {
  color: #354055;
}

.analysis-detail p,
.distractor-analysis p {
  margin: 0;
}

.distractor-analysis {
  display: grid;
  gap: 7px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  color: #465166;
}

.answer-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 0 8px;
}

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

.result-panel {
  flex: 0 0 auto;
  max-height: 36%;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  background: #f8fafc;
}

.result-score {
  margin: 0 0 10px;
  font-size: 19px;
  font-weight: 700;
}

.analysis-text {
  color: var(--muted);
  line-height: 1.65;
}

.history-panel {
  flex: 0 0 auto;
  max-height: 34%;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  background: #fff;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-heading h3 {
  margin: 0;
  font-size: 15px;
}

.section-heading button {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--line);
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  text-align: left;
}

.history-item:hover,
.history-item.is-active {
  border-color: rgba(102, 118, 255, 0.42);
  background: #eef1ff;
}

.empty-state {
  color: var(--muted);
}

.hidden {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.36);
}

.confirm-dialog {
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.confirm-dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.confirm-dialog p {
  margin: 0;
  color: #465166;
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.confirm-actions button {
  border-radius: 8px;
  padding: 9px 13px;
}

.confirm-actions .secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: #526079;
}

.confirm-actions .danger {
  background: var(--danger);
  color: #fff;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 270px minmax(0, 1fr);
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .reading-panel {
    min-height: 48vh;
  }

  .answer-panel {
    min-height: 70vh;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 64px auto minmax(0, 1fr);
    overflow: auto;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .app-shell.sidebar-collapsed .sidebar {
    display: none;
  }

  .main {
    overflow: visible;
    padding: 10px;
  }

  .workspace {
    display: flex;
    height: auto;
    flex-direction: column;
    gap: 10px;
    overflow: visible;
  }

  .reading-panel {
    height: 46vh;
    min-height: 360px;
  }

  .answer-panel {
    height: auto;
    min-height: 70vh;
  }

  .panel-toolbar,
  .answer-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .passage-content {
    padding: 18px 14px 24px;
    font-size: 18px;
  }

  .question-list {
    overflow: visible;
    padding: 14px;
  }

  .answer-form {
    overflow: visible;
  }

  .result-panel,
  .history-panel {
    max-height: none;
  }
}
