:root {
  --bg0: #07061a;
  --bg1: #140e38;
  --ink: #f4efff;
  --muted: #b6acd9;
  --faint: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.14);
  --pink: #ff7ac8;
  --violet: #9d6bff;
  --cyan: #8ff0ff;
  --gold: #ffd98a;
  --card: rgba(22, 16, 56, 0.72);
  --radius: 18px;
  --c: #b877ff;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, #2a1a63 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 100% 100%, #3a1450 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 0% 100%, #0f2a55 0%, transparent 60%),
    var(--bg0);
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }

/* ---------- app shell ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: max(10px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
  max-width: 1280px;
  margin: 0 auto;
}

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  line-height: 1.05;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-right: auto;
}
.brand img { width: 34px; height: 34px; filter: drop-shadow(0 0 8px rgba(184, 119, 255, 0.7)); }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 78px;
  padding: 5px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
}
.stat .lbl { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.next { min-width: 64px; }
.next-slot { display: block; width: 30px; height: 30px; }
.next-slot canvas { display: block; }
.hud-btns { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: rgba(60, 44, 130, 0.8); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.off { opacity: 0.45; }
.icon-btn.off svg { filter: grayscale(1); }

.stage {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 268px;
  gap: 18px;
  min-height: 0;
}
.stage > .board-wrap { grid-column: 2; }
.stage > .side-right { grid-column: 3; }
.side { min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  backdrop-filter: blur(8px);
}
.card h2 {
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.board-wrap {
  min-height: 0; min-width: 0;
  display: flex; align-items: center; justify-content: center;
}
.board {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(157, 107, 255, 0.35),
    0 0 90px rgba(255, 122, 200, 0.15),
    inset 0 0 30px rgba(255, 255, 255, 0.05);
  touch-action: none;
}
.board canvas { display: block; cursor: crosshair; touch-action: none; }
.board::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 18px;
  pointer-events: none;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.10), transparent 22%, transparent 80%, rgba(255, 255, 255, 0.05));
}

.toast {
  position: absolute;
  left: 50%; top: 104px;
  transform: translateX(-50%);
  z-index: 3;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(20, 12, 50, 0.88);
  box-shadow: 0 0 24px var(--c);
  font-size: 13px;
  white-space: nowrap;
  animation: toastIn 0.5s cubic-bezier(.2, 1.4, .4, 1);
}
.toast b { color: #fff; }
.toast .more { color: var(--cyan); font-weight: 600; }
.toast canvas { flex: none; }
.toast.leaving { animation: toastOut 0.4s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -16px) scale(0.9); } }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, -10px); } }

/* ---------- crystal key ---------- */
.key-card { display: flex; flex-direction: column; min-height: 0; flex: 1; padding-bottom: 8px; }
.key-tip { display: block; font-family: var(--body); font-size: 11px; font-weight: 400; letter-spacing: 0.02em; color: var(--muted); margin-top: 2px; }
.key-list { list-style: none; margin: 0 -8px; padding: 0; overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.25) transparent; }
.key-item {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: none;
  text-align: left;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}
.key-item:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--line); }
.key-thumb { flex: none; width: 38px; height: 38px; display: grid; place-items: center; }
.key-name { flex: 1; font-size: 14px; font-weight: 600; line-height: 1.1; }
.key-name small { display: block; font-size: 10px; font-weight: 400; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.key-info {
  flex: none;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-family: Georgia, serif; font-style: italic; font-weight: 700; font-size: 12px;
  color: var(--cyan);
}
.key-item.top { background: linear-gradient(90deg, color-mix(in srgb, var(--c) 30%, transparent), transparent); border-color: color-mix(in srgb, var(--c) 50%, transparent); }
.key-item.reached .key-thumb { filter: drop-shadow(0 0 6px var(--c)); }
.key-item .badge {
  position: absolute; left: 34px; top: 0;
  font-size: 9px; font-weight: 700; letter-spacing: 0.08em;
  padding: 1px 5px; border-radius: 6px;
  background: var(--pink); color: #2a0a24;
  animation: badge 1.2s ease-in-out infinite alternate;
}
@keyframes badge { to { transform: translateY(-2px); box-shadow: 0 0 10px var(--pink); } }

/* ---------- buttons ---------- */
.btn-primary {
  position: relative;
  border: 0;
  padding: 16px 64px;
  border-radius: 999px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #1a0b33;
  background: linear-gradient(100deg, #ffd1f0, #ff9ad8 25%, #c79bff 50%, #8ff0ff 75%, #ffd1f0);
  background-size: 200% 100%;
  box-shadow: 0 0 30px rgba(255, 122, 200, 0.55), 0 0 60px rgba(143, 240, 255, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.7);
  animation: shimmer 5s linear infinite, breathe 2.4s ease-in-out infinite;
  transition: transform 0.15s;
}
.btn-primary:hover { transform: scale(1.05); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary.small { font-size: 17px; padding: 12px 40px; }
@keyframes breathe { 50% { box-shadow: 0 0 44px rgba(255, 122, 200, 0.8), 0 0 90px rgba(143, 240, 255, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.7); } }
@keyframes shimmer { to { background-position: -200% 0; } }

.btn-ghost {
  display: block; width: 100%;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
  transition: background 0.2s;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.link-btn { border: 0; background: none; padding: 4px; color: var(--cyan); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px; font-weight: 600;
  transition: background 0.2s, opacity 0.2s;
}
.chip-btn:hover { background: rgba(255, 255, 255, 0.15); }
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn.off { opacity: 0.5; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.overlay.dim {
  background: rgba(8, 6, 24, 0.62);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.35s;
}
@keyframes fadeIn { from { opacity: 0; } }
.panel-card {
  width: min(360px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 26px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(160deg, rgba(48, 32, 104, 0.95), rgba(18, 12, 44, 0.96));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), 0 0 60px rgba(157, 107, 255, 0.3);
  text-align: center;
  animation: popIn 0.45s cubic-bezier(.2, 1.3, .4, 1);
}
.panel-card h2 { font-family: var(--display); font-size: 30px; letter-spacing: 0.06em; margin-bottom: 6px; }
.panel-card .btn-primary { margin: 6px 0 4px; }
@keyframes popIn { from { opacity: 0; transform: translateY(20px) scale(0.94); } }
.kicker { font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--muted); }
.over-score span, .over-highest > span { display: block; font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.over-score b {
  font-size: 54px; font-weight: 700; line-height: 1.1;
  background: linear-gradient(100deg, #fff, var(--gold), #fff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.over-best { font-size: 14px; color: var(--muted); min-height: 18px; }
.over-best.record { color: var(--gold); font-weight: 700; animation: breathe2 1s ease-in-out infinite alternate; }
@keyframes breathe2 { to { text-shadow: 0 0 12px var(--gold); } }
.over-highest { margin: 6px 0; }
.over-highest div { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; margin-top: 4px; }

/* ---------- splash ---------- */
.splash {
  z-index: 50;
  background:
    radial-gradient(ellipse 70% 50% at 50% 45%, rgba(120, 70, 200, 0.35), transparent 70%),
    linear-gradient(180deg, #06051a 0%, #150f3d 55%, #2c1650 100%);
  overflow: hidden;
  transition: opacity 0.7s, transform 0.7s;
}
.splash.leaving { opacity: 0; transform: scale(1.08); pointer-events: none; }
.splash-cv { position: absolute; inset: 0; width: 100%; height: 100%; }
.splash-inner {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 16px;
  text-align: center;
  max-width: 640px;
}
.splash-inner::before {
  content: '';
  position: absolute;
  inset: -12% -18%;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(10, 6, 30, 0.55), rgba(10, 6, 30, 0.25) 60%, transparent);
  pointer-events: none;
}
.splash .kicker { animation: kickerIn 1.1s 0.1s cubic-bezier(.2, .8, .3, 1) both; color: #d9ccff; text-shadow: 0 0 12px rgba(184, 119, 255, 0.8); }
@keyframes kickerIn { from { opacity: 0; letter-spacing: 1.2em; filter: blur(6px); } }
@keyframes rise { from { opacity: 0; transform: translateY(24px); filter: blur(8px); } }

/* Title: faceted crystal lettering that drops in, converges, and keeps shimmering */
.title {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  font-family: var(--display);
  font-weight: 800;
  line-height: 0.92;
  text-transform: uppercase;
  margin: 2px 0 4px;
}
.title::before {
  content: '';
  position: absolute;
  inset: -35% -20%;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(184, 119, 255, 0.6), rgba(255, 122, 200, 0.28) 45%, rgba(143, 240, 255, 0.08) 65%, transparent 78%);
  filter: blur(22px);
  animation: aura 4.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes aura { 50% { transform: scale(1.15); opacity: 0.7; } }
.title .word {
  position: relative;
  display: block;
  white-space: nowrap;
  filter: drop-shadow(0 0 16px rgba(190, 130, 255, 0.55)) drop-shadow(0 0 40px rgba(255, 122, 200, 0.25));
}
.title .t1 { font-size: clamp(50px, 12.5vw, 124px); letter-spacing: 0.03em; }
.title .t2 { font-size: clamp(27px, 7.6vw, 74px); letter-spacing: 0.07em; margin-top: 0.1em; }

.ch { position: relative; display: inline-block; animation: chDrop 0.8s cubic-bezier(.25, 1.45, .5, 1) both; animation-delay: calc(0.25s + var(--i) * 60ms); }
.t2 .ch { animation: chConverge 0.85s cubic-bezier(.2, .9, .3, 1.15) both; animation-delay: calc(0.75s + var(--i) * 18ms); }
.ch::before {
  content: attr(data-ch);
  position: absolute;
  left: 0; top: 0;
  color: #4a1f96;
  text-shadow:
    0 0.012em 0 #43198a, 0 0.024em 0 #3b167c, 0 0.036em 0 #33136d,
    0 0.048em 0 #2b0f5e, 0 0.06em 0 #230c50,
    0 0.1em 0.18em rgba(8, 0, 30, 0.75);
}
.face {
  position: relative;
  color: transparent;
  background-image:
    linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.95) 49%, rgba(255, 255, 255, 0) 58%),
    linear-gradient(180deg, #ffffff 0%, #f6eeff 26%, #d7ecff 45%, #8ff0ff 47%, #a98bff 70%, #ff7ac8 100%);
  background-size: 300% 100%, 100% 100%;
  background-position: 90% 0, 0 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text; background-clip: text;
  animation: sweep 5.5s ease-in-out infinite;
  animation-delay: calc(2s + var(--i) * 70ms);
}
@keyframes sweep {
  0%, 72% { background-position: 90% 0, 0 0; }
  100% { background-position: 0% 0, 0 0; }
}
@keyframes chDrop {
  0% { opacity: 0; transform: translateY(-140%) scale(0.5) rotate(-12deg); filter: blur(8px); }
  55% { opacity: 1; transform: translateY(5%) scale(1.08, 0.94) rotate(0); filter: blur(0) brightness(2.4); }
  75% { transform: translateY(-4%) scale(0.98, 1.02); filter: brightness(1.4); }
  100% { transform: none; filter: none; }
}
@keyframes chConverge {
  0% { opacity: 0; transform: translateX(var(--dx)) scale(1.7); filter: blur(12px); }
  70% { opacity: 1; filter: blur(0) brightness(2); }
  100% { transform: none; filter: none; }
}
.t2::before, .t2::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  pointer-events: none;
  z-index: -1;
}
.t2::after {
  width: 1.6em; height: 1.6em;
  margin: -0.8em 0 0 -0.8em;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(255, 210, 245, 0.9) 18%, rgba(184, 119, 255, 0.5) 42%, transparent 70%);
  animation: burst 1.1s 1.35s ease-out both;
}
.t2::before {
  width: 120%; height: 3px;
  margin: -1.5px 0 0 -60%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.95) 45%, #fff 50%, rgba(255, 255, 255, 0.95) 55%, transparent);
  animation: flare 1.3s 1.35s ease-out both;
}
@keyframes burst {
  0% { opacity: 0; transform: scale(0.2); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: scale(4.5); }
}
@keyframes flare {
  0% { opacity: 0; transform: scaleX(0); }
  30% { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(1.3); }
}

.spark {
  position: absolute;
  width: var(--s); height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  background: radial-gradient(circle, #fff 0%, #fff 12%, var(--hue) 40%, transparent 72%);
  clip-path: polygon(50% 0, 56% 44%, 100% 50%, 56% 56%, 50% 100%, 44% 56%, 0 50%, 44% 44%);
  mix-blend-mode: screen;
  pointer-events: none;
  animation: twinkle 1.1s ease-in-out forwards;
}
@keyframes twinkle {
  0% { opacity: 0; transform: scale(0) rotate(0); }
  45% { opacity: 1; transform: scale(1) rotate(45deg); }
  100% { opacity: 0; transform: scale(0) rotate(90deg); }
}

.tag { margin: 0; font-size: clamp(15px, 2.4vw, 19px); color: #e6ddff; text-shadow: 0 2px 10px rgba(10, 5, 30, 0.8); animation: rise 0.9s 1.45s both; }
.splash .btn-primary { margin-top: 14px; animation: shimmer 5s linear infinite, breathe 2.4s ease-in-out infinite, rise 0.9s 1.6s both; }

/* ---------- codex ---------- */
.modal {
  position: fixed; inset: 0;
  z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(6, 4, 20, 0.7); backdrop-filter: blur(8px); animation: fadeIn 0.3s; }
.codex-card {
  position: relative;
  width: min(780px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border-radius: 26px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, rgba(255, 255, 255, 0.2));
  background:
    radial-gradient(ellipse 70% 40% at 20% 0%, color-mix(in srgb, var(--c) 35%, transparent), transparent 70%),
    linear-gradient(170deg, rgba(38, 26, 88, 0.98), rgba(14, 10, 36, 0.98));
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6), 0 0 80px color-mix(in srgb, var(--c) 35%, transparent);
  padding: 26px 28px 18px;
  animation: popIn 0.45s cubic-bezier(.2, 1.2, .4, 1);
  scrollbar-width: thin;
  user-select: text;
  -webkit-user-select: text;
}
.codex-card.swap { animation: swapIn 0.4s cubic-bezier(.2, 1.1, .4, 1); }
@keyframes swapIn { from { opacity: 0.2; transform: translateX(var(--dir, 20px)); } }
.modal-close { position: absolute; top: 14px; right: 14px; z-index: 2; }
.cx-hero { display: grid; grid-template-columns: 210px 1fr; gap: 22px; align-items: center; }
.cx-gem-wrap {
  width: 210px; height: 210px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--c) 30%, transparent), transparent 70%);
  display: grid; place-items: center;
}
.cx-gem { width: 210px; height: 210px; }
.cx-tier { font-size: 12px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--muted); }
.cx-title h2 {
  font-family: var(--display);
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.05;
  margin: 4px 0 8px;
  background: linear-gradient(100deg, #fff 20%, color-mix(in srgb, var(--c) 70%, #fff));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.cx-tagline { margin: 0 0 14px; font-size: 17px; font-style: italic; color: #e6ddff; }
.cx-body { margin-top: 20px; display: flex; flex-direction: column; gap: 18px; }
.cx-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.fact {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}
.fact span { display: block; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.fact b { display: block; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.mohs { display: flex; gap: 3px; margin-top: 6px; }
.mohs i { flex: 1; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); }
.mohs i.on { background: linear-gradient(90deg, color-mix(in srgb, var(--c) 60%, #fff), var(--c)); box-shadow: 0 0 6px var(--c); }
.cx-sec h3 {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.cx-sec h3 svg { width: 18px; height: 18px; color: var(--c); }
.cx-sec p { margin: 0; line-height: 1.6; color: #e4dcff; font-size: 15px; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }
.chips li { padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); font-size: 13px; }
.chips li.nc { border-color: color-mix(in srgb, var(--c) 70%, transparent); background: color-mix(in srgb, var(--c) 18%, transparent); font-weight: 600; }
.cx-wnc {
  padding: 14px 16px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, transparent 55%, rgba(80, 70, 160, 0.25)),
    rgba(255, 255, 255, 0.04);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}
.cx-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cx-photos figure { margin: 0; }
.cx-photos button {
  display: block; width: 100%;
  padding: 0; border: 0;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.cx-photos img { display: block; width: 100%; height: 210px; object-fit: cover; transition: transform 0.5s; }
.cx-photos button:hover img { transform: scale(1.05); }
.cx-photos figcaption { margin-top: 7px; font-size: 13px; line-height: 1.35; color: #e4dcff; }
.credit { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.credit a { color: var(--muted); }
.cx-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.cx-dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.cx-dots button { width: 10px; height: 10px; padding: 0; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.25); transition: transform 0.2s, background 0.2s; }
.cx-dots button.on { background: var(--c); transform: scale(1.4); box-shadow: 0 0 8px var(--c); }

.lightbox {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(4, 2, 12, 0.92);
  animation: fadeIn 0.25s;
}
.lightbox figure { margin: 0; text-align: center; }
.lightbox img { max-width: 92vw; max-height: 80vh; border-radius: 12px; box-shadow: 0 20px 80px rgba(0, 0, 0, 0.7); }
.lightbox figcaption { margin-top: 10px; font-size: 14px; color: #ddd; }

.credits-card h2 { font-family: var(--display); font-size: 28px; margin-bottom: 10px; }
.credits-card h3 { font-family: var(--display); font-size: 16px; margin: 18px 0 6px; letter-spacing: 0.06em; }
.credits-card p { line-height: 1.55; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: 14px; }
.credit-list { list-style: none; padding: 0; margin: 0; font-size: 13px; line-height: 1.5; }
.credit-list li { padding: 6px 0; border-bottom: 1px solid var(--faint); }
.credit-list a { color: var(--cyan); }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .stage { grid-template-columns: minmax(0, 1fr) 250px; }
  .stage > .board-wrap { grid-column: 1; }
  .stage > .side-right { grid-column: 2; }
}
@media (max-width: 760px) {
  .app { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .brand span { display: none; }
  .brand { margin-right: auto; }
  .brand img { width: 30px; height: 30px; }
  .hud { gap: 6px; }
  .stat { min-width: 0; padding: 3px 9px; }
  .stat b { font-size: 17px; }
  .icon-btn { width: 36px; height: 36px; }
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 8px; }
  .stage > .board-wrap, .stage > .side-right { grid-column: 1; }
  .side-right { min-height: 0; }
  .key-card { padding: 8px 10px 6px; }
  .key-card h2 { font-size: 12px; margin-bottom: 4px; display: flex; align-items: baseline; gap: 8px; }
  .key-tip { margin: 0; }
  .key-list { display: flex; overflow-x: auto; overflow-y: hidden; margin: 0 -4px; gap: 2px; }
  .key-list li { flex: none; }
  .key-item { flex-direction: column; gap: 2px; padding: 4px 6px; width: 70px; text-align: center; }
  .key-name { font-size: 10px; font-weight: 600; }
  .key-name small { font-size: 8px; }
  .key-info { display: none; }
  .key-item .badge { left: 44px; }
  .cx-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 6px; }
  .cx-gem-wrap, .cx-gem { width: 170px; height: 170px; }
  .codex-card { padding: 20px 16px 14px; }
  .cx-photos { grid-template-columns: 1fr; }
  .cx-photos img { height: 190px; }
  .toast { top: 100px; font-size: 12px; }
}
@media (max-height: 560px) and (min-width: 761px) {
  .splash-inner { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ---------- optimization pass: focus, touch targets, phones held sideways ---------- */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.cx-dots button { position: relative; }
.cx-dots button::after { content: ''; position: absolute; inset: -8px -3px; }

@media (max-width: 760px) {
  .hud { gap: 5px; }
  .stat { padding: 3px 7px; }
  .hud-btns { gap: 4px; }
  .icon-btn { width: 44px; height: 44px; }
}
@media (max-width: 370px) {
  .brand img { display: none; }
}

/* Phones held sideways: the HUD moves into the side column so the board gets the full height. */
@media (orientation: landscape) and (max-height: 500px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 250px;
    grid-template-rows: auto minmax(0, 1fr);
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    column-gap: 14px; row-gap: 8px;
  }
  .stage { display: contents; }
  .stage > .board-wrap { grid-column: 1; grid-row: 1 / 3; }
  .hud { grid-column: 2; grid-row: 1; flex-wrap: wrap; justify-content: space-between; gap: 6px; }
  .brand { display: none; }
  .stat { min-width: 0; flex: 1; padding: 2px 6px; }
  .stat b { font-size: 16px; }
  .hud-btns { width: 100%; justify-content: space-between; }
  .icon-btn { width: 44px; height: 44px; flex: 1; }
  .stage > .side-right { grid-column: 2; grid-row: 2; }
  .key-card { padding: 8px 10px 6px; }
  .key-card h2 { font-size: 12px; margin-bottom: 4px; }
  .key-tip { display: none; }
  .key-list { display: block; overflow-x: hidden; overflow-y: auto; margin: 0 -6px; }
  .key-item { flex-direction: row; gap: 8px; width: 100%; padding: 3px 6px; text-align: left; }
  .key-name { font-size: 13px; }
  .key-name small { font-size: 9px; }
  .key-item .badge { left: 30px; }
  .toast { top: 70px; font-size: 12px; }
}
@media (pointer: coarse) {
  .icon-btn { min-width: 44px; min-height: 44px; }
}
/* short screens: pause / game over cards stay fully on screen (scroll if still too tall) */
.overlay.dim { overflow-y: auto; }
.overlay.dim .panel-card { margin: auto; }
@media (max-height: 560px) {
  .overlay.dim { padding: 10px; }
  .panel-card { padding: 14px 22px; gap: 6px; }
  .panel-card h2 { font-size: 22px; margin-bottom: 2px; }
  .panel-card .btn-primary { margin: 2px 0; }
  .btn-ghost { padding: 9px 18px; }
  .over-score b { font-size: 36px; }
  .over-highest { margin: 2px 0; }
  .over-card .kicker { display: none; }
}
