:root {
  --bg: #fff7ec;
  --surface: #ffffff;
  --ink: #2b2140;
  --muted: #7a7090;
  --line: #eadfce;
  --accent: #6c5ce7;
  --accent-soft: #ece9ff;
  --good: #1fa971;
  --good-soft: #dcf6ea;
  --miss: #e8684a;
  --miss-soft: #fde6df;
  --timer: #f2b84b;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(43, 33, 64, 0.08), 0 14px 30px rgba(43, 33, 64, 0.08);
}

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

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 32px;
}

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

.title { font-size: 2.1rem; font-weight: 700; margin: 8px 0 0; text-align: center; }
.sub { margin: 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 10px; color: var(--muted); }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }

.link {
  background: none; border: 0; padding: 6px 4px;
  color: var(--accent); font-weight: 500;
}

.btn {
  background: var(--accent); color: #fff; border: 0;
  border-radius: 999px; padding: 12px 22px; font-weight: 600;
  box-shadow: 0 4px 0 #4b3fc0;
  transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4b3fc0; }
.btn.big { font-size: 1.35rem; padding: 16px 28px; }
.btn.ghost { background: var(--surface); color: var(--accent); box-shadow: 0 4px 0 var(--line); }
.btn:disabled { opacity: .45; cursor: default; }

.panel {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.panel.row { display: flex; flex-wrap: wrap; gap: 18px; justify-content: space-between; }

/* Players */
.player-list { display: grid; gap: 12px; }
.player-list button {
  background: var(--surface); border: 0; border-radius: var(--radius);
  padding: 18px; font-size: 1.4rem; font-weight: 600; box-shadow: var(--shadow);
}
.add-player { display: flex; gap: 10px; }
.add-player input {
  flex: 1; min-width: 0; font: inherit; padding: 12px 16px;
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
}

/* Table chips */
.chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.chips button {
  aspect-ratio: 1; border: 2px solid var(--line); background: var(--surface);
  border-radius: 16px; font-size: 1.25rem; font-weight: 600; position: relative;
}
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips button .dot {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px; border-radius: 50%;
}
.quick { display: flex; gap: 12px; margin-top: 8px; }

.seg { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 4px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 999px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,.08); }

/* Practice */
.progress { flex: 1; height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }

.card {
  background: var(--surface); border-radius: 28px; box-shadow: var(--shadow);
  padding: 34px 20px 26px; text-align: center; position: relative; overflow: hidden;
  border: 3px solid transparent; transition: border-color .15s, background .15s;
}
.card.good { border-color: var(--good); background: var(--good-soft); }
.card.miss { border-color: var(--miss); background: var(--miss-soft); }
.card.pop { animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: .3; } to { transform: none; opacity: 1; } }

.problem { font-size: clamp(3rem, 15vw, 4.5rem); font-weight: 700; line-height: 1.1; }
.answer {
  margin: 14px auto 0; min-height: 1.3em; min-width: 3ch; width: fit-content; padding: 0 16px;
  font-size: clamp(2.4rem, 12vw, 3.4rem); font-weight: 600; color: var(--accent);
  border-bottom: 4px solid var(--line);
}
.feedback { min-height: 1.6em; margin-top: 12px; font-size: 1.15rem; font-weight: 500; }
.card.good .feedback { color: var(--good); }
.card.miss .feedback { color: var(--miss); }

/* Small, calm timer: a thin bar along the card's bottom edge */
.timer { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: transparent; }
#timer-fill { height: 100%; width: 100%; background: var(--timer); transform-origin: left; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  height: 64px; border: 0; border-radius: 18px; background: var(--surface);
  font-size: 1.7rem; font-weight: 600; box-shadow: 0 4px 0 var(--line);
  touch-action: manipulation;
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.keypad .go { background: var(--good); color: #fff; box-shadow: 0 4px 0 #168055; }

/* Summary + stats */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 8px; text-align: center; display: flex; flex-direction: column; gap: 2px;
}
.tile b { font-size: 1.6rem; }
.tile span { font-size: .85rem; color: var(--muted); }
.tile small { font-size: .75rem; color: var(--muted); }

.missed { display: flex; flex-wrap: wrap; gap: 8px; }
.missed span { background: var(--miss-soft); color: #a8402a; padding: 6px 12px; border-radius: 999px; font-weight: 500; }
.actions { display: flex; flex-direction: column; gap: 12px; }

#stats-body { display: flex; flex-direction: column; gap: 18px; }

.bars { display: grid; gap: 8px; }
.bars .r { display: grid; grid-template-columns: 3.2em 1fr 3.6em; align-items: center; gap: 10px; font-size: .95rem; }
.bars .track { height: 16px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 99px; }
.bars .v { text-align: right; font-weight: 600; }
.bars .r.empty { color: var(--muted); }

.days { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.days .d { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.days .d i { display: block; border-radius: 6px 6px 2px 2px; min-height: 3px; }
.days-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 6px; }

.sessions { width: 100%; border-collapse: collapse; font-size: .95rem; }
.sessions td, .sessions th { padding: 8px 4px; text-align: left; border-bottom: 1px solid var(--line); }
.sessions th { color: var(--muted); font-weight: 500; font-size: .8rem; }
.sessions td:last-child, .sessions th:last-child { text-align: right; }

.grid { display: grid; gap: 3px; font-size: .72rem; }
.grid div { aspect-ratio: 1; display: grid; place-items: center; border-radius: 5px; font-weight: 600; }
.grid .h { color: var(--muted); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

@media (max-width: 380px) {
  .chips { grid-template-columns: repeat(4, 1fr); }
  .keypad button { height: 56px; }
}
