/* Letter Rally — Ancient Paleo Quest */
:root {
  --cream: #fff8e7;
  --cream-deep: #f3e6c8;
  --gold: #d4a017;
  --gold-soft: #f0d78c;
  --gold-dark: #8a6a12;
  --sky: #7ec8e3;
  --sky-deep: #4a9fc0;
  --sky-pale: #d6eef7;
  --sand: #e8c98a;
  --sand-deep: #c9a45c;
  --ink: #3d2e1a;
  --ink-soft: #5c4a32;
  --card: #fffdf6;
  --good: #5a9e5a;
  --good-deep: #3d7a45;
  --bad: #c45c4a;
  --wood: #c4a574;
  --shadow: rgba(61,46,26,0.16);
  --radius: 18px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "PaleoHeb",var(--font); color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky-pale) 42%, var(--cream) 100%);
  overflow: hidden; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
#app {
  position: relative; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
canvas#game {
  display: block;
  width: min(100vw, 1100px);
  height: auto;
  max-height: calc(100vh - 8px);
  background: var(--sky);
  border-radius: 14px;
  box-shadow: 0 10px 36px var(--shadow), 0 0 0 3px #e6d7a8;
}
.overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(255,248,231,0.92);
  backdrop-filter: blur(6px);
  z-index: 30; padding: 12px;
}
.overlay.active { display: flex; }
.panel {
  background: linear-gradient(180deg, #fffef8, var(--cream));
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--gold-dark), 0 18px 44px var(--shadow);
  padding: 20px 22px;
  max-width: 540px; width: 100%;
  max-height: min(92vh, 760px);
  overflow: auto;
  text-align: center;
}
.panel h1 {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 4vw, 1.9rem);
  color: var(--good-deep);
  letter-spacing: 0.02em;
}
.panel h2 { margin: 0 0 8px; font-size: 1.2rem; color: var(--good-deep); }
.panel .tag { color: var(--ink-soft); margin: 0 0 12px; font-size: 0.95rem; line-height: 1.4; }
.credit {
  font-size: 0.72rem; color: var(--ink-soft); line-height: 1.45;
  margin-top: 12px;
}
.credit a { color: var(--good-deep); }
.mode-row { display: grid; gap: 10px; margin: 14px 0 10px; }
.btn {
  appearance: none; border: none; cursor: pointer;
  border-radius: 999px; padding: 12px 20px;
  font-size: 1rem; font-weight: 700; font-family: "PaleoHeb",inherit;
  background: var(--good); color: #fff;
  box-shadow: 0 3px 0 var(--good-deep);
  transition: transform 0.08s ease;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--good-deep); }
.btn.gold {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: var(--ink); box-shadow: 0 3px 0 var(--gold-dark);
}
.btn.secondary {
  background: var(--cream-deep); color: var(--ink);
  box-shadow: 0 3px 0 #c9b88a; border: 1px solid #e0d0a0;
}
.btn.block { width: 100%; display: block; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.mode-btn {
  appearance: none; width: 100%; text-align: left;
  border: 2px solid var(--gold); border-radius: 14px;
  background: var(--card); padding: 14px 16px; cursor: pointer;
  font-family: "PaleoHeb",inherit; color: var(--ink);
  box-shadow: 0 3px 0 var(--gold-dark);
}
.mode-btn strong { display: block; color: var(--good-deep); font-size: 1.05rem; }
.mode-btn span { font-size: 0.85rem; color: var(--ink-soft); }
.mode-btn.selected { outline: 3px solid var(--good); background: #f0f8ec; }

.glyph-wrap {
  width: 108px; height: 108px; margin: 6px auto 10px;
  background: #fff; border-radius: 16px;
  border: 2px solid #e6d7a8;
  display: flex; align-items: center; justify-content: center;
  color: var(--good-deep);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.04);
}
.glyph-wrap.svg-sm { width: 88px; height: 88px; }
.glyph-wrap svg { width: 78%; height: 78%; display: block; }

.fact-grid {
  text-align: left; font-size: 0.86rem; line-height: 1.45;
  background: rgba(255,253,246,0.95); border-radius: 12px;
  border: 1px solid #e6d7a8; padding: 12px 14px; margin: 8px 0 12px;
}
.fact-grid dt {
  font-weight: 700; color: var(--good-deep); font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.04em; margin-top: 8px;
}
.fact-grid dt:first-child { margin-top: 0; }
.fact-grid dd { margin: 2px 0 0; white-space: pre-wrap; color: var(--ink); }

.quiz-step {
  display: inline-block; font-size: 0.75rem; font-weight: 700;
  background: var(--gold-soft); color: var(--ink);
  border-radius: 999px; padding: 4px 10px; margin-bottom: 8px;
}
.quiz-opts { display: grid; gap: 8px; margin: 12px 0; }
.quiz-opts button {
  appearance: none; cursor: pointer; font-family: "PaleoHeb",inherit;
  text-align: left; padding: 12px 14px;
  border-radius: 12px; border: 2px solid #e0d0a0;
  background: #fff; color: var(--ink); font-size: 0.95rem;
  box-shadow: 0 2px 0 #c9b88a;
}
.quiz-opts button:hover { border-color: var(--gold); }
.quiz-opts button.correct { border-color: var(--good); background: #e8f5e4; }
.quiz-opts button.wrong { border-color: var(--bad); background: #fdecea; opacity: 0.85; }
.quiz-opts button:disabled { cursor: default; }

#hud {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: min(100vw - 16px, 1100px);
  display: none; pointer-events: none; z-index: 15;
  padding: 0 12px;
}
#hud.active { display: block; }
.hud-row {
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
}
.pill {
  pointer-events: auto;
  background: rgba(255,253,246,0.94);
  border: 2px solid #e6d7a8;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem; font-weight: 700;
  color: var(--ink);
  box-shadow: 0 2px 8px var(--shadow);
}
.pill.ghost { opacity: 0.9; font-weight: 600; }
#progressRibbon {
  margin-top: 8px;
  height: 14px;
  background: rgba(255,253,246,0.85);
  border: 2px solid #e6d7a8;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}
#progressFill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold-soft), var(--gold));
  border-radius: 999px;
  transition: width 0.35s ease;
}
.ribbon-labels {
  display: flex; justify-content: space-between;
  font-size: 0.68rem; color: var(--ink-soft);
  margin-top: 3px; padding: 0 4px;
}

#speedo {
  position: absolute; right: 14px; bottom: 118px;
  width: 86px; height: 86px; display: none; z-index: 16;
  pointer-events: none;
}
#speedo.active { display: block; }
#speedo svg { width: 100%; height: 100%; filter: drop-shadow(0 3px 6px var(--shadow)); }
#speedLabel {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end; padding-bottom: 14px;
  font-size: 0.7rem; font-weight: 800; color: var(--ink);
}

#touch {
  position: absolute; left: 0; right: 0; bottom: 10px;
  display: none; justify-content: space-between; align-items: flex-end;
  padding: 0 14px; z-index: 18; pointer-events: none;
}
#touch.active { display: flex; }
.pad {
  pointer-events: auto; display: grid; gap: 8px;
}
.pad-steer { grid-template-columns: 1fr 1fr; }
.pad-drive { grid-template-columns: 1fr; }
.pad button {
  width: 64px; height: 64px; border-radius: 16px;
  border: 2px solid #e6d7a8; background: rgba(255,253,246,0.92);
  font-size: 1.35rem; font-weight: 800; color: var(--ink);
  box-shadow: 0 3px 0 #c9b88a; cursor: pointer; font-family: "PaleoHeb",inherit;
}
.pad button:active, .pad button.held {
  transform: translateY(2px); box-shadow: 0 1px 0 #c9b88a;
  background: var(--gold-soft);
}
#btnMenu {
  pointer-events: auto;
  position: absolute; top: 10px; right: 14px; z-index: 17;
  display: none;
  appearance: none; border: 2px solid #e6d7a8;
  background: rgba(255,253,246,0.94); border-radius: 999px;
  padding: 6px 12px; font-weight: 700; font-family: "PaleoHeb",inherit;
  color: var(--ink); cursor: pointer; font-size: 0.8rem;
  box-shadow: 0 2px 8px var(--shadow);
}
#btnMenu.active { display: block; }

@media (max-width: 640px) {
  .pad button { width: 56px; height: 56px; }
  #speedo { bottom: 130px; width: 72px; height: 72px; right: 10px; }
}

#stPicture {
  text-align: left;
  background: rgba(255,253,246,0.95);
  border: 1px solid #e6d7a8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--ink);
}
#stPicture strong { color: var(--good-deep); }

#btnHub{pointer-events:auto;position:absolute;top:10px;right:92px;z-index:17;display:none;border:2px solid #e6d7a8;background:rgba(255,253,246,.94);border-radius:999px;padding:6px 12px;font-weight:700;color:var(--ink);font-size:.8rem;text-decoration:none;box-shadow:0 2px 8px var(--shadow)}
body.playing #btnHub{display:block}
/* 1030b: Hub + Menu live in the HUD row flow so they never cover pills */
#hud #btnHub,#hud #btnMenu{position:static;top:auto;right:auto}
.hud-row{justify-content:flex-start}
#hudProgress{margin-right:auto}
.hud-row>*{white-space:nowrap}
@media(max-width:440px){.hud-row{gap:5px}.hud-row .pill,#hud #btnHub,#hud #btnMenu{padding:5px 8px;font-size:.72rem}}
