:root {
  --paper: #fbf4e4;
  --card: #fffdf7;
  --ink: #3b2f2a;
  --ink-soft: #7a6a5f;
  --red: #c43b3b;
  --red-dark: #9e2b2b;
  --sky: #9cc7e4;
  --sky-soft: #e4f0f8;
  --rose: #f2c4c4;
  --leaf: #a8c686;
  --gold: #e9c46a;
  --shadow: 0 6px 18px rgba(59, 47, 42, .12);
  --radius: 18px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Lora", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(156, 199, 228, .35), transparent 32%),
    radial-gradient(circle at 92% 18%, rgba(242, 196, 196, .45), transparent 30%),
    radial-gradient(circle at 80% 92%, rgba(168, 198, 134, .35), transparent 34%),
    var(--paper);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

h2, h3 { margin: 0 0 .6em; }
h2 { font-size: 1.6rem; text-align: center; }
h3 { font-size: 1.1rem; }
h3 small { font-weight: 400; color: var(--ink-soft); font-size: .85rem; }

.cover { text-align: center; padding: 18px 16px 4px; }
.collection {
  margin: 0;
  font-size: .75rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.cover-frame {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-top: 8px;
  padding: 10px 22px 10px 12px;
  background: var(--card);
  border: 3px double var(--red);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.alica { width: 74px; height: 74px; flex: none; }
h1 {
  margin: 0;
  font-family: "Playball", "Brush Script MT", cursive;
  font-weight: 400;
  font-size: clamp(2.1rem, 7vw, 3.2rem);
  line-height: 1;
  color: var(--red);
  text-align: left;
}
h1 span { display: block; font-size: .62em; color: #4a78ad; }
.tome { margin: 10px 0 0; font-style: italic; color: var(--ink-soft); min-height: 1.4em; }

main { max-width: 860px; margin: 0 auto; padding: 12px 14px 24px; }
.page { animation: pageIn .35s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(59, 47, 42, .08);
}

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 2px solid var(--sky);
  background: var(--sky-soft);
  font: inherit;
  font-size: .95rem;
  color: var(--ink);
  cursor: pointer;
}
.chip[aria-pressed="false"] { background: transparent; border-style: dashed; color: var(--ink-soft); }
.chip.player { border-color: var(--rose); background: #fdecec; cursor: default; }
.chip .remove {
  border: 0;
  background: none;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--red);
  cursor: pointer;
  padding: 0 2px;
}
.chip.fun { border-color: var(--gold); background: #fdf3d6; }

.inline-form { display: flex; gap: 8px; margin-bottom: 10px; }
input, select {
  font: inherit;
  padding: 9px 12px;
  border-radius: 12px;
  border: 2px solid #e6dccb;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
.inline-form input { flex: 1; }
input:focus, select:focus { outline: none; border-color: var(--sky); }

.options label { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; }
.options label.check { justify-content: flex-start; cursor: pointer; }
.options input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--red); }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  border: 0;
  background: #4a78ad;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn:hover { filter: brightness(1.06); }
.btn.small { padding: 8px 14px; font-size: .9rem; }
.btn.big { display: block; margin: 10px auto; padding: 14px 30px; font-size: 1.15rem; background: var(--red); }
.btn.ghost { background: transparent; color: #4a78ad; box-shadow: inset 0 0 0 2px #4a78ad; }
.btn.go { background: #5d9b4e; }
.btn.stop { background: var(--red); font-size: 1.1rem; letter-spacing: .05em; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 14px 0; }
.actions .btn.big { margin: 0; }

.error { color: var(--red); text-align: center; min-height: 1.2em; margin: 4px 0; }

.letter-tile {
  width: min(56vw, 230px);
  aspect-ratio: 1;
  margin: 18px auto 8px;
  display: grid;
  place-items: center;
  font-family: "Playball", cursive;
  font-size: min(36vw, 150px);
  color: var(--red);
  background: var(--card);
  border-radius: 28px;
  border: 4px solid var(--gold);
  box-shadow: var(--shadow), inset 0 0 0 8px #fdf3d6;
  user-select: none;
}
.letter-tile.spinning { animation: wobble .12s linear infinite; color: #4a78ad; }
.letter-tile.landed { animation: land .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes wobble { 50% { transform: rotate(-3deg) scale(.97); } }
@keyframes land { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }

.used { text-align: center; color: var(--ink-soft); letter-spacing: .08em; }
.challenge {
  max-width: 460px;
  margin: 12px auto;
  padding: 14px 18px;
  background: #fdf3d6;
  border-left: 6px solid var(--gold);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transform: rotate(-1deg);
}
.challenge strong { font-family: "Playball", cursive; font-weight: 400; font-size: 1.3rem; color: var(--red-dark); }
.challenge p { margin: 6px 0 0; }
.challenge-mini { text-align: center; font-style: italic; color: var(--ink-soft); }

.clock-wrap { position: relative; width: min(78vw, 300px); aspect-ratio: 1; margin: 10px auto; }
.clock { width: 100%; height: 100%; transform: rotate(-90deg); }
.clock-bg { fill: var(--card); stroke: #efe5d3; stroke-width: 14; }
.clock-ring {
  fill: none;
  stroke: var(--leaf);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 552.92;
  transition: stroke-dashoffset .25s linear, stroke .3s;
}
.clock-face { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.play-letter { font-family: "Playball", cursive; font-size: min(24vw, 104px); line-height: .9; color: var(--red); }
.clock-text { font-size: min(9vw, 2.4rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.hurry .clock-ring { stroke: var(--red); }
.hurry .clock-text { color: var(--red); animation: pulse 1s ease infinite; }
.paused .clock-text { opacity: .45; }
@keyframes pulse { 50% { transform: scale(1.12); } }

.cat-columns { columns: 2 180px; margin: 0; padding-left: 1.4em; }
.cat-columns li { margin: 4px 0; break-inside: avoid; }

.legend { text-align: center; color: var(--ink-soft); line-height: 2; }
.table-wrap { overflow-x: auto; margin: 0 -4px 12px; padding: 4px; }
.grid { border-collapse: separate; border-spacing: 0; min-width: 100%; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.grid th, .grid td { padding: 8px 10px; text-align: center; border-bottom: 1px solid #f0e7d8; white-space: nowrap; }
.grid thead th { background: var(--sky-soft); font-size: .85rem; font-weight: 600; }
.grid th:first-child, .grid td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); font-weight: 600; z-index: 1; }
.grid thead th:first-child { background: var(--sky-soft); }
.grid tr:last-child td { border-bottom: 0; }
.grid .total { font-weight: 700; color: var(--red); font-size: 1.1rem; }
.grid .row-tools { font-size: .75rem; padding: 2px 8px; margin-left: 6px; }

.stamp {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px dashed #d8ccb8;
  background: transparent;
  font: inherit;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
  vertical-align: middle;
}
.legend .stamp { width: 30px; height: 30px; font-size: .8rem; cursor: default; margin: 0 4px 0 10px; }
.stamp.s10 { border: 2px solid #5d9b4e; color: #3f7a32; background: #e6f2dd; transform: rotate(-6deg); }
.stamp.s5 { border: 2px solid #d9a521; color: #9a7310; background: #fbf0cf; transform: rotate(4deg); }
.stamp.s0 { border: 2px solid var(--red); color: var(--red); background: #fbe3e3; transform: rotate(-3deg); }

.bonus { display: inline-flex; align-items: center; gap: 4px; }
.bonus button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--gold); background: #fdf3d6; font: inherit; font-weight: 700; cursor: pointer; color: var(--ink); }
.bonus span { min-width: 2.2em; font-weight: 700; }

.ranking { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.ranking li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-size: 1.1rem;
}
.ranking .medal { font-size: 1.5rem; width: 1.6em; text-align: center; }
.ranking .name { flex: 1; font-weight: 600; }
.ranking .pts { font-weight: 700; color: var(--red); }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 26px 0 10px; }
.step { width: 30%; max-width: 150px; text-align: center; }
.step .who { font-weight: 700; margin-bottom: 6px; overflow-wrap: anywhere; }
.step .block {
  display: grid;
  place-items: center;
  border-radius: 14px 14px 0 0;
  color: #fff;
  font-family: "Playball", cursive;
  font-size: 2rem;
  box-shadow: var(--shadow);
}
.step.p1 .block { height: 150px; background: var(--gold); }
.step.p2 .block { height: 105px; background: var(--sky); }
.step.p3 .block { height: 75px; background: var(--rose); }
.final-note { text-align: center; font-style: italic; color: var(--ink-soft); }

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 247, .92);
  backdrop-filter: blur(6px);
  border-top: 1px solid #eadfcd;
  z-index: 5;
}
.tool { font: inherit; font-size: .9rem; padding: 8px 12px; border: 0; border-radius: 999px; background: transparent; color: var(--ink); cursor: pointer; }
.tool:hover { background: var(--sky-soft); }
.tool:disabled { opacity: .35; cursor: default; background: none; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(251, 244, 228, .9);
  z-index: 10;
  animation: pageIn .2s ease;
}
.overlay p {
  margin: 0;
  font-family: "Playball", cursive;
  font-size: clamp(3rem, 14vw, 7rem);
  color: var(--red);
  text-align: center;
  animation: land .6s cubic-bezier(.3, 1.6, .5, 1);
}

.rules { border: 0; border-radius: var(--radius); padding: 22px 24px; max-width: 520px; color: var(--ink); background: var(--card); box-shadow: var(--shadow); font-family: inherit; }
.rules::backdrop { background: rgba(59, 47, 42, .35); }
.rules li { margin: 8px 0; line-height: 1.45; }
.rules form { text-align: center; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

@media (max-width: 520px) {
  .cover-frame { padding: 8px 16px 8px 8px; gap: 10px; }
  .alica { width: 58px; height: 58px; }
  .tool { padding: 8px; font-size: .82rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.skyline { display: block; width: min(340px, 86%); height: auto; margin: 10px auto 0; }
