:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --panel: #fffdf8;
  --ink: #1f2528;
  --muted: #687076;
  --line: #ded8cd;
  --accent: #1f6f78;
  --accent-strong: #165760;
  --study: #b43d2a;
  --uncertain: #9a6a12;
  --known: #2f7350;
  --shadow: 0 12px 36px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(16px, 4vw, 44px) 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.8rem);
  line-height: 1.08;
}

.progress {
  display: grid;
  grid-template-columns: repeat(3, minmax(94px, 1fr));
  gap: 8px;
  min-width: min(100%, 430px);
}

.progress span {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3eee5;
  color: var(--muted);
  font-size: 0.86rem;
}

.progress strong {
  display: block;
  color: var(--ink);
  font-size: 1.2rem;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 4vw, 28px) 36px;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-button,
.primary-button,
.secondary-button,
.file-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.tab-button.active,
.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button:hover,
.tab-button:hover,
.file-button:hover {
  border-color: var(--accent);
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(130px, 0.8fr) minmax(180px, 1.4fr) auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.toolbar label {
  display: grid;
  gap: 5px;
}

.toolbar span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.toolbar input,
.toolbar select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
}

.file-button {
  display: inline-grid;
  place-items: center;
  text-align: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.source-line {
  min-height: 24px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.line-list {
  display: grid;
  gap: 12px;
}

.line-card {
  display: grid;
  grid-template-columns: minmax(84px, 120px) 1fr;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.line-card.own-line {
  border-left: 5px solid var(--accent);
}

.line-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.scene-name {
  display: block;
  color: var(--ink);
  font-weight: 700;
}

.character-name {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.line-text {
  margin: 0;
  white-space: pre-wrap;
}

.line-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.hidden-line {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f3eee5;
  color: var(--muted);
}

.line-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.status-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.status-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: #fbfaf7;
  color: var(--ink);
  cursor: pointer;
}

.status-button[data-status="study"].active {
  border-color: var(--study);
  background: #fff0ec;
  color: var(--study);
}

.status-button[data-status="uncertain"].active {
  border-color: var(--uncertain);
  background: #fff6de;
  color: var(--uncertain);
}

.status-button[data-status="known"].active {
  border-color: var(--known);
  background: #eef8f1;
  color: var(--known);
}

.quiz-layout {
  display: grid;
  gap: 12px;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

.quiz-card {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 4vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.line-label {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.cue-text,
.masked-answer {
  margin: 0;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
}

.answer-box {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3eee5;
}

.masked-answer {
  color: var(--muted);
}

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 760px) {
  .app-header {
    display: grid;
    align-items: start;
  }

  .progress,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .line-card {
    grid-template-columns: 1fr;
  }

  .line-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }
}

@media (max-width: 430px) {
  .app-header {
    padding-top: 22px;
  }

  .progress {
    grid-template-columns: 1fr;
  }

  .view-tabs,
  .quiz-actions,
  .line-actions,
  .status-group {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tab-button,
  .primary-button,
  .secondary-button,
  .file-button,
  .status-button {
    width: 100%;
  }
}
