:root {
  --bg: color-mix(in oklab, var(--accent) 4%, #fff);
  --card: #ffffff;
  --ink: #1d1b26;
  --muted: #6b6880;
  --line: #e7e5f2;
  --accent: #534ab7;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in oklab, var(--accent) 9%, #fff);
  --accent-line: color-mix(in oklab, var(--accent) 35%, #fff);
  /* Button roles, set from the host page's theme by ../theme.js. */
  --cta: #534ab7;
  --cta-ink: #ffffff;
  --chosen: #534ab7;
  --chosen-ink: #ffffff;
  --mint: #e2f5ec;
  --sky: #e3effd;
  --peach: #fdebe1;
  --shadow: 0 1px 2px rgba(29, 27, 38, .06), 0 4px 14px rgba(29, 27, 38, .06);
}

* {
  margin: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

canvas {
  background: radial-gradient(circle at center, #ffffff 0, var(--bg) 60%);
  display: block;
}

button { font: inherit; color: inherit; }

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ---- HUD ---- */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  pointer-events: none;
}

.hud > * { pointer-events: auto; }
.hud-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* Score and lives in one bar, split by thin lines. */
.scoreboard {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0;
  align-items: stretch;
  min-height: 44px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.pill + .pill { border-left: 1px solid var(--line); }
.pill .label { color: var(--muted); font-weight: 500; }
.pill strong { font-variant-numeric: tabular-nums; }
.pill.streak { background: #fff4d6; }

.controls .btn { min-height: 44px; border-radius: 12px; background: var(--card); border-color: var(--line); box-shadow: var(--shadow); }
.controls .btn:hover { background: var(--accent-soft); border-color: var(--accent-line); }

/* Off screen but focusable, so a phone shows its keyboard. */
.soft-keys {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
  border: 0;
  padding: 0;
}

/* ---- Overlays ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.overlay.soft { background: color-mix(in oklab, var(--bg) 60%, transparent); }

.panel {
  width: 100%;
  max-width: 440px;
  margin: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 1px 2px rgba(29, 27, 38, .04), 0 18px 48px rgba(29, 27, 38, .14);
  padding: 28px 24px 24px;
  text-align: center;
}

.panel.small { max-width: 340px; }
/* The card's picture, in a soft circle of the theme colour. */
.panel .emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-line);
  font-size: 36px;
  line-height: 1;
}
.panel h2 { margin: 14px 0 6px; font-size: 26px; letter-spacing: -.01em; }
.panel .lead { margin: 0 0 16px; color: var(--muted); font-size: 16px; line-height: 1.45; }
.panel .ready { font-weight: 700; color: var(--accent); }

.how {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 12px;
  text-align: left;
  font-size: 15px;
  line-height: 1.5;
}

.how p + p { margin-top: 6px; }

/* One rule a line: the icon in its own column, so wrapped words line up. */
.how p {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  align-items: start;
}

/* Every icon in the same box, centred on the first line of its rule. */
.how .ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  /* The rule's own line height, so the icon centres on its first line. */
  height: 1.5em;
}


.toggle-row { display: flex; margin-bottom: 16px; }

/* ---- Buttons (host app game standard, in the host page's colours) ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.btn .ico { font-size: 16px; line-height: 1; }
.btn-primary { background: var(--cta); color: var(--cta-ink); }
.btn-primary:hover { background: color-mix(in oklab, var(--cta) 88%, #000); }
.btn-outline { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-outline:hover { background: var(--accent-soft); border-color: var(--accent-line); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-block { width: 100%; min-height: 48px; font-size: 16px; }

/* Speed picker: equal tiles, icon over the name; the chosen one is filled. */
.levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.level {
  flex-direction: column;
  gap: 4px;
  min-height: 68px;
  padding: 8px 6px;
  border-radius: 12px;
  white-space: normal;
  text-align: center;
}

.level .ico { font-size: 22px; }
.level[aria-pressed="true"] { background: var(--chosen); color: var(--chosen-ink); border-color: var(--chosen); }
.level[aria-pressed="true"]:hover { background: color-mix(in oklab, var(--chosen) 88%, #000); }

/* "Capital letters too": a ghost button holding a small on/off switch. */
/* A setting row: the switch, then its name over what it does now. */
.toggle {
  width: 100%;
  justify-content: flex-start;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  white-space: normal;
  text-align: left;
}

.toggle-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toggle-title { font-size: 15px; font-weight: 600; }
.toggle-note { color: var(--muted); font-size: 13px; font-weight: 400; }

.toggle .switch {
  flex: none;
  position: relative;
  width: 30px;
  height: 18px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--muted) 35%, #fff);
}

.toggle .switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}

.toggle[aria-pressed="true"] .switch { background: var(--chosen); }
.toggle[aria-pressed="true"] .switch::after { left: 14px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* A card's buttons share its width, so none looks stranded. */
.panel .actions { margin-top: 4px; }
.panel .actions > .btn { flex: 1 1 0; min-width: max-content; min-height: 46px; border-radius: 12px; font-size: 15px; }
.panel .btn-outline { border-color: var(--accent-line); }

@media (max-width: 639px) {
  .btn { min-height: 44px; }
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}

.stat {
  background: var(--accent-soft);
  border: 1px solid color-mix(in oklab, var(--accent) 14%, #fff);
  border-radius: 14px;
  padding: 12px 6px;
}
.stat > span { display: block; font-size: 13px; color: var(--muted); }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: #fff4d6;
  font-weight: 700;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 76px;
  z-index: 30;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  font-size: 17px;
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 520px) {
  /* The level on a row of its own, the counts in a row under it. */
  .scoreboard { flex-wrap: wrap; }
  #levelPill { flex: 1 1 100%; min-height: 36px; justify-content: center; border-bottom: 1px solid var(--line); }
  #levelPill + .pill { border-left: 0; }
  .scoreboard .pill:not(#levelPill) { min-height: 40px; }
  .hud { padding: 8px; gap: 6px; }
  .pill { padding: 0 9px; font-size: 14px; }
  .scoreboard, .controls .btn { min-height: 38px; }
  .panel { padding: 20px 16px; }
  .panel h2 { font-size: 22px; }
  .toast { font-size: 15px; }
}

/* Short frames: keep the start card on one screen. */
@media (max-height: 640px) {
  .panel { padding: 16px; }
  .panel .emoji { width: 56px; height: 56px; font-size: 28px; }
  .panel h2 { margin: 4px 0; font-size: 22px; }
  .panel .lead { margin-bottom: 10px; font-size: 15px; }
  .how { margin-bottom: 10px; padding: 8px 12px; font-size: 14px; }
  .toggle-row { margin-bottom: 10px; }
}

@media (max-height: 520px) {
  .panel .emoji { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn { transition: transform .15s ease, background-color .15s ease, border-color .15s ease; }
  .toggle .switch, .toggle .switch::after { transition: all .15s ease; }
  .btn:active { transform: scale(.96); }
  .toast.show { animation: toast-pop 1.6s ease forwards; }
  .panel { animation: rise .3s ease-out; }
  .pill.bump { animation: bump .35s ease; }
  .pill.miss { animation: shake .3s ease; }

  @keyframes toast-pop {
    0% { opacity: 0; transform: translate(-50%, -10px) scale(.9); }
    12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
    20% { transform: translate(-50%, 0) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -6px); }
  }

  @keyframes rise {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to { opacity: 1; transform: none; }
  }

  @keyframes bump { 50% { transform: scale(1.12); } }

  @keyframes shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
  }
}
