:root {
  --bg: #fff8f0;
  --card: #ffffff;
  --ink: #3b3355;
  --soft: #8a82a3;
  --line: #e6dcef;
  --accent: #ff8fab;
  --good: #6cc68a;
  --bad: #ef6f6c;
  --key: #efe7f7;
  --radius: 14px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  /* Fast repeated taps (a double-tapped key) would otherwise zoom the page on mobile.
     Pinch zoom still works. */
  touch-action: manipulation;
}
button { touch-action: manipulation; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}

/* Three columns keep the logo centered however many buttons sit on each side. */
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 2px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 14px;
  gap: 8px;
}

/* Row of seven little slimes showing progress */
#trail {
  display: flex;
  gap: 4px;
  justify-content: center;
}
#trail .mini {
  width: 40px;
  height: 36px;
  opacity: 0.45;
  transition: opacity 0.3s, transform 0.3s;
}
#trail .mini.current { opacity: 1; transform: translateY(-4px) scale(1.15); }
#trail .mini.done { opacity: 1; }
#trail .mini i {
  display: block;
  width: 14px;
  height: 6px;
  margin: 1px auto 0;
  border-radius: 3px;
}

#score {
  margin-top: 6px;
  font-size: 1.15rem;
  color: var(--soft);
}
#score b { font-size: 1.5rem; color: var(--ink); }

#stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#level-label {
  font-weight: 700;
  color: var(--soft);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#bubble {
  position: relative;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 14px 18px;
  width: 100%;
  text-align: center;
  box-shadow: 0 3px 0 var(--line);
}
#bubble::after {
  content: "";
  position: absolute;
  bottom: -11px;
  left: 50%;
  width: 18px;
  height: 18px;
  background: var(--card);
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}
#pos {
  font-style: italic;
  color: var(--soft);
  font-size: 0.95rem;
}
#definition {
  margin: 4px 0 0;
  font-size: 1.3rem;
  line-height: 1.4;
}

#big-slime { width: 120px; height: 100px; }
#big-slime.bounce svg { animation: bounce 1.6s ease-in-out infinite; transform-origin: bottom center; }
#big-slime.ouch svg { animation: ouch 0.5s ease; }
#big-slime.yay svg { animation: yay 0.7s ease; transform-origin: bottom center; }

@keyframes bounce {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.06, 0.94); }
}
@keyframes ouch {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
@keyframes yay {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-24px) scale(0.95, 1.08); }
  70% { transform: translateY(0) scale(1.1, 0.9); }
  100% { transform: translateY(0) scale(1); }
}

/* Letter blanks. Tile size shrinks for long words so they fit on one row. */
#tiles {
  display: flex;
  gap: 4px;
  justify-content: center;
  width: 100%;
  --size: min(52px, calc((100vw - 40px) / var(--len, 5) - 4px), calc((560px - 40px) / var(--len, 5) - 4px));
}
.tile {
  width: var(--size);
  height: calc(var(--size) * 1.15);
  border-bottom: 4px solid var(--soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--size) * 0.62);
  font-weight: 800;
  text-transform: uppercase;
  background: var(--card);
  border-radius: 8px 8px 4px 4px;
}
.tile.cursor { border-bottom-color: var(--accent); background: #fff0f4; }
.tile.ghost { color: #c3bad6; }
.tile.extra { background: transparent; border: 2px dashed var(--line); border-bottom: 4px dashed var(--soft); }
.tile.solved { background: var(--good); color: #fff; border-bottom-color: #4aa36a; }
.tile.close { background: #fdf0c4; border-bottom-color: #f7cd5d; color: #8a6a10; }
.tile.revealed { background: #fde2e1; border-bottom-color: var(--bad); color: #a33b39; }
#tiles.shake { animation: ouch 0.45s ease; }
/* Tiles take focus after browsing answers; the cursor tile already shows where typing goes. */
#tiles:focus { outline: none; }
/* A rejected guess stays visible but dimmed; typing replaces it. */
#tiles.stale .tile:not(.ghost) { color: var(--soft); background: var(--key); }

#message {
  min-height: 1.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
}
#message.bad { color: var(--bad); }
#message.good { color: #3f9a5e; }

#wrong-guesses {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
#wrong-guesses span {
  text-decoration: line-through;
  color: var(--soft);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.08em;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #e0708d;
  font-family: inherit;
}
button.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #e0708d; }

#status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.status-line { color: var(--soft); font-size: 1.05rem; }
.status-line b { color: var(--ink); }
.actions { display: flex; gap: 10px; }
button.secondary {
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
button.secondary:disabled { opacity: 0.5; cursor: default; }
button.secondary.quiet { color: var(--soft); }

.hidden { display: none !important; }

/* On-screen keyboard */
#keyboard {
  padding: 8px 6px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  user-select: none;
  -webkit-user-select: none;
}
#keyboard.disabled { opacity: 0.4; pointer-events: none; }
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  max-width: 48px;
  height: 56px;
  border: none;
  border-radius: 8px;
  background: var(--key);
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 0 var(--line);
}
.key.wide { max-width: 80px; flex: 1.6; font-size: 0.95rem; }
.key:active { background: #ddd0ec; }

/* Modal */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(59, 51, 85, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
#modal-card {
  position: relative;
  background: var(--card);
  border-radius: 20px;
  padding: 24px 22px;
  max-width: 460px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  font-size: 1.1rem;
  line-height: 1.5;
}
#modal-card .close { position: absolute; top: 12px; right: 12px; }
#modal-card h2 { margin: 0 0 10px; padding: 0 40px; color: var(--accent); }
#modal-card ul { padding-left: 1.2em; }
.center { text-align: center; }

.stats { display: flex; justify-content: space-around; margin: 14px 0; }
.stats div { text-align: center; }
.stats b { display: block; font-size: 1.8rem; }
.stats small { color: var(--soft); }

.recap { list-style: none; padding: 0 !important; margin: 12px 0; }
.recap li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.recap svg { flex: none; width: 36px; height: 32px; }
.recap b { text-transform: uppercase; letter-spacing: 0.05em; }
.recap small { display: block; color: var(--soft); }
.recap div { flex: 1; }
.recap .pts {
  flex: none;
  min-width: 42px;
  padding: 2px 8px;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
  text-align: center;
}

.big-score { font-size: 1.2rem; color: var(--soft); margin: 0; }
.big-score b { font-size: 2.4rem; color: var(--ink); }

.scale { display: flex; justify-content: center; gap: 12px; font-weight: 700; }
.scale span { display: flex; align-items: center; gap: 4px; }
.scale i { display: inline-block; width: 18px; height: 18px; border-radius: 4px; }

.countdown { color: var(--soft); margin-top: 12px; }

#toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 20;
}

/* The chart complements the full text recap. */
.results-chart { margin: 18px 0; }
.results-chart figcaption { font-weight: 800; text-align: center; }
.results-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.results-chart text { fill: var(--ink); font-size: 12px; }
.results-chart .chart-score { font-weight: 700; }
.chart-grid { stroke: var(--line); stroke-dasharray: 3 4; }
.results-chart p { text-align: center; font-size: 0.85rem; margin: 0; }
.recap div { min-width: 0; overflow-wrap: anywhere; }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.frequency-note { font-size: 0.85rem; color: var(--soft); text-align: center; }

.mode-switch { display:flex; justify-content:center; gap:8px; margin:12px 0; }
.mode-switch a { color:var(--ink); padding:8px 18px; border:2px solid transparent; border-radius:20px; text-decoration:none; }
.mode-switch a[aria-current="page"] { border-color:currentColor; font-weight:700; }
.mode-switch a:focus-visible { outline:3px solid var(--ink); outline-offset:3px; }
#mode-description { font-size:13px; margin:0 0 16px; }

#answer-options { display:flex; align-items:center; justify-content:center; gap:12px; margin:8px 0; }
.answer-entry > button { min-width:44px; min-height:44px; font-size:24px; padding:4px 12px; }
#answer-option-label { font-size:13px; }
#another-round { display:block; margin:12px auto 0; }

.answer-entry { display:flex; align-items:center; gap:6px; width:100%; }
.answer-entry #tiles { flex:1; min-width:0; }
.answer-entry > button { flex:0 0 36px; min-width:36px; padding:4px; }

.link-btn { background: none; border: none; padding: 4px; color: var(--soft); text-decoration: underline; font: inherit; font-size: 0.95rem; cursor: pointer; }
.actions-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* Wordmark: gooey letters in the seven level colors, drawn by drawLogo(). */
h1.logo { line-height: 0; }
#logo { display: block; height: clamp(44px, 12vw, 56px); width: auto; max-width: 100%; overflow: visible; }
#logo text { font-family: inherit; letter-spacing: 0.5px; }
#logo .drip { transform-box: fill-box; transform-origin: top; animation: drip 3.4s ease-in-out infinite; }
#logo .face { transform-box: fill-box; transform-origin: bottom; animation: bounce 1.6s ease-in-out infinite; }
@keyframes drip {
  0%, 100% { transform: scaleY(0.8); }
  50% { transform: scaleY(1.12); }
}

.header-actions { display: flex; gap: 6px; }

#help-btn { justify-self: start; }
.header-actions { justify-self: end; }
button.secondary.confirming { color: var(--bad); border-color: var(--bad); }
