:root {
  --bg: #f7f7fb;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #707a8a;
  --ok: #2e7d32;
  --bad: #c62828;
  --focus: #3b82f6;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Noto Sans, sans-serif;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
  background: linear-gradient(135deg, #e0f2ff, #fde7f3 40%, #fff6d7 80%);
  background-size: 200% 200%;
  animation: bg-move 12s ease-in-out infinite alternate;
}

@keyframes bg-move {
  0% { background-position: 0% 0%; }
  100% { background-position: 100% 100%; }
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 16px;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.topbar h1 {
  font-size: 20px;
  margin: 0;
}
.actions { display: flex; gap: 8px; }

main { position: relative; flex: 1; display: grid; place-items: center; padding: 16px; height: calc(100svh - var(--topbar-h)); overflow: hidden; }

.bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(600px 300px at 20% 20%, rgba(59,130,246,0.15), transparent 60%),
    radial-gradient(500px 300px at 80% 30%, rgba(244,63,94,0.14), transparent 60%),
    radial-gradient(500px 300px at 30% 80%, rgba(16,185,129,0.12), transparent 60%);
  filter: blur(0px);
}

.screen { position: relative; z-index: 1; width: min(100%, 820px); height: 100%; background: rgba(255,255,255,0.6); backdrop-filter: blur(10px); border-radius: 20px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); display: grid; grid-template-rows: auto auto auto 1fr; align-content: start; }
.hidden { display: none; }

.lead { text-align: center; font-size: 18px; color: var(--muted); margin: 8px 0 16px; }

.status { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.message { font-size: 18px; font-weight: 600; }
.score { margin-left: auto; background: rgba(59,130,246,0.12); color: #0b5bd4; padding: 6px 10px; border-radius: 999px; font-weight: 600; }

.start { display: grid; gap: 16px; place-items: center; padding: 32px 20px; text-align: center; }
.hero { display: grid; gap: 8px; }
.hero-emoji { font-size: 64px; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.12)); }
.hero-title { margin: 0; font-size: 24px; }

.prompt {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.8);
  border: 1px solid rgba(13, 18, 28, 0.06);
  border-radius: 16px;
  padding: 12px 12px 12px 14px;
  margin: 10px 0 12px;
}
.prompt-left { min-width: 0; }
.prompt-label { font-size: 12px; color: var(--muted); }
.prompt-text { font-size: 22px; font-weight: 700; }
.speak-btn { margin-left: auto; background: #111827; color: #fff; border-color: #111827; border-radius: 12px; }
.speak-btn:disabled { opacity: 0.6; }

.progress { display: flex; gap: 8px; justify-content: center; margin: 6px 0 14px; }
.progress .dot { width: 12px; height: 12px; border-radius: 999px; background: rgba(0,0,0,0.1); box-shadow: inset 0 1px 1px rgba(0,0,0,0.08); }
.progress .dot.filled { background: linear-gradient(180deg, #60a5fa, #2563eb); box-shadow: 0 1px 2px rgba(37,99,235,0.35); }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  align-content: start;
}

@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border: 3px solid transparent;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12), inset 0 0 0 1px rgba(255,255,255,0.35);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, border-color 0.2s ease; 
}
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: scale(0.98); }
.tile .label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  background: rgba(255,255,255,0.78);
  color: #111827;
  padding: 6px 10px;
  border-radius: 12px;
  font-weight: 600;
  text-align: center;
}
.tile.light .label { background: rgba(0,0,0,0.6); color: #fff; }

.tile.correct { outline: 4px solid var(--ok); outline-offset: 2px; }
.tile.wrong { animation: shake 200ms linear 0s 1; border-color: var(--bad); }
@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

button {
  -webkit-tap-highlight-color: transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 16px;
  border: 1px solid #d0d5dd;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
button.big { font-size: 18px; padding: 14px 18px; border-radius: 12px; }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.primary { background: var(--focus); color: white; border-color: var(--focus); }
button.secondary { background: #eef2ff; border-color: #c7d2fe; }
button.ghost { background: transparent; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Ripple effect for taps */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  animation: ripple 500ms ease-out;
  pointer-events: none;
  background: rgba(255,255,255,0.45);
  width: 20px; height: 20px;
}
@keyframes ripple {
  to { transform: scale(12); opacity: 0; }
}

dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,0.25); }
dialog form { padding: 16px; min-width: min(90vw, 520px); }
dialog h2 { margin-top: 0; }
.field { display: grid; gap: 6px; margin: 12px 0; }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field input, .field select { padding: 10px; border-radius: 10px; border: 1px solid #d0d5dd; font-size: 16px; }
.spacer { flex: 1; }

.footer { text-align: center; color: var(--muted); padding: 8px 0 16px; }
