/* Stray Lilac Llama — styles */

:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --ink: #1E2533;
  --muted: #646B7A;
  --line: #D5D9E0;
  --line-strong: #1E2533;
  --key: #E3E6EC;
  --good: #2D7A4F;
  --bad: #B3261E;

  /* rarity scale: common → very rare */
  --t0: #C8CDD6; --t0-ink: #1E2533;
  --t1: #E9C440; --t1-ink: #1E2533;
  --t2: #E8863A; --t2-ink: #1E2533;
  --t3: #6E48C0; --t3-ink: #FFFFFF;

  --radius-tile: 6px;
  --radius-btn: 10px;
  --col: 440px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171E;
    --surface: #1C2029;
    --ink: #E9ECF2;
    --muted: #9BA2B2;
    --line: #353B48;
    --line-strong: #E9ECF2;
    --key: #2A303C;
    --good: #6CC594;
    --bad: #FF8A80;
    --t0: #4A5162; --t0-ink: #E9ECF2;
    --t1: #D9B532; --t1-ink: #14171E;
    --t2: #E07A2E; --t2-ink: #14171E;
    --t3: #8C67E0; --t3-ink: #FFFFFF;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.45;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--t3); outline-offset: 2px; }

/* ---------- header & logo ---------- */
.top {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  max-width: var(--col);
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 40px; height: 40px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-weight: 700;
  font-size: 1.05rem;
  display: grid; place-items: center;
}
/* logo: the word with the rarity scale as its underline, shrinking from common to very rare */
.logo {
  margin: 0;
  justify-self: center;
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.logo-word {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 0.9;
  white-space: nowrap;
}
.logo-scale { display: flex; gap: 3px; width: 100%; }   /* underline spans the whole name */
.logo-scale i { display: block; height: 4px; border-radius: 2px; }
.logo-scale .s0 { flex: 38; background: var(--t0); }
.logo-scale .s1 { flex: 27; background: var(--t1); }
.logo-scale .s2 { flex: 16; background: var(--t2); }
.logo-scale .s3 { flex: 8; background: var(--t3); }

/* ---------- main column ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: var(--col);
  margin: 0 auto;
  padding: 14px 16px 20px;
}
.puzzle-line { margin: 0 0 4px; color: var(--muted); font-size: 0.92rem; text-align: center; }
.goal { margin: 0 0 14px; text-align: center; font-size: 1.05rem; font-weight: 600; }

/* ---------- slots ---------- */
.slot {
  width: 100%;
  margin: 0 0 12px;
  padding: 10px 12px 8px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  display: block;
}
.slot.active { border-color: var(--line-strong); }
.slot-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.slot-kind { font-size: 0.8rem; color: var(--muted); }
.slot-rule { font-weight: 650; font-size: 0.98rem; }
.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.box {
  aspect-ratio: 1;
  max-height: 54px;
  display: grid; place-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius-tile);
  font-size: 1.6rem;
  font-weight: 800;
  text-transform: uppercase;
}
.box.filled { border-color: var(--muted); }
.slot.active .box.cursor { border-color: var(--line-strong); border-style: dashed; }
.slot { padding-bottom: 12px; }
.slot-status { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
.slot-status.bad { color: var(--bad); }
.slot.invalid .box.filled { border-color: var(--bad); }
.slot.valid .box.filled { border-color: var(--good); }

/* ---------- buttons ---------- */
.btn {
  padding: 12px 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-btn);
  background: transparent;
  font-weight: 700;
}
.btn-wide { width: 100%; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- result ---------- */
.result-rows { display: grid; gap: 10px; margin: 6px 0 16px; }
#result { padding-top: 12px; }
.r-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.r-word { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.r-word span {
  aspect-ratio: 1;
  max-height: 46px;
  display: grid; place-items: center;
  border-radius: var(--radius-tile);
  font-weight: 800;
  font-size: 1.3rem;
}
.t0 { background: var(--t0); color: var(--t0-ink); }
.t1 { background: var(--t1); color: var(--t1-ink); }
.t2 { background: var(--t2); color: var(--t2-ink); }
.t3 { background: var(--t3); color: var(--t3-ink); }
.r-meta { text-align: right; min-width: 82px; }
.r-score { font-size: 1.35rem; font-weight: 800; display: block; line-height: 1.1; }
.r-tier { font-size: 0.78rem; color: var(--muted); display: flex; gap: 5px; justify-content: flex-end; align-items: center; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 6px; height: 6px; border-radius: 50%; border: 1.5px solid var(--muted); }
.pips i.on { background: var(--ink); border-color: var(--ink); }

.score-block { text-align: center; margin: 4px 0 10px; }
.big-total { margin: 0; font-size: 3rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.big-total .unit { font-size: 1rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
#r-beat { margin: 6px 0 0; font-size: 1.05rem; }
.extras { margin: 6px 0 0; font-size: 0.86rem; color: var(--muted); }
.score-block { margin-bottom: 18px; }
.note { color: var(--muted); font-size: 0.86rem; text-align: center; margin: 0 0 10px; }
.countdown { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 0; font-variant-numeric: tabular-nums; }

/* collapsible sections */
details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  list-style: none;
  width: fit-content;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: " ▾"; }
details[open] summary::after { content: " ▴"; }
.r-details { margin-top: 14px; }
.r-details summary { margin: 0 auto; }
.r-details[open] summary { margin-bottom: 10px; }
.breakdown { list-style: none; padding: 0; margin: 0 0 12px; border-top: 1px solid var(--line); }
.breakdown li { display: flex; justify-content: space-between; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.bd-word { font-weight: 700; }
.bd-right { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.bd-right b { color: var(--ink); min-width: 2.2em; text-align: right; }

/* ---------- yesterday (one line, details on request) ---------- */
.yesterday {
  padding: 10px 12px;
  margin: 8px 0 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.y-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.y-line p { margin: 0; font-weight: 650; font-size: 0.95rem; }
.close-btn { border: 0; background: transparent; font-size: 1.3rem; line-height: 1; color: var(--muted); padding: 2px 6px; }
.yesterday summary { margin-top: 4px; }
.yesterday[open] summary, .yesterday details[open] summary { margin-bottom: 10px; }
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 4px; }
.lists h3 { margin: 0 0 4px; font-size: 0.9rem; }
.lists ol { margin: 0; padding-left: 1.3em; font-size: 0.92rem; }
.lists li span { color: var(--muted); font-size: 0.82rem; }

/* ---------- banner, error, toast ---------- */
.banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin: 8px 0 14px;
  border: 2px solid var(--t2); border-radius: 12px; background: var(--surface);
}
.banner p { margin: 0; font-weight: 600; }
.error { color: var(--bad); text-align: center; font-weight: 600; }
.toast {
  position: fixed; left: 50%; top: 72px; transform: translate(-50%, -8px);
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-weight: 650; font-size: 0.92rem;
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- keyboard ---------- */
.keyboard {
  position: sticky;          /* always reachable, even on short screens */
  bottom: 0;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 6px 6px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  user-select: none;
}
.kb-row { display: flex; gap: 5px; justify-content: center; margin-bottom: 6px; }
.key {
  flex: 1;
  height: 52px;
  max-width: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--key);
  font-weight: 700;
  font-size: 1rem;
  touch-action: manipulation;
}
.key.wide { max-width: 68px; flex: 1.5; font-size: 0.78rem; }
.key:active { filter: brightness(0.9); }

/* ---------- dialogs ---------- */
dialog {
  width: min(420px, calc(100% - 32px));
  border: 0;
  border-radius: 14px;
  padding: 20px 20px 16px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgb(10 12 18 / 0.55); }
dialog h2 { margin: 0 0 10px; font-size: 1.25rem; }
dialog p, dialog li { font-size: 0.95rem; }
dialog ul { padding-left: 1.2em; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 16px; font-size: 0.88rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chip { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 8px; margin: 6px 0 16px; text-align: center; }
.stats-grid div { display: flex; flex-direction: column-reverse; }
.stats-grid dt { font-size: 0.8rem; color: var(--muted); }
.stats-grid dd { margin: 0; font-size: 1.6rem; font-weight: 800; }
.backup-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 10px; }
.backup-btns .btn { padding: 10px 8px; font-size: 0.88rem; }
.backup-status { margin: 0 0 10px; min-height: 1.2em; font-size: 0.86rem; font-weight: 600; text-align: center; }
.backup-status:empty { display: none; }
.nudge { margin: -4px 0 12px; font-size: 0.86rem; font-weight: 600; text-align: center; color: var(--t3); }
@media (prefers-color-scheme: dark) { .nudge { filter: brightness(1.3); } }

@media (max-height: 760px) {
  .goal { display: none; }
  .logo-word { font-size: 1.3rem; }
  .boxes { grid-template-columns: repeat(5, 40px); justify-content: start; }
  .box { font-size: 1.3rem; height: 40px; }
  .slot { padding: 8px 10px 8px; margin-bottom: 8px; }
  .slot-head { margin-bottom: 6px; }
  .slot-status { margin-top: 3px; font-size: 0.8rem; }
  .key { height: 44px; }
  .kb-row { margin-bottom: 5px; }
  main { padding-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
