  :root {
    --ink: #1f2340;
    --card: rgba(255,255,255,0.93);
    --accent: #ff8a3d;
    --ok: #22b573;
    --bad: #ef4b5f;
    --blank: #fff4c2;
    --muted: #6b6f8a;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; }
  html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
  body {
    font-family: "Fredoka", system-ui, sans-serif;
    color: var(--ink);
    background: #8ec5ff;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; user-select: none;
  }
  #bg { position: fixed; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; }
  .wrap {
    position: relative; z-index: 1;
    min-height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
    padding: 16px;
  }
  .card {
    background: var(--card);
    border-radius: 28px;
    box-shadow: 0 20px 50px rgba(30,40,90,0.25);
    padding: 28px 32px;
    width: min(760px, 100%);
    text-align: center;
    backdrop-filter: blur(6px);
  }
  h1 { margin: 0 0 6px; font-size: 34px; }
  .sub { color: var(--muted); margin: 0 0 22px; }
  .levels { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
  .lvl {
    border: 0; cursor: pointer; font: inherit;
    padding: 18px 26px; border-radius: 20px; min-width: 220px;
    color: white; font-size: 20px; font-weight: 600;
    box-shadow: 0 6px 0 rgba(0,0,0,0.18);
    transition: transform .1s;
  }
  .lvl small { display: block; font-weight: 400; font-size: 14px; opacity: .9; margin-top: 4px; }
  .lvl:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.18); }
  .lvl1 { background: #36b37e; }
  .progressLink { display: inline-block; margin-top: 16px; color: var(--muted); font-weight: 600; }
  .lvl2 { background: #6c5ce7; }

  .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; flex-wrap: wrap; }
  .pill { background: #eef1ff; border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 15px; }
  .link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; }
  .pos { color: var(--accent); font-weight: 600; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; }
  .def { font-size: 22px; line-height: 1.4; margin: 8px 0 18px; }
  .speak {
    border: 0; cursor: pointer; font: inherit; font-size: 18px; font-weight: 600;
    background: var(--accent); color: white; padding: 10px 22px; border-radius: 999px;
    box-shadow: 0 4px 0 #d66a22;
  }
  .speak.meaning { background: #4c6ef5; box-shadow: 0 4px 0 #3451c7; }
  .speak.meaning:active { box-shadow: 0 2px 0 #3451c7; }
  .speak:active { transform: translateY(2px); box-shadow: 0 2px 0 #d66a22; }
  .slots { display: flex; justify-content: center; gap: 8px; margin: 26px 0 10px; flex-wrap: wrap; cursor: text; }
  .slot {
    width: 58px; height: 70px; border-radius: 14px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: 40px; font-weight: 700; position: relative;
    background: #e9ecf8; color: var(--ink);
    transition: background .15s, transform .15s;
  }
  .slot.blank { background: var(--blank); border: 3px dashed #e0b400; }
  .slot.cur { border: 3px solid var(--accent); transform: translateY(-4px); }
  .slot.cur::after {
    content: ""; position: absolute; bottom: 8px; width: 24px; height: 3px; background: var(--accent);
    animation: blink 1s steps(1) infinite;
  }
  .slot.right { background: #c9f2dd; border: 3px solid var(--ok); }
  .slot.wrong { background: #ffd6db; border: 3px solid var(--bad); color: var(--bad); }
  .slot .fix { position: absolute; bottom: -24px; font-size: 16px; color: var(--ok); font-weight: 600; }
  @keyframes blink { 50% { opacity: 0; } }
  .shake { animation: shake .4s; }
  @keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }
  .msg { min-height: 32px; font-size: 20px; font-weight: 600; margin-top: 22px; }
  .msg.ok { color: var(--ok); }
  .msg.bad { color: var(--bad); }
  .actions { display: flex; gap: 10px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
  .btn {
    border: 0; cursor: pointer; font: inherit; font-size: 16px; font-weight: 600;
    padding: 10px 20px; border-radius: 14px; background: #eef1ff; color: var(--ink);
  }
  .btn.primary { background: #4c6ef5; color: white; }
  .hint { color: var(--muted); font-size: 14px; margin-top: 12px; }
  #kb { position: absolute; opacity: 0; pointer-events: none; height: 1px; width: 1px; font-size: 16px; }

  /* on-screen letter keyboard */
  .keys { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
  .krow { display: flex; justify-content: center; gap: 6px; }
  .key {
    flex: 1 1 0; max-width: 64px; height: 58px;
    border: 0; border-radius: 12px; cursor: pointer;
    font: inherit; font-size: 28px; font-weight: 600; color: var(--ink);
    background: white; box-shadow: 0 4px 0 #c5cbe3;
    touch-action: manipulation; white-space: nowrap;
  }
  .key:active, .key.down { transform: translateY(3px); box-shadow: 0 1px 0 #c5cbe3; background: #fff4c2; }
  .key.wide { max-width: 110px; flex-grow: 1.6; font-size: 22px; background: #ffe3e6; box-shadow: 0 4px 0 #f0b3bb; }
  .key.go { max-width: 110px; flex-grow: 1.6; font-size: 22px; background: #4c6ef5; color: white; box-shadow: 0 4px 0 #3451c7; }
  .keys.hidden { display: none; }
  body.touch .hint { display: none; }
  body.touch #check { display: none; }
  body.touch .msg { margin-top: 14px; }
  .hidden { display: none !important; }

  /* race HUD */
  #hud {
    position: fixed; top: 12px; left: 16px; right: 16px; z-index: 2;
    display: flex; align-items: center; gap: 14px; pointer-events: none;
  }
  #hudPlace {
    background: #ff6a00; color: white; font-weight: 700; font-size: 26px;
    padding: 4px 16px; border-radius: 14px; box-shadow: 0 4px 0 #c24f00; min-width: 76px; text-align: center;
  }
  .hudBar {
    flex: 1; position: relative; height: 34px; border-radius: 999px;
    background: rgba(255,255,255,0.85); box-shadow: 0 4px 14px rgba(30,40,90,0.2);
    padding: 0 40px 0 18px;
  }
  .hudBar::after { content: "🏁"; position: absolute; right: 8px; top: 3px; font-size: 22px; }
  #hudTrack { position: relative; height: 100%; }
  #hudTrack::before { content: ""; position: absolute; left: 0; right: 0; top: 16px; height: 3px; background: #d5daea; border-radius: 2px; }
  .dot {
    position: absolute; top: 4px; width: 26px; height: 26px; margin-left: -13px; border-radius: 50%;
    color: white; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center;
    border: 2px solid white; transition: left .2s linear;
  }
  .dot.me { width: 30px; height: 30px; margin-left: -15px; top: 2px; font-size: 15px; z-index: 2; }

  /* finish screen */
  .bigPlace { font-size: 64px; font-weight: 700; color: #ff6a00; margin: 4px 0; }

  /* short screens (iPad landscape, laptops): compact card so the race stays visible */
  @media (max-height: 860px) {
    .wrap { padding: 10px 16px; }
    .card { padding: 12px 20px 14px; border-radius: 22px; }
    .top { margin-bottom: 4px; }
    .pill { padding: 3px 12px; font-size: 14px; }
    .pos { font-size: 13px; }
    .def { font-size: 19px; margin: 0 0 8px; }
    .speak { padding: 6px 16px; font-size: 16px; }
    .actions { margin-top: 4px; }
    .slots { margin: 10px 0 2px; }
    .slot { width: 50px; height: 58px; font-size: 34px; }
    .slot .fix { bottom: -20px; font-size: 14px; }
    .msg { margin-top: 10px; min-height: 24px; font-size: 17px; }
    .btn { padding: 6px 16px; font-size: 15px; }
    .hint { margin-top: 6px; font-size: 13px; }
    .keys { margin-top: 8px; gap: 6px; }
    .key { height: 46px; font-size: 24px; }
    .key.wide, .key.go { font-size: 19px; }
    h1 { font-size: 28px; }
    .sub { margin-bottom: 14px; }
    .lvl { padding: 12px 22px; }
  }

  @media (max-width: 560px) {
    .card { padding: 20px 16px; }
    .slot { width: 40px; height: 52px; font-size: 28px; border-radius: 10px; }
    .def { font-size: 18px; }
    .lvl { min-width: 0; width: 100%; }
  }

/* landing page */
body.landing {
  background: linear-gradient(180deg, #0b1236 0%, #3a3f9e 38%, #8ec5ff 72%, #9be3a2 100%);
  min-height: 100%;
}
body.landing .wrap { justify-content: center; }
body.landing #start { width: min(820px, 100%); }
.step { font-weight: 700; color: var(--muted); text-align: left; margin: 14px 0 8px; font-size: 15px; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mode {
  border: 3px solid transparent; cursor: pointer; font: inherit; color: var(--ink);
  background: #eef1ff; border-radius: 20px; padding: 14px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .1s, border-color .1s, background .1s;
}
.mode .emo { font-size: 48px; line-height: 1.1; }
.mode b { font-size: 19px; }
.mode small { color: var(--muted); font-size: 13px; }
.mode.on { border-color: var(--accent); background: #fff4e8; transform: translateY(-3px); box-shadow: 0 6px 0 rgba(255,138,61,0.35); }
@media (max-width: 560px) {
  .modes { grid-template-columns: 1fr; }
  .mode { flex-direction: row; gap: 10px; justify-content: flex-start; padding: 10px 14px; }
  .mode .emo { font-size: 34px; }
  .mode small { margin-left: auto; }
}

/* per-race HUD ends */
body.mode-jet { background: #7cc0ff; }
body.mode-jet .hudBar, body.mode-space .hudBar { padding-left: 40px; }
body.mode-jet .hudBar::before { content: "🇺🇸"; position: absolute; left: 8px; top: 3px; font-size: 22px; }
body.mode-jet .hudBar::after { content: "🇹🇼"; }
body.mode-space { background: #070b24; }
body.mode-space .hudBar::before { content: "☿"; position: absolute; left: 12px; top: 2px; font-size: 22px; color: #8a8f9c; font-weight: 700; }
body.mode-space .hudBar::after { content: "♆"; color: #3a6df0; font-weight: 700; top: 2px; right: 12px; }
