:root {
  color-scheme: light dark;
  --bg: #f7f6f3;
  --panel: #ffffff;
  --text: #22201d;
  --muted: #6b6660;
  --border: #e2ded7;
  --accent: #8a5a3b;
  --accent-contrast: #ffffff;
  --correct: #3f7d4f;
  --partial: #b8862f;
  --incorrect: #b04a3f;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a18;
    --panel: #262320;
    --text: #ece8e3;
    --muted: #a8a29a;
    --border: #3a3530;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.topbar {
  padding: 1rem 1rem 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
}

.tab-btn {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  padding: 1rem;
  max-width: 720px;
  margin: 0 auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.banner {
  background: #fdecea;
  color: #7a2b20;
  border: 1px solid #f2b8ae;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
  color: var(--accent);
}

h2:first-child { margin-top: 0; }

.task-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  margin-bottom: 0.6rem;
}

.task-prompt {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.task-input {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.task-reveal {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

.task-solution {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.3rem;
}

.task-explanation {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
}

.tier-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tier-buttons button {
  padding: 0.35rem 0.7rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
}

.tier-buttons button.selected[data-tier="correct"] { background: var(--correct); color: #fff; border-color: var(--correct); }
.tier-buttons button.selected[data-tier="partial"] { background: var(--partial); color: #fff; border-color: var(--partial); }
.tier-buttons button.selected[data-tier="incorrect"] { background: var(--incorrect); color: #fff; border-color: var(--incorrect); }

.tier-buttons button.suggested:not(.selected) {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

button {
  font-family: inherit;
}

#check-all-btn, #save-btn, #retry-load-btn {
  display: inline-block;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.95rem;
  cursor: pointer;
  margin: 0.8rem 0;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

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

.score-summary {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin: 0.8rem 0;
  font-weight: 600;
}

.stats-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.stat-tile {
  flex: 1 1 100px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  text-align: center;
}

.stat-tile .value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-tile .label {
  font-size: 0.75rem;
  color: var(--muted);
}

.history-day {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.history-day .day-date { font-weight: 600; }
.history-day .day-score { color: var(--muted); font-size: 0.85rem; }

label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  color: var(--muted);
}

label input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
}

.btn-row {
  display: flex;
  gap: 0.6rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

img { max-width: 100%; }
[hidden] { display: none !important; }
