:root {
  color-scheme: light;
  --ink: #171613;
  --muted: #68645a;
  --paper: #faf7ef;
  --panel: #fffdf7;
  --line: #ddd5c7;
  --accent: #0d6b64;
  --accent-2: #c4462f;
  --gold: #b7831f;
  --good: #177245;
  --bad: #b4382d;
  --shadow: 0 18px 45px rgba(44, 36, 20, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(23, 22, 19, 0.035) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(rgba(23, 22, 19, 0.03) 1px, transparent 1px) 0 0 / 34px 34px,
    var(--paper);
  color: var(--ink);
  font-family: Charter, "Iowan Old Style", Georgia, serif;
}

button,
input {
  font: inherit;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.86);
  backdrop-filter: blur(10px);
  padding: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  background: var(--accent);
  color: #fffdf7;
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 5px 5px 0 var(--gold);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 27px;
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  margin-top: 7px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 20px;
}

.filter,
.ghost-button,
.check-button,
.submit-button,
.topic-group-toggle,
.topic-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.filter {
  min-height: 38px;
}

.filter.is-active,
.topic-button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.topic-group {
  margin-top: 18px;
}

.topic-group-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  margin: 0 0 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--accent-2);
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0 2px 7px;
  text-align: left;
  text-transform: uppercase;
}

.topic-group-toggle::before {
  content: "▾";
  grid-column: 2;
  grid-row: 1;
  color: var(--muted);
  font-size: 13px;
  transform: translateY(-1px);
}

.topic-group-count {
  grid-column: 2;
  grid-row: 1;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  padding: 2px 20px 2px 6px;
}

.topic-group.is-collapsed .topic-group-toggle::before {
  content: "▸";
}

.topic-group.is-collapsed .topic-items {
  display: none;
}

.topic-button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  text-align: left;
  padding: 12px;
  margin: 8px 0;
  border-radius: 8px;
}

.topic-button strong {
  line-height: 1.15;
}

.topic-button span {
  color: inherit;
  opacity: 0.74;
  font-size: 13px;
}

.topic-badge {
  align-self: start;
  min-width: 42px;
  text-align: center;
  border: 1px solid currentColor;
  padding: 3px 6px;
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-weight: 800;
}

.workspace {
  padding: 28px clamp(18px, 4vw, 58px) 54px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 24px;
}

.eyebrow {
  color: var(--accent-2);
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  max-width: 820px;
  font-size: clamp(38px, 6vw, 78px);
  line-height: 0.92;
  letter-spacing: 0;
  margin-top: 8px;
}

.score-tile {
  min-width: 158px;
  border: 2px solid var(--ink);
  background: var(--panel);
  box-shadow: 6px 6px 0 var(--accent);
  padding: 14px;
  text-align: right;
}

.score-tile span,
.stat span,
label span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.sync-status {
  display: flex;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.74);
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
}

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

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

.score-tile strong {
  display: block;
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 38px;
  line-height: 1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
  margin: 22px 0;
}

.stat,
.ghost-button,
.check-button,
.submit-button {
  border-radius: 8px;
  min-height: 48px;
}

.stat {
  min-width: 128px;
  background: rgba(255, 253, 247, 0.74);
  border: 1px solid var(--line);
  padding: 8px 12px;
}

.stat strong {
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 24px;
}

.ghost-button,
.check-button,
.submit-button {
  padding: 0 16px;
}

.ghost-button:hover,
.check-button:hover,
.submit-button:hover,
.filter:hover,
.topic-group-toggle:hover,
.topic-button:hover {
  transform: translateY(-1px);
}

.result-panel {
  border-left: 6px solid var(--accent);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 22px;
  border-radius: 8px;
}

.result-panel.is-hidden {
  display: none;
}

.result-panel strong {
  color: var(--accent);
}

.quiz-form {
  display: grid;
  gap: 16px;
}

.question-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 8px 22px rgba(44, 36, 20, 0.07);
}

.question-card.is-correct {
  border-color: rgba(23, 114, 69, 0.55);
}

.question-card.is-wrong {
  border-color: rgba(180, 56, 45, 0.55);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.question-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
}

.question-meta .qid {
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 700;
}

.question-scan {
  margin: 0 0 16px;
  padding: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.question-scan img {
  display: block;
  width: 100%;
  height: auto;
}

.prompt {
  white-space: pre-wrap;
  margin: 0;
  font-family: Charter, "Iowan Old Style", Georgia, serif;
  font-size: 15px;
  line-height: 1.42;
}

.text-panel {
  margin: -4px 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 247, 239, 0.7);
  overflow: hidden;
}

.text-panel summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  cursor: pointer;
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-weight: 800;
  text-transform: uppercase;
}

.text-panel .prompt {
  border-top: 1px solid var(--line);
  padding: 12px;
}

label {
  display: grid;
  gap: 6px;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 11px;
}

input:focus {
  outline: 2px solid rgba(13, 107, 100, 0.32);
  border-color: var(--accent);
}

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

.check-button {
  min-height: 40px;
  border-color: rgba(13, 107, 100, 0.35);
  color: var(--accent);
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
}

.feedback {
  display: none;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(221, 213, 199, 0.35);
}

.feedback.is-visible {
  display: block;
}

.feedback strong {
  color: var(--accent);
}

.question-card.is-correct .feedback strong {
  color: var(--good);
}

.question-card.is-wrong .feedback strong {
  color: var(--bad);
}

.form-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  background: linear-gradient(transparent, var(--paper) 30%);
  padding-top: 28px;
}

.submit-button {
  min-width: 190px;
  border-color: var(--ink);
  background: var(--accent-2);
  color: #fffdf7;
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 8px 8px 0 var(--accent);
  color: var(--ink);
  padding: 0;
}

.profile-dialog::backdrop {
  background: rgba(23, 22, 19, 0.34);
}

.profile-dialog form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.profile-dialog h3 {
  font-family: "Avenir Next Condensed", "Gill Sans", sans-serif;
  font-size: 30px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.profile-dialog p {
  color: var(--muted);
  line-height: 1.4;
}

.profile-dialog .submit-button {
  width: 100%;
}

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

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topic-list {
    max-height: 360px;
    overflow: auto;
  }

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

  .score-tile {
    text-align: left;
  }
}
