:root {
  --bg: #fbf7f0;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e6dfd3;
  --accent: #e4572e;
  --good: #2a9d8f;
  --bad: #d1495b;
  --cell: #f1ebe1;
  --radius: 14px;
  font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --panel: #1e2128;
    --ink: #eef0f4;
    --muted: #9aa1ad;
    --line: #2d313a;
    --cell: #2a2e37;
  }
  .cloud text { filter: brightness(1.35); }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  min-height: 100vh;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
}
button.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
  font-weight: 700;
}
.link-btn {
  border: none;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 4px 6px;
}
[hidden] { display: none !important; }

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px 6px;
}
.brand { text-align: center; }
.brand h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0.04em;
  font-weight: 700;
}
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
}

.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.notice a { color: var(--accent); }

/* Cloud */
.cloud-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 8px;
}
.cloud {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10; /* fixed box, so re-packing never shifts the page */
  max-height: 46vh;
  overflow: visible;
}
.cloud text {
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
}
.cloud-letter { transform-origin: 0 0; }
.cloud.animate text { transition: font-size 0.5s ease, opacity 0.5s ease; }
.cloud.animate .cloud-letter { transition: transform 0.6s ease; }
.cloud-letter.spent text { opacity: 0; }
.cloud-letter.spent { visibility: hidden; }
.cloud.animate .cloud-letter.spent { transition: transform 0.6s ease, visibility 0s 0.5s; }
.cloud-letter.pop text { animation: pop 0.5s ease; }
@keyframes pop {
  0% { opacity: 1; }
  40% { opacity: 0.25; }
  100% { opacity: 1; }
}

/* Theme */
.theme-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 6px;
}
.theme-label {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.theme { font-size: 20px; font-weight: 700; }

/* Word slots */
.slots {
  list-style: none;
  padding: 0;
  margin: 10px auto 18px;
  max-width: 380px;
  display: grid;
  gap: 8px;
}
.slot { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.slot-num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  border: 2px solid var(--line);
}
.slot.found .slot-num { border-color: var(--good); color: var(--good); }
.slot-word { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.slot.empty .slot-word { height: 34px; border-radius: 7px; border: 2px dashed var(--line); }
.cell {
  width: 30px;
  height: 34px;
  border-radius: 7px;
  background: var(--cell);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
}
.gap { width: 10px; display: grid; place-items: center; color: var(--muted); }
.slot.found .cell { background: var(--good); color: #fff; }
.slot.new .cell { animation: flip 0.4s ease; }
.slot.missed .cell { color: var(--bad); }
@keyframes flip {
  from { transform: rotateX(90deg); }
  to { transform: none; }
}
@media (max-width: 420px) {
  .cell { width: 24px; height: 30px; font-size: 15px; }
  .slot.empty .slot-word { height: 30px; }
}

/* Guessing */
.guess-form { display: flex; gap: 8px; }
.guess-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  outline: none;
}
.guess-form input:focus { border-color: var(--ink); }
.shake { animation: shake 0.35s ease; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}
.message { min-height: 1.4em; text-align: center; margin: 10px 0; font-weight: 500; }
.message[data-tone='good'] { color: var(--good); }
.message[data-tone='bad'] { color: var(--bad); }
.message[data-tone='info'] { color: var(--muted); }

.tried h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 0 6px;
  text-align: center;
}
.tried ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.tried li {
  font-size: 14px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--cell);
  color: var(--muted);
  text-decoration: line-through;
}
.footer-actions { text-align: center; margin-top: 18px; }

/* Result */
.result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  margin-top: 8px;
}
.result h2 { margin: 0 0 4px; }
.result p { margin: 0 0 14px; color: var(--muted); }
.stats { display: flex; justify-content: center; gap: 36px; margin-bottom: 16px; }
.stats div { display: grid; }
.stats strong { font-size: 28px; }
.stats span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Archive */
.archive-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.archive-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.archive-list a {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: 'num when status' 'num what status';
  column-gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}
.archive-list a.current { border-color: var(--ink); }
.archive-list .num { grid-area: num; font-weight: 700; font-size: 18px; }
.archive-list .when { grid-area: when; }
.archive-list .what { grid-area: what; font-size: 13px; color: var(--muted); }
.archive-list .status { grid-area: status; font-size: 13px; color: var(--muted); }
.archive-list .status.done { color: var(--good); }
.archive-list .status.missed { color: var(--bad); }
.archive-list .status.progress { color: var(--accent); }

/* Dialog */
dialog {
  border: none;
  border-radius: var(--radius);
  max-width: 420px;
  width: calc(100% - 32px);
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin-top: 0; }
dialog p { line-height: 1.45; }
dialog form { text-align: right; margin-top: 12px; }

.broken { padding: 24px 16px; }

/* Editor page */
.editor label { display: grid; gap: 4px; margin-bottom: 12px; font-weight: 500; }
.editor input {
  font: inherit;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}
.editor .words { display: grid; gap: 6px; }
.editor pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
}
.editor .problems { color: var(--bad); }
.editor .warnings { color: var(--accent); }
.editor .counts { color: var(--muted); font-size: 14px; }
