:root {
  --bg: #fff8ec;
  --ink: #2b2d42;
  --muted: #6b6f85;
  --card: #ffffff;
  --soft: #f1e6d3;
  --accent: #ff8c42;
  --accent-dark: #d9661a;
  --pick: #3d7fe0;
  --pick-bg: #e8f1ff;
  --good: #2f9e65;
  --good-dark: #237a4d;
  --bad: #d63d42;
  --gold: #f5b700;
  --gold-dark: #a87a00;
  --sun: #fff3c4;
  --purple: #7a5cff;
  --radius: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "Segoe UI Rounded", "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  /* Avakuvalt avatuna ulatub leht iPhone'i sälgu ja kodunupu riba alla. */
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.app { max-width: 540px; margin: 0 auto; }

.screen { display: flex; flex-direction: column; gap: 16px; }

h1 {
  font-size: clamp(2rem, 8vw, 3rem);
  margin: 12px 0 0;
  text-align: center;
}

h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--muted);
  margin: 4px 0 0;
}

.lead {
  text-align: center;
  font-size: 1.2rem;
  color: var(--muted);
  margin: 0;
}

ul { list-style: none; margin: 0; padding: 0; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: default; }
button:focus-visible { outline: 4px solid var(--pick); outline-offset: 3px; }

.link { color: var(--muted); font-size: 1rem; padding: 8px 4px; }

.big {
  background: var(--accent);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--accent-dark);
  margin-top: 4px;
}

.big:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-dark); }

.secondary {
  background: var(--card);
  border: 3px solid var(--soft);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1.2rem;
  font-weight: 700;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px 16px;
}

.panel h2 { margin: 0 0 8px; }

.hint {
  background: var(--sun);
  border-radius: 16px;
  padding: 10px 14px;
  margin: 0;
  font-weight: 700;
  text-align: center;
}

.install { width: 100%; font-size: 1.1rem; }

.sync {
  margin: 24px 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.sync[data-status="offline"] { color: var(--accent-dark); font-weight: 700; }

.pill {
  background: var(--card);
  border-radius: 99px;
  padding: 6px 12px;
  font-weight: 800;
  white-space: nowrap;
}

/* Mängija riba */

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  box-shadow: 0 4px 0 var(--soft);
}

.hud-avatar { font-size: 2.6rem; line-height: 1; }
.hud-main { flex: 1; min-width: 0; }
.hud-name { display: block; font-size: 1.2rem; }
.hud-title { display: block; color: var(--muted); font-size: 0.95rem; }

.xpbar {
  height: 12px;
  margin-top: 6px;
  background: var(--soft);
  border-radius: 99px;
  overflow: hidden;
}

.xpfill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--pick), var(--purple));
  border-radius: 99px;
  transition: width 0.8s ease;
}

.coins { font-size: 1.4rem; font-weight: 800; white-space: nowrap; }

/* Kes mängib? */

.players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 3px solid transparent;
  border-radius: 24px;
  padding: 20px 8px;
  box-shadow: 0 5px 0 var(--soft);
}

.player:hover { border-color: var(--pick); }
.player-avatar { font-size: 4.2rem; line-height: 1.1; }
.player-name { font-size: 1.6rem; font-weight: 800; }
.player-level, .player-coins { color: var(--muted); font-size: 0.95rem; text-align: center; }

/* Menüü */

.tasks { display: grid; gap: 12px; }

.task-row {
  display: grid;
  grid-template-columns: 7.4em repeat(3, 1fr);
  gap: 8px;
  align-items: center;
}

.task-label { font-weight: 800; font-size: 1.05rem; }

.task {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--card);
  border: 3px solid var(--soft);
  border-radius: 16px;
  padding: 10px 4px;
}

.task:hover { border-color: var(--pick); }
.task-max { font-weight: 800; font-size: 1.05rem; }
.task-stars { font-size: 1.2rem; letter-spacing: 0.05em; }

.star { color: var(--soft); }
.star.on { color: var(--gold); }

.goal { margin: 0; text-align: center; font-weight: 700; color: var(--muted); }

.menu {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.menu button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 3px solid var(--soft);
  border-radius: var(--radius);
  padding: 12px 4px;
  font-weight: 800;
}

.menu button:hover { border-color: var(--pick); }
.menu .icon { font-size: 2rem; }

.footer-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }

/* Mäng */

.topbar { display: flex; align-items: center; gap: 8px; }
.topbar .streak { margin-left: auto; color: var(--accent-dark); animation: pop 0.4s ease; }
.topbar #round-coins { margin-left: auto; }
.topbar .streak:not([hidden]) + #round-coins { margin-left: 0; }

.progress { display: flex; justify-content: center; gap: 6px; }

.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--soft); }
.dot.now { background: var(--pick); }
.dot.good { background: var(--good); }
.dot.miss { background: var(--accent); }

.card {
  position: relative;
  background: var(--card);
  border-radius: 28px;
  padding: 40px 12px 16px;
  text-align: center;
  box-shadow: 0 6px 0 var(--soft);
}

.buddy { position: absolute; top: 10px; left: 14px; font-size: 2.2rem; line-height: 1; }

.sum {
  font-size: clamp(2rem, 10vw, 4rem);
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.answer {
  display: inline-block;
  min-width: 2.2em;
  padding: 0 0.15em;
  border-bottom: 5px solid var(--pick);
  color: var(--pick);
}

.answer.empty { color: var(--soft); }

.feedback {
  min-height: 1.6em;
  margin: 12px 0 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.feedback[data-tone="good"] { color: var(--good); }
.feedback[data-tone="retry"] { color: var(--accent-dark); }
.feedback[data-tone="show"] { color: var(--bad); }

.float {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold-dark);
  animation: floatup 1.1s ease forwards;
}

.card.right { animation: pop 0.4s ease; }
.card.right .buddy { animation: hop 0.5s ease; }
.card.wrong { animation: shake 0.4s ease; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.keypad button {
  background: var(--card);
  border-radius: 18px;
  padding: 14px 0;
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 0 4px 0 var(--soft);
}

.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--soft); }
.keypad .back { color: var(--muted); }
.keypad .ok { background: var(--good); color: #fff; box-shadow: 0 4px 0 var(--good-dark); }
.keypad .ok:active { box-shadow: 0 1px 0 var(--good-dark); }

/* Ringi tulemus */

.stars { display: block; text-align: center; font-size: 4rem; letter-spacing: 0.1em; line-height: 1.1; }
.stars .star.on { display: inline-block; animation: starpop 0.5s ease backwards; }
.stars .star:nth-child(2) { animation-delay: 0.25s; }
.stars .star:nth-child(3) { animation-delay: 0.5s; }

.lines { display: grid; gap: 6px; font-size: 1.15rem; }
.lines li { display: flex; justify-content: space-between; gap: 12px; }

.lines-total {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 2px dashed var(--soft);
  font-size: 1.35rem;
  font-weight: 800;
}

.levelup {
  background: linear-gradient(90deg, var(--pick), var(--purple));
  color: #fff;
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  animation: pop 0.6s ease;
}

.badge-mini { display: grid; gap: 6px; font-size: 1.2rem; }
.badge-mini li { display: flex; align-items: center; gap: 10px; }
.badge-mini-icon { font-size: 2rem; }

.mistake-list {
  display: grid;
  gap: 4px;
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Alamlehed */

.subhead { display: grid; grid-template-columns: auto 1fr auto; align-items: center; }
.subhead::after { content: ""; width: 5em; }
.subhead .link { width: 5em; text-align: left; }
.subhead h1 { margin: 0; font-size: clamp(1.6rem, 6vw, 2.2rem); }
.count { color: var(--muted); font-size: 0.6em; white-space: nowrap; }

.animal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.animal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--card);
  border: 3px solid var(--soft);
  border-radius: var(--radius);
  padding: 12px 6px 8px;
}

.animal-emoji { font-size: 3rem; line-height: 1.2; }
.animal-name { font-weight: 800; }
.animal-action { margin-top: 4px; padding: 4px 14px; border-radius: 99px; background: var(--soft); font-weight: 800; }
.animal-note { min-height: 1.2em; font-size: 0.8rem; color: var(--muted); }

.animal.buyable .animal-action { background: var(--sun); }
.animal.buyable:hover, .animal.owned:hover { border-color: var(--pick); }
.animal.owned .animal-action { background: var(--pick-bg); color: var(--pick); }
.animal.chosen { border-color: var(--good); }
.animal.chosen .animal-action { background: var(--good); color: #fff; }
.animal.confirm { border-color: var(--accent); }
.animal.confirm .animal-action { background: var(--accent); color: #fff; }
.animal.locked .animal-emoji { filter: grayscale(1); opacity: 0.35; }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 3px solid var(--soft);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}

.badge.earned { border-color: var(--gold); background: #fffdf3; }
.badge-icon { font-size: 2.6rem; line-height: 1.2; }
.badge:not(.earned) .badge-icon { filter: grayscale(1); opacity: 0.35; }
.badge-name { font-size: 1.05rem; }
.badge-text { font-size: 0.9rem; color: var(--muted); }
.badge-date { font-size: 0.8rem; font-weight: 700; color: var(--gold-dark); }
.badge:not(.earned) .badge-date { color: var(--muted); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 8px;
}

.tile-value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: 0.95rem; text-align: center; }

.history { display: grid; gap: 8px; }

.history li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: 14px;
  padding: 10px 14px;
}

.history-date { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.history-task { font-weight: 700; }
.history-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.history-stars { font-size: 1.1rem; }
.history .empty-note { display: block; color: var(--muted); text-align: center; }

/* Teated ja pidu */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: #fff;
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 700;
  text-align: center;
  z-index: 20;
}

.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 10; }
.confetti span { position: absolute; top: -48px; animation: fall 2.4s ease-in forwards; }

@keyframes pop { 50% { transform: scale(1.05); } }
@keyframes hop { 40% { transform: translateY(-12px) rotate(-10deg); } }
@keyframes starpop { from { transform: scale(0); } 70% { transform: scale(1.3); } }
@keyframes floatup { to { transform: translateY(-40px); opacity: 0; } }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); } }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

@media (max-width: 440px) {
  .task-row { grid-template-columns: repeat(3, 1fr); }
  .task-label { grid-column: 1 / -1; }
  .history li { grid-template-columns: 1fr auto; }
  .history-date { grid-column: 1 / -1; }
}

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