/* Dwindle — visual identity: warm paper / dusk, honeycomb tiles, drift-away. */

:root {
  --bg: #faf7f2;
  --ink: #2a2438;
  --muted: #6d6680; /* >=4.5:1 on --bg and --sheet */
  --tile: #ffffff;
  --tile-ink: #2a2438;
  --tile-shadow: rgba(42, 36, 56, 0.12);
  --thread: #ddd5e8;
  --accent: #7c5cff;       /* violet: live trace */
  --good: #3f9e6e;         /* moss: found word */
  --ember: #e08a3c;        /* ember: extras */
  --hint: #4d9dd6;
  --bad: #cf5f5f;
  --sheet: #ffffff;
  --chip: #efe9f7;
  --chip-done: #e3f2e9;
}
[data-theme="dusk"] {
  --bg: #16141f;
  --ink: #efeaff;
  --muted: #a49dbc; /* >=4.5:1 on --bg and --sheet */
  --tile: #262134;
  --tile-ink: #efeaff;
  --tile-shadow: rgba(0, 0, 0, 0.5);
  --thread: #383150;
  --accent: #9d85ff;
  --good: #55b585;
  --ember: #eb9c50;
  --hint: #64abe0;
  --bad: #de7676;
  --sheet: #221e30;
  --chip: #2d273f;
  --chip-done: #26382e;
}

[data-theme="honey"] {
  --bg: #fbf3df;
  --ink: #3d2f1a;
  --muted: #79643c;
  --tile: #fffaf0;
  --tile-ink: #3d2f1a;
  --tile-shadow: rgba(120, 90, 30, 0.18);
  --thread: #ecd9ac;
  --accent: #9a5503;
  --good: #3f7d43;
  --ember: #c25718;
  --hint: #2e7fa8;
  --bad: #c04545;
  --sheet: #fffaf0;
  --chip: #f3e5c3;
  --chip-done: #e2eecd;
}
[data-theme="meadow"] {
  --bg: #f2f7ee;
  --ink: #24331f;
  --muted: #5c7051;
  --tile: #ffffff;
  --tile-ink: #24331f;
  --tile-shadow: rgba(40, 70, 30, 0.15);
  --thread: #d5e3cb;
  --accent: #6b4fd8;
  --good: #3f8b4f;
  --ember: #c8761d;
  --hint: #3d7fb8;
  --bad: #bf4d4d;
  --sheet: #ffffff;
  --chip: #e3eedb;
  --chip-done: #d3e7cf;
}
[data-theme="tide"] {
  --bg: #0f1b26;
  --ink: #e6f1f7;
  --muted: #9db4c4;
  --tile: #1c2f3f;
  --tile-ink: #e6f1f7;
  --tile-shadow: rgba(0, 0, 0, 0.5);
  --thread: #2b4459;
  --accent: #1f7fa3;
  --good: #2e8f63;
  --ember: #c2701f;
  --hint: #2d85c0;
  --bad: #cf5f5f;
  --sheet: #17242f;
  --chip: #223648;
  --chip-done: #1e3b2f;
}
[data-theme="blossom"] {
  --bg: #fbf1f5;
  --ink: #3a2733;
  --muted: #77596b;
  --tile: #ffffff;
  --tile-ink: #3a2733;
  --tile-shadow: rgba(120, 50, 90, 0.14);
  --thread: #eed3e0;
  --accent: #b83d72;
  --good: #3f8b5f;
  --ember: #c8761d;
  --hint: #4d7fd6;
  --bad: #c04545;
  --sheet: #ffffff;
  --chip: #f4dfe9;
  --chip-done: #dcedd8;
}


* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- Header ---------- */
.top {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 4px;
}
.logo {
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}
.logo-hex {
  width: 18px; height: 18px;
  background: var(--accent);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  display: inline-block;
}
.puz-label { color: var(--muted); font-weight: 600; font-size: 1.05rem; }
.top-right { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px;
  border: none; border-radius: 12px;
  background: var(--chip);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- Board ---------- */
main {
  width: 100%;
  max-width: 520px;
  padding: 0 14px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.status {
  min-height: 1.5em;
  color: var(--muted);
  font-weight: 600;
  margin: 4px 0 2px;
  text-align: center;
}
.status-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  cursor: pointer;
}
.board-wrap { width: 100%; max-width: 440px; }
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 0.95;
  touch-action: none;
}
#webLayer, #traceLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
line.thread {
  stroke: var(--thread);
  stroke-width: 1.6;
  stroke-linecap: round;
  transition: opacity 0.5s;
}
line.thread.lit { stroke: var(--accent); stroke-width: 2.4; }
line.thread.flash { stroke: var(--hint); stroke-width: 2.6; }
line.thread.won { stroke: var(--good); }
line.thread.extra { stroke: var(--ember); }
line.thread.away { opacity: 0; }
line.tracer {
  stroke: var(--accent);
  stroke-width: 2.8;
  stroke-linecap: round;
  opacity: 0.85;
}

.tile {
  position: absolute;
  width: 15.5%;
  aspect-ratio: 1 / 1.12;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile);
  color: var(--tile-ink);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  font-size: clamp(18px, 5.4vw, 26px);
  font-weight: 800;
  cursor: pointer;
  filter: drop-shadow(0 2px 3px var(--tile-shadow));
  transition: background 0.25s, color 0.25s;
}
.tile.on { background: var(--accent); color: #fff; }
.tile.won { background: var(--good); color: #fff; }
.tile.extra { background: var(--ember); color: #fff; }
.tile.deny { animation: wobble 0.34s; }
.tile.beacon::after {
  content: "";
  position: absolute;
  inset: -6%;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border: 0; background: transparent;
  box-shadow: 0 0 0 3px var(--hint) inset;
  animation: breathe 1.4s ease-in-out infinite;
}
.tile.flash { background: var(--hint); color: #fff; }
.tile.away {
  animation: drift 0.7s ease-in forwards;
  pointer-events: none;
}
.tile.gone { visibility: hidden; pointer-events: none; }

@keyframes drift {
  0%   { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -78%) rotate(9deg) scale(0.72); }
}
@keyframes wobble {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-54%, -50%); }
  75% { transform: translate(-46%, -50%); }
}
@keyframes breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* Weaving a fresh board: empty slots pulse as a loom, threads shimmer, then
   the new letters settle in on a staggered diagonal wave. */
.tile.loom {
  background: var(--chip);
  color: transparent;
  filter: none;
  animation: loomPulse 1.15s ease-in-out infinite;
}
@keyframes loomPulse {
  0%, 100% { opacity: 0.28; transform: translate(-50%, -50%) scale(0.9); }
  50%      { opacity: 0.85; transform: translate(-50%, -50%) scale(1.02); }
}
.board.weaving line.thread { animation: loomThread 1.15s ease-in-out infinite; }
@keyframes loomThread {
  0%, 100% { opacity: 0.12; }
  50%      { opacity: 0.5; }
}
.tile.settle { animation: settleIn 0.55s cubic-bezier(0.2, 0.85, 0.3, 1.25) both; }
@keyframes settleIn {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.35) rotate(-10deg); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .tile.loom { animation: none; opacity: 0.5; }
  .board.weaving line.thread { animation: none; opacity: 0.3; }
  .tile.settle { animation: none; }
}

/* ---------- Forming word ---------- */
.forming-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  margin-top: 2px;
}
.forming {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  min-width: 40px;
  text-align: center;
}
.forming.good { color: var(--good); }
.forming.extra { color: var(--ember); }
.forming.bad { color: var(--bad); letter-spacing: 0.04em; font-size: 1.05rem; }
.forming.note { color: var(--muted); letter-spacing: 0.04em; font-size: 1.05rem; }
.mini-btn {
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: var(--chip);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}
.mini-btn.ok { background: var(--accent); color: #fff; }

/* ---------- Ledger ---------- */
.ledger {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
  max-width: 440px;
  transition: opacity 0.3s;
}
.ledger.dim { opacity: 0; }
.chip {
  border: none;
  border-radius: 10px;
  background: var(--chip);
  color: var(--ink);
  padding: 6px 10px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chip .len {
  background: var(--bg);
  border-radius: 6px;
  padding: 0 5px;
  font-size: 0.8rem;
  color: var(--muted);
}
.chip.done {
  background: var(--chip-done);
  color: var(--good);
  letter-spacing: 0.06em;
  cursor: default;
}
.chip.hinted { box-shadow: 0 0 0 2px var(--hint) inset; }
.chip.pop { animation: chipPop 0.5s; }
@keyframes chipPop { 30% { transform: scale(1.18); } }

/* ---------- Under-board ---------- */
.under {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-weight: 700;
}
.extras-pill { color: var(--ember); }
.penalty-float {
  position: fixed;
  color: var(--bad);
  font-weight: 800;
  animation: floatUp 1.1s ease-out forwards;
  pointer-events: none;
  z-index: 60;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-34px); }
}

/* ---------- Popover ---------- */
.popover {
  position: fixed;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  background: var(--sheet);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  width: min(320px, 88vw);
}
.popover p { font-weight: 700; text-align: center; margin-bottom: 4px; }
.popover button {
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-weight: 700;
  background: var(--chip);
  color: var(--ink);
  cursor: pointer;
}
.popover button.ghost { background: transparent; color: var(--muted); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 30, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.overlay[hidden], .popover[hidden], .toast[hidden] { display: none; }
@media (min-width: 480px) { .overlay { align-items: center; } }
.sheet {
  position: relative;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 24px 20px;
}
@media (min-width: 480px) { .sheet { border-radius: 20px; } }
.sheet h2 { margin-bottom: 12px; }
.close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--chip);
  color: var(--ink);
  cursor: pointer;
}
.done-time { font-size: 2.4rem; font-weight: 800; text-align: center; margin: 6px 0; }
.badges { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.badge {
  background: var(--chip);
  border-radius: 999px;
  padding: 5px 12px;
  font-weight: 700;
  font-size: 0.88rem;
}
.badge.gold { color: var(--ember); }
.badge.streak { color: var(--accent); }
.done-actions { display: flex; gap: 8px; justify-content: center; }
.done-actions button {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-weight: 700;
  background: var(--chip);
  color: var(--ink);
  cursor: pointer;
}
.done-actions button.primary { background: var(--accent); color: #fff; }
.countdown { text-align: center; color: var(--muted); margin-top: 14px; font-weight: 600; }

/* Finish time vs. the global average (under the big time on the done sheet). */
.done-compare { text-align: center; font-weight: 700; margin-top: -6px; margin-bottom: 4px; min-height: 1.2em; color: var(--muted); }
.done-compare.fast { color: var(--good); }
.done-compare.slow { color: var(--ember); }
.done-compare:empty { margin: 0; min-height: 0; }

/* ---------- Leaderboard ---------- */
.leaderboard { margin: 2px 0 16px; text-align: left; }
.lb-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.lb-head h3 { font-size: 1rem; }
.lb-count { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.lb-list { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.lb-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; background: var(--chip); }
.lb-row.me { box-shadow: inset 0 0 0 2px var(--accent); }
.lb-row.me .lb-rank, .lb-row.me .lb-name { color: var(--accent); }
.lb-rank { min-width: 1.7em; text-align: right; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-star { color: var(--ember); }
.lb-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.lb-you { color: var(--muted); font-weight: 600; margin-top: 8px; text-align: center; }
.lb-name-edit { display: flex; gap: 6px; margin-top: 12px; }
.lb-name-edit input {
  flex: 1; min-width: 0;
  border: 1px solid var(--thread); background: var(--bg); color: var(--ink);
  border-radius: 8px; padding: 9px 11px; font: inherit;
}
.lb-name-edit button {
  border: none; background: var(--accent); color: #fff; border-radius: 8px;
  padding: 9px 15px; font-weight: 700; cursor: pointer;
}

.defs { display: flex; flex-direction: column; gap: 12px; }
.defs .entry b { letter-spacing: 0.06em; }
.defs .entry.extra b { color: var(--ember); }
.defs .entry p { color: var(--muted); font-size: 0.95rem; margin-top: 2px; }
.defs .entry p.ex { font-style: italic; }
.defs .entry p.tf { font-size: 0.82rem; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.defs .entry p.tf.fast { color: var(--good); }
.defs .entry p.tf.slow { color: var(--ember); }

.help-body p { margin-bottom: 10px; line-height: 1.45; }

.archive { display: flex; flex-direction: column; gap: 6px; }
.archive button {
  display: flex;
  justify-content: space-between;
  border: none;
  background: var(--chip);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.archive .st { color: var(--muted); font-weight: 600; }
.archive .st.done { color: var(--good); }

.settings { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.settings button {
  border: none;
  background: var(--chip);
  border-radius: 10px;
  padding: 12px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.settings button.danger { color: var(--bad); }
.fineprint { color: var(--muted); font-size: 0.8rem; line-height: 1.5; }
.theme-pick { background: var(--chip); border-radius: 10px; padding: 10px 12px; }
.theme-label { font-weight: 700; display: block; margin-bottom: 8px; }
.theme-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  position: relative;
  padding: 0;
}
.swatch.active { border-color: var(--ink); transform: scale(1.18); }
.swatch::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--sw-accent);
}
.defs .lookup {
  border: none;
  background: var(--chip);
  color: var(--accent);
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  margin-top: 4px;
}
.defs .src-note { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
/* Language: pill row in settings, big buttons in the first-run picker. */
.lang-pick { background: var(--chip); border-radius: 10px; padding: 10px 12px; }
.lang-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lang-row button {
  border: 2px solid transparent;
  background: var(--sheet);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.lang-row button.active { border-color: var(--accent); color: var(--accent); }
.lang-sheet { max-width: 340px; text-align: center; }
.lang-choices { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.lang-choices button {
  border: 2px solid transparent;
  background: var(--chip);
  border-radius: 12px;
  padding: 14px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  cursor: pointer;
}
.lang-choices button.active { border-color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sheet);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
  z-index: 70;
  animation: floatUp 0.001s; /* replaced inline */
}

/* Confetti-free celebration: gentle rise of hex sparks */
.spark {
  position: fixed;
  width: 10px; height: 10px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  z-index: 45;
  animation: sparkRise 1.6s ease-out forwards;
  pointer-events: none;
}
@keyframes sparkRise {
  0% { opacity: 0; transform: translateY(10px) rotate(0deg); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-90px) rotate(140deg); }
}
