@font-face {
  font-family: "Noto Sans Buginese";
  src: url("../fonts/NotoSansBuginese-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+1A00-1A1F, U+200C, U+200D;
}

:root {
  --ink: #1c140c;
  --muted: #5c4a38;
  --paper: #f4ead6;
  --paper-deep: #ebe0c8;
  --rule: #d4c4a8;
  --accent: #7a3e1d;
  --accent-soft: rgba(122, 62, 29, 0.16);
  --good: #2f6b3a;
  --good-soft: rgba(47, 107, 58, 0.16);
  --warn: #8a4b2a;
  --topbar: #2a1c12;
  --topbar-text: #f4ead6;
  --shadow: 0 10px 30px rgba(28, 20, 12, 0.18);
  --ui: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --serif: "Source Serif 4", Palatino, Georgia, serif;
  --lontara: "Noto Sans Buginese", "Noto Sans", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

[data-theme="night"] {
  --ink: #f3ead8;
  --muted: #cbbba3;
  --paper: #1a140e;
  --paper-deep: #241c14;
  --rule: #3d3226;
  --accent: #e0a06a;
  --accent-soft: rgba(224, 160, 106, 0.16);
  --good: #8fd49a;
  --good-soft: rgba(143, 212, 154, 0.16);
  --topbar: #100c08;
  --topbar-text: #f3ead8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
}
body {
  padding-top: calc(56px + var(--safe-t));
  padding-bottom: var(--safe-b);
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(56px + var(--safe-t));
  padding: var(--safe-t) 10px 0 calc(10px + var(--safe-l));
  padding-right: calc(10px + var(--safe-r));
  background: var(--topbar);
  color: var(--topbar-text);
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  color: var(--topbar-text);
  border-radius: 10px;
}
.topbar-title { flex: 1 1 auto; min-width: 0; }
.brand { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 15px; }
.brand-sub { margin: 0; font-size: 11px; opacity: 0.8; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.stats-pills { display: flex; gap: 6px; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(244, 234, 214, 0.28);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.lang-toggle {
  display: flex;
  height: 32px;
  border: 1px solid rgba(244, 234, 214, 0.28);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  min-width: 32px;
  color: var(--topbar-text);
  opacity: 0.7;
  font-size: 11px;
  font-weight: 600;
}
.lang-toggle button.is-active { background: rgba(244, 234, 214, 0.16); opacity: 1; }

.round-bar {
  position: sticky;
  top: calc(56px + var(--safe-t));
  z-index: 15;
  height: 8px;
  background: var(--paper-deep);
  border-bottom: 1px solid var(--rule);
}
.round-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

.stage {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.hero-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero h1 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
}
.hero-sub {
  margin: 0 0 16px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 16px;
}
.tabs button {
  flex: 1 1 0;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper-deep);
  font-size: 13px;
  font-weight: 600;
}
.tabs button.is-active {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}

.name-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--muted);
}
.name-row input {
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 15px;
}

.path {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 20px;
}
.unit {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--paper-deep);
}
.unit.is-locked { opacity: 0.55; cursor: default; }
.unit.is-open { box-shadow: inset 0 0 0 1px var(--accent); }
.unit-orb {
  flex: 0 0 52px;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
  border: 2px solid var(--accent);
}
.unit.is-done .unit-orb { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.unit strong { display: block; font-size: 15px; }
.unit span { display: block; font-size: 12px; color: var(--muted); }

.contrib-card {
  margin: 8px 0 16px;
  padding: 14px;
  border: 1px solid var(--accent);
  border-radius: 16px;
  background: var(--accent-soft);
}
.contrib-card h2 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 1.2rem;
}
.contrib-badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-size: 11px;
  font-weight: 600;
}
.contrib-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sheet-note { font-size: 13px; color: var(--muted); line-height: 1.4; margin: 8px 0 0; }

.text-btn, .choice, .listen, .primary {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: var(--paper-deep);
}
.primary, .text-btn.primary {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
  font-weight: 600;
}

.card-prompt {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}
.glyph {
  font-family: var(--lontara);
  font-size: 3.2rem;
  line-height: 1.4;
  text-align: center;
  margin: 8px 0 16px;
}
.latin-prompt {
  text-align: center;
  font-size: 2rem;
  font-weight: 600;
  margin: 8px 0 16px;
}
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.choices.stack { grid-template-columns: 1fr; }
.choice { text-align: center; font-size: 16px; }
.choice .lg { font-family: var(--lontara); font-size: 1.8rem; display: block; }
.choice.is-right { background: var(--good-soft); border-color: var(--good); }
.choice.is-wrong { background: rgba(138, 75, 42, 0.14); border-color: var(--warn); }
.choice.is-unclear { grid-column: 1 / -1; color: var(--muted); }
.listen {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px;
}

.build-target {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 12px;
}
.build-preview {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 14px;
  border: 1px dashed var(--rule);
  border-radius: 12px;
  font-family: var(--lontara);
  font-size: 2.2rem;
}
.build-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 0 0 10px;
}
.build-row button {
  min-width: 56px;
  min-height: 48px;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper-deep);
}
.build-row button.is-on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.scan-frame {
  position: relative;
  width: 100%;
  height: 180px;
  margin: 0 0 14px;
  border-radius: 14px;
  overflow: hidden;
  background: #1a140e;
  border: 1px solid var(--rule);
}
.scan-frame canvas { width: 100%; height: 100%; display: block; }

.feedback {
  margin: 14px 0 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--good-soft);
  font-weight: 600;
}
.feedback.is-careful { background: var(--accent-soft); }
.feedback.is-miss { background: rgba(138, 75, 42, 0.14); }
.continue-row { margin-top: 12px; }

.result-score {
  font-family: var(--serif);
  font-size: 2.4rem;
  margin: 8px 0;
}

@media (max-width: 480px) {
  .hero h1 { font-size: 1.45rem; }
  .glyph { font-size: 2.6rem; }
  .topbar .brand { font-size: 14px; }
}

.marks-strip {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin: 0 0 16px;
  padding: 8px 6px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
}
.marks-strip span {
  flex: 1 1 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.marks-strip .lg {
  display: block;
  font-family: var(--lontara);
  font-size: 1.35rem;
  color: var(--ink);
  line-height: 1.3;
}
.honest, .muted { font-size: 13px; color: var(--muted); line-height: 1.45; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(90vw, 420px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--topbar);
  color: var(--topbar-text);
  font-size: 13px;
  box-shadow: var(--shadow);
}
.contrib-card .who { margin: 0; font-weight: 600; }
.contrib-card .count { margin: 2px 0 0; font-size: 14px; }
.unit-orb .check { font-size: 20px; }

.build-row small { display: block; font-size: 11px; color: var(--muted); }
.choice[disabled], .build-row button[disabled] { cursor: default; }

a.text-btn { display: inline-flex; align-items: center; text-decoration: none; color: inherit; }

/* First-visit welcome */
.welcome-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(28, 20, 12, 0.55);
}
.welcome-card {
  position: relative;
  max-width: 520px;
  width: 100%;
  padding: 22px 20px 18px;
  border-radius: 16px;
  border: 1px solid var(--rule, #d4c4a8);
  background: var(--paper, #f4ead6);
  color: var(--ink, #1c140c);
  box-shadow: 0 16px 40px rgba(28, 20, 12, 0.28);
}
.welcome-card h2 {
  margin: 0 22px 12px 0;
  font-family: var(--serif, Georgia, serif);
  font-size: 1.35rem;
}
.welcome-card ul {
  margin: 0 0 16px;
  padding: 0 0 0 1.15em;
}
.welcome-card li {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.45;
}
.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.welcome-primary, .welcome-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.welcome-primary {
  background: var(--accent, #7a3e1d);
  color: var(--paper, #f4ead6);
}
.welcome-link {
  border: 1px solid var(--rule, #d4c4a8);
  color: var(--ink, #1c140c);
  background: var(--paper-deep, #ebe0c8);
}
.welcome-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
html[data-await-lang] body { visibility: hidden; }
