/* ============================================================
   HEXA STACK — style.css
   Arcade visual theme: HUD, panels, buttons, overlays, toast.
   ============================================================ */

:root {
  --bg: #05070f;
  --ink: #eaf2ff;
  --dim: #8fa3c8;
  --cyan: #22d3ee;
  --cyan-deep: #0891b2;
  --mag: #e879f9;
  --amber: #fbbf24;
  --red: #fb7185;
  --edge: rgba(122, 160, 255, 0.26);
  --panel-grad: linear-gradient(165deg, #111c3d 0%, #0a1128 60%, #080d20 100%);
  --font-display: "Arial Black", "Segoe UI Black", "Avenir Next Heavy", system-ui, sans-serif;
  --font-body: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button { font-family: inherit; touch-action: manipulation; cursor: pointer; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; }

#game-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none; /* we own every drag gesture */
}

/* ============================ HUD ============================ */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  z-index: 5;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

.hud-logo {
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 0 14px rgba(34, 211, 238, 0.55);
  white-space: nowrap;
}
.hud-logo span { color: var(--cyan); }

.hud-center { flex: 1; max-width: 340px; text-align: center; }
.hud-lines {
  display: inline-flex; align-items: baseline; gap: 9px;
  padding: 6px 16px;
  border: 1px solid rgba(122, 160, 255, 0.22);
  border-radius: 99px;
  background: rgba(13, 20, 44, 0.6);
  font-size: 10px; font-weight: 800;
  letter-spacing: 0.26em;
  color: var(--dim);
}
.hud-lines b {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.5);
}

.hud-right { display: flex; align-items: center; gap: 12px; }
.scores { display: flex; gap: 16px; text-align: right; }
.score-block label {
  display: block;
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--dim);
}
.score-block .val {
  font-family: var(--font-display);
  font-size: 19px;
  color: #fff;
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.35);
}
#hud-score { color: var(--amber); text-shadow: 0 0 12px rgba(251, 191, 36, 0.4); }

.hud-btns { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: rgba(13, 20, 44, 0.78);
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.icon-btn svg { width: 18px; height: 18px; display: block; }
.icon-btn:hover {
  border-color: rgba(34, 211, 238, 0.7);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.25);
  transform: translateY(-1px);
}
.icon-btn:active { transform: scale(0.93); }

/* sound icon on/off states */
#btn-sound .ico-off { display: none; }
#btn-sound:not(.on) .ico-on { display: none; }
#btn-sound:not(.on) .ico-off { display: block; }
#btn-sound:not(.on) { color: var(--dim); }

/* ====================== MOBILE CONTROLS ===================== */
#mobile-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: none;
  justify-content: center;
  gap: 14px;
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  z-index: 6;
}
.m-btn {
  flex: 1; max-width: 230px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 13px 10px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: rgba(13, 20, 44, 0.85);
  color: var(--ink);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.12em;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.m-btn svg { width: 16px; height: 16px; flex: none; }
.m-btn:active { transform: scale(0.95); border-color: rgba(34, 211, 238, 0.7); }

/* ========================= OVERLAYS ========================= */
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: 22px 16px;
  overflow-y: auto;
  z-index: 10;
  background: radial-gradient(120% 120% at 50% 0%, rgba(10, 16, 40, 0.86), rgba(3, 5, 12, 0.94));
}
.screen.active { display: flex; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  position: relative;
  width: min(560px, 94vw);
  margin: auto;
  background: var(--panel-grad);
  border: 1px solid var(--edge);
  border-radius: 18px;
  padding: 30px 32px 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
  animation: panelPop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes panelPop { from { transform: scale(0.9) translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel::before {
  content: "";
  position: absolute; top: -1px; left: 26px; right: 26px; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.85), transparent);
  border-radius: 2px;
}

/* ------------------------ home screen ----------------------- */
.hex-logo { display: flex; gap: 7px; justify-content: center; margin-bottom: 14px; }
.hex-logo .h {
  width: 32px; height: 36px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  animation: floaty 2.6s ease-in-out infinite;
}
.hex-logo .h1 { background: linear-gradient(180deg, #a5f3fc, #0891b2); }
.hex-logo .h2 { background: linear-gradient(180deg, #f5d0fe, #a21caf); width: 40px; height: 45px; animation-delay: 0.25s; }
.hex-logo .h3 { background: linear-gradient(180deg, #fde68a, #b45309); animation-delay: 0.5s; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.game-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(38px, 8vw, 60px);
  line-height: 1;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 0 0 26px rgba(34, 211, 238, 0.4);
}
.game-title em {
  font-style: normal;
  color: var(--cyan);
  text-shadow: 0 0 22px rgba(34, 211, 238, 0.65), 3px 3px 0 rgba(232, 121, 249, 0.35);
}
.tagline {
  margin: 10px 0 0;
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.55em;
  color: var(--dim);
  text-indent: 0.55em;
}

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 18px;
  padding: 8px 16px;
  border: 1px solid var(--edge);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--dim);
  font-size: 12px; font-weight: 700; letter-spacing: 0.1em;
}
.chip b { color: var(--amber); font-family: var(--font-display); letter-spacing: 0.04em; }

.btn-col { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.btn-col .btn { width: 100%; }
.row-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }

.home-hint {
  margin: 20px 0 0;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.06em;
}

/* ========================= BUTTONS ========================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 15px 28px;
  border: none; border-radius: 12px;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.12em;
  color: #03131c;
  background: linear-gradient(180deg, #67e8f9 0%, #0ea5c4 55%, #0b8aa8 100%);
  box-shadow: 0 5px 0 #075e73, 0 12px 26px rgba(34, 211, 238, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #075e73, 0 16px 32px rgba(34, 211, 238, 0.45); filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #075e73, 0 4px 12px rgba(34, 211, 238, 0.3); }

.btn-magenta {
  color: #1c0412;
  background: linear-gradient(180deg, #f9a8d4 0%, #db2777 60%, #be185d 100%);
  box-shadow: 0 5px 0 #831843, 0 12px 26px rgba(232, 121, 249, 0.3);
}
.btn-magenta:hover { box-shadow: 0 7px 0 #831843, 0 16px 32px rgba(232, 121, 249, 0.4); }
.btn-magenta:active { box-shadow: 0 1px 0 #831843; }

.btn-ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  box-shadow: none;
}
.btn-ghost:hover { border-color: rgba(34, 211, 238, 0.6); background: rgba(34, 211, 238, 0.08); box-shadow: 0 0 16px rgba(34, 211, 238, 0.15); }
.btn-ghost:active { transform: translateY(1px); box-shadow: none; }

.btn-danger {
  color: #fff;
  background: linear-gradient(180deg, #fda4af 0%, #e11d48 60%, #be123c 100%);
  box-shadow: 0 5px 0 #881337, 0 12px 26px rgba(251, 113, 133, 0.25);
}
.btn-danger:hover { box-shadow: 0 7px 0 #881337, 0 16px 32px rgba(251, 113, 133, 0.35); }
.btn-danger:active { box-shadow: 0 1px 0 #881337; }
.btn-danger.armed { animation: armPulse 0.6s ease infinite; }
@keyframes armPulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.35); } }

.btn.small { padding: 11px 18px; font-size: 12px; }

/* ======================= HEADINGS / TEXT ==================== */
.panel h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: clamp(24px, 5vw, 34px);
  letter-spacing: 0.14em;
  color: #fff;
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.35);
}
.panel h2.warn { color: var(--red); text-shadow: 0 0 18px rgba(251, 113, 133, 0.45); }
.panel h2.gold { color: var(--amber); text-shadow: 0 0 20px rgba(251, 191, 36, 0.5); }
.sub-note { margin: 0 0 14px; color: var(--dim); font-size: 13.5px; line-height: 1.5; }

/* ======================== HOW TO PLAY ======================= */
.steps { list-style: none; margin: 18px 0 6px; padding: 0; text-align: left; }
.steps li { display: flex; gap: 14px; align-items: flex-start; padding: 8px 0; }
.steps .n {
  flex: none;
  width: 30px; height: 34px;
  display: grid; place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: linear-gradient(180deg, #67e8f9, #0b8aa8);
  font-family: var(--font-display);
  font-size: 14px;
  color: #04121a;
}
.steps b { color: var(--cyan); }
.steps div { font-size: 13.5px; line-height: 1.5; color: #c6d4ef; padding-top: 4px; }

.demo {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 14px 0 4px;
  padding: 12px;
  border: 1px dashed rgba(122, 160, 255, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}
.demo .hx {
  width: 24px; height: 27px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: linear-gradient(180deg, #a5f3fc, #0891b2);
}
.demo .hx.lit { background: linear-gradient(180deg, #fde68a, #d97706); animation: blink 1s ease infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.demo .arrow { font-family: var(--font-display); color: var(--mag); font-size: 18px; }
.demo .demo-note { font-size: 11px; font-weight: 800; letter-spacing: 0.14em; color: var(--dim); }

.keys-hint { margin-top: 14px; font-size: 12px; color: var(--dim); }
kbd {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--edge);
  border-bottom-width: 3px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit; font-size: 11px; font-weight: 700;
  color: var(--ink);
}

/* ====================== SCORE STAT GRIDS ==================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 6px;
}
.stat {
  padding: 12px 6px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}
.stat label {
  display: block;
  font-size: 9px; font-weight: 800; letter-spacing: 0.22em;
  color: var(--dim);
  margin-bottom: 5px;
}
.stat .v { font-family: var(--font-display); font-size: 20px; color: #fff; }
.stat.gold .v { color: var(--amber); }
.stat.cyan .v { color: var(--cyan); }

/* ---------------------- high-score table -------------------- */
.scores-wrap { margin-top: 18px; text-align: left; }
.scores-wrap h3 {
  margin: 0 0 8px;
  font-size: 11px; font-weight: 800; letter-spacing: 0.3em;
  color: var(--dim);
  text-align: center;
}
.score-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid rgba(122, 160, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.score-row .rank {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  font-family: var(--font-display); font-size: 12px;
  color: var(--dim);
}
.score-row .rank.r1 { background: rgba(251, 191, 36, 0.2); color: var(--amber); }
.score-row .rank.r2 { background: rgba(203, 213, 225, 0.18); color: #cbd5e1; }
.score-row .rank.r3 { background: rgba(251, 146, 60, 0.18); color: #fb923c; }
.score-row .sc { font-family: var(--font-display); font-size: 15px; color: #fff; }
.score-row .lv { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; color: var(--dim); }
.score-row.me { border-color: rgba(251, 191, 36, 0.6); background: rgba(251, 191, 36, 0.08); box-shadow: 0 0 14px rgba(251, 191, 36, 0.15); }
.scores-empty { padding: 14px; text-align: center; color: var(--dim); font-size: 12.5px; border: 1px dashed rgba(122, 160, 255, 0.25); border-radius: 10px; }

/* pop-in shared by the game-over record badge */
@keyframes bonusPop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ------------------------- game over ------------------------ */
#go-record {
  display: inline-block;
  margin-bottom: 8px;
  padding: 6px 16px;
  border-radius: 99px;
  background: linear-gradient(180deg, #fde68a, #d97706);
  color: #241303;
  font-family: var(--font-display);
  font-size: 12px; letter-spacing: 0.18em;
  animation: bonusPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 22px rgba(251, 191, 36, 0.5);
}

/* ========================== SETTINGS ======================== */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  text-align: left;
}
.setting-row .lbl b { display: block; font-size: 13.5px; letter-spacing: 0.08em; }
.setting-row .lbl small { color: var(--dim); font-size: 11.5px; }
#sound-state { color: var(--cyan); font-family: var(--font-display); font-size: 13px; letter-spacing: 0.1em; }
#btn-sound-toggle.off #sound-state { color: var(--dim); }

/* ============================ TOAST ========================= */
#toast {
  position: absolute;
  bottom: 92px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  max-width: 86vw;
  padding: 10px 20px;
  border: 1px solid var(--edge);
  border-radius: 99px;
  background: rgba(10, 16, 36, 0.94);
  color: var(--ink);
  font-size: 13px; font-weight: 600; letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 70;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========================= ACCESSIBILITY ==================== */
:focus-visible { outline: 2px solid #7dd3fc; outline-offset: 2px; border-radius: 6px; }

noscript .ns-msg {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  padding: 24px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .hex-logo .h, .demo .hx.lit, #go-record, .btn-danger.armed { animation: none !important; }
}
