:root {
  --bg: #f7f1df;
  --bg-elevated: #fffdf6;
  --ink: #1c1412;
  --muted: #6e5a48;
  --accent: #c1001f;
  --accent-hover: #9e0019;
  --senyera-gold: #fccc12;
  --senyera-red: #c1001f;
  --highlight: #fccc12;
  --danger: #9f1239;
  --ok: #15803d;
  --border: #e5d4a0;
  --track: #efe2b4;
  --tab-rail: #f0e6c4;
  --surface-solid: #ffffff;
  --radius: 10px;
  --font-ui: "Figtree", "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --shadow-soft: 0 1px 4px rgba(90, 40, 20, 0.1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  background:
    radial-gradient(ellipse 90% 50% at 50% -10%, rgba(252, 204, 18, 0.35), transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a {
  color: var(--accent);
}

[hidden] {
  display: none !important;
}

.brand__link {
  color: inherit;
  text-decoration: none;
}

a.btn {
  text-decoration: none;
}

a.icon-btn {
  text-decoration: none;
  color: inherit;
}

a.level-tile,
a.list-row,
a.tab-btn {
  text-decoration: none;
  color: inherit;
}

a.level-tile,
a.list-row {
  box-sizing: border-box;
}

a.tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ── Layout shells ───────────────────────────────────── */

.page {
  max-width: 40rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.page--flush-top {
  padding-top: 2rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stack-lg {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.study-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
}

.study-actions__end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.dialog {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 0;
  background: var(--bg-elevated);
  color: var(--ink);
  max-width: min(22rem, calc(100vw - 2rem));
  box-shadow: 0 12px 40px color-mix(in srgb, var(--ink) 18%, transparent);
}

.dialog::backdrop {
  background: color-mix(in srgb, var(--ink) 35%, transparent);
}

.dialog__panel {
  padding: 1.25rem 1.35rem 1.35rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.check-row input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

/* ── Brand ───────────────────────────────────────────── */

.topbar {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 1.5rem;
}

.topbar__side {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
}

.topbar__side--start {
  justify-content: flex-start;
}

.topbar__side--end {
  justify-content: flex-end;
  align-items: flex-start;
}

.topbar__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.topbar__actions .icon-btn {
  text-decoration: none;
  color: inherit;
}

.topbar__brand {
  text-align: center;
  min-width: 0;
}

.topbar__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1.5rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.topbar__back:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.topbar__back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn__svg {
  display: block;
}

.brand {
  text-align: center;
}

.brand__title {
  font-family: var(--font-display);
  font-size: clamp(2.25rem, 6vw, 3rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--senyera-red);
  margin: 0;
}

.topbar .brand__title {
  font-size: clamp(1.5rem, 4.5vw, 2rem);
}

.brand__tagline {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

/* ── Typography ──────────────────────────────────────── */

.heading-1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.heading-2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
}

/* Page titles / meta under the topbar — centered; list/card body stays LTR left. */
.page-intro {
  text-align: center;
}

.page-intro .text-muted + .text-muted {
  margin-top: 0.35rem;
}

.heading-3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.text-body {
  margin: 0;
  color: var(--ink);
}

.text-muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.text-small {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.rule-callout {
  margin: 0;
  padding: 0.9rem 1rem;
  background: color-mix(in srgb, var(--senyera-gold) 14%, var(--bg-elevated));
  border-left: 3px solid var(--senyera-gold);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

a.btn.btn--primary {
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: #fff;
}

.btn--secondary {
  background: var(--bg-elevated);
  color: var(--ink);
  border-color: var(--border);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

.btn--ghost:hover:not(:disabled) {
  color: var(--ink);
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.btn--block {
  width: 100%;
}

/* ── Forms ───────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.field__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
}

.input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.input--error {
  border-color: var(--danger);
}

.field__error {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
}

/* ── Tabs ────────────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 0;
  width: 100%;
  max-width: 22rem;
  margin-inline: auto;
  padding: 3px;
  background: var(--tab-rail);
  border-radius: var(--radius);
}

.tab-btn {
  flex: 1;
  padding: 0.5rem 0;
  border: none;
  background: none;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.tab-btn.is-active {
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

/* ── Progress ────────────────────────────────────────── */

.progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--senyera-gold), #e8b400);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── Level tile ──────────────────────────────────────── */

.level-grid {
  display: grid;
  gap: 0.75rem;
}

.level-tile-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.level-tile-card.is-current,
.level-tile-card:hover {
  border-color: var(--senyera-red);
  box-shadow: inset 3px 0 0 var(--senyera-gold);
}

.level-tile-card .level-tile {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding-bottom: 0.55rem;
}

.level-tile-card .level-tile:hover,
.level-tile-card .level-tile.is-current {
  border-color: transparent;
  box-shadow: none;
}

.level-tile {
  display: block;
  width: 100%;
  text-align: left;
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.level-tile:hover,
.level-tile.is-current {
  border-color: var(--senyera-red);
  box-shadow: inset 3px 0 0 var(--senyera-gold);
}

.level-tile.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}

.level-tile.is-disabled:hover {
  border-color: var(--border);
  box-shadow: none;
}

.level-tile__code {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
}

.level-tile__meta {
  margin: 0.2rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.level-tile__goals {
  margin: 0;
  padding: 0 1.15rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--senyera-red);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.12em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.text-link:hover,
.text-link:focus-visible {
  color: var(--ink);
  outline: none;
}

.level-heading {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.level-heading .heading-2 {
  margin: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--senyera-red);
  border-color: var(--senyera-red);
  outline: none;
}

.icon-btn__svg {
  display: block;
}

.can-do-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.can-do {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
  color: var(--ink);
  font-size: 0.95rem;
}

.can-do__main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.can-do__label {
  font-weight: 600;
}

.can-do.is-done {
  color: var(--muted);
}

.can-do.is-done .can-do__label {
  font-weight: 600;
}

.goal-section {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.goal-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.goal-section__title {
  margin: 0;
  font-size: 1.05rem;
}

.progress--goals {
  margin: 0.55rem auto 0;
  max-width: 12rem;
}

/* ── List rows ───────────────────────────────────────── */

.list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  text-decoration: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.list-row:hover {
  border-color: color-mix(in srgb, var(--senyera-red) 45%, var(--border));
}

.list-row__title {
  margin: 0;
  font-weight: 600;
}

.list-row__sub {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.list-row--vocab.is-retired {
  opacity: 0.72;
}

.list-row--vocab.is-retired .list-row__title {
  color: var(--muted);
}

.btn--retire {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.vocab-main {
  min-width: 0;
  flex: 1;
}

.vocab-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.vocab-pronunciation,
.vocab-hint,
.vocab-forms {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.vocab-pronunciation {
  color: color-mix(in srgb, var(--senyera-gold) 75%, var(--ink));
  letter-spacing: 0.03em;
}

.vocab-forms {
  font-style: italic;
  text-align: right;
}

.vocab-tags {
  margin: 0.35rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-chip {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--tab-rail);
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge--done {
  background: color-mix(in srgb, var(--ok) 15%, white);
  color: var(--ok);
}

.badge--todo {
  background: var(--tab-rail);
  color: var(--muted);
}

/* ── Flashcard ───────────────────────────────────────── */

.flashcard {
  width: 100%;
  min-height: 12rem;
  padding: 1.5rem;
  border-radius: calc(var(--radius) + 4px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.flashcard:active {
  transform: scale(0.99);
}

.flashcard__lang {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.flashcard__word {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  font-weight: 600;
  margin: 0;
}

.flashcard__pronunciation {
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  color: color-mix(in srgb, var(--senyera-gold) 75%, var(--ink));
}

.flashcard__grammar {
  margin: 0.65rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

.flashcard__forms {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--muted);
}

.flashcard__hint {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.gram-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: flex-end;
}

.gram-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--tab-rail);
  color: var(--muted);
}

.gram-pill--m {
  background: color-mix(in srgb, #3a5bbf 12%, white);
  color: #3a5bbf;
}

.gram-pill--f {
  background: color-mix(in srgb, #bf3a72 12%, white);
  color: #bf3a72;
}

.gram-pill--pl {
  text-transform: none;
  font-weight: 600;
  font-size: 0.72rem;
}

/* ── Exercise options ────────────────────────────────── */

.option-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option {
  width: 100%;
  text-align: left;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.option:hover:not(:disabled) {
  border-color: var(--accent);
}

.option.is-selected {
  border-color: var(--senyera-red);
  background: color-mix(in srgb, var(--senyera-gold) 22%, white);
}

.option.is-correct {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 10%, white);
}

.option.is-wrong {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, white);
}

/* ── Examples table ──────────────────────────────────── */

.examples {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.examples th,
.examples td {
  padding: 0.55rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--track);
  vertical-align: top;
}

.examples th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

.examples__ca {
  font-weight: 600;
}

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

/* ── Seen dots ───────────────────────────────────────── */

.seen-dots {
  display: inline-flex;
  gap: 0.25rem;
}

.seen-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--border);
}

.seen-dot.is-filled {
  background: var(--senyera-gold);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--senyera-red) 35%, transparent);
}

/* ── Style-guide gallery chrome (page only) ──────────── */

.sg-page {
  max-width: 46rem;
  margin: 0 auto;
  padding: 2.75rem 1.25rem 5rem;
}

.sg-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.sg-toc a {
  font-size: 0.85rem;
  text-decoration: none;
}

.sg-section {
  margin-top: 2.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--track);
}

.sg-section__title {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1rem;
}

.sg-demo {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sg-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.75rem;
}

.sg-swatch {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.sg-swatch__chip {
  height: 3rem;
}

.sg-swatch__meta {
  padding: 0.45rem 0.55rem 0.55rem;
  font-size: 0.72rem;
  color: var(--muted);
}
