/* Clash of 2048 - interface. Direction: gilded royal fantasy. Deep indigo enamel panels,
   hammered-gold rims, chunky pressable buttons, Cinzel display over Inter text.
   Motion rule: animate transform / translate / scale / opacity only (compositor-friendly). */

:root {
  --ink: #0a0d1f;
  --ink-2: #141a3a;
  --panel-top: #26306a;
  --panel-bottom: #121838;
  --panel-edge: #0a0e24;
  --gold-1: #fff2b8;
  --gold-2: #f4c55a;
  --gold-3: #c88a2a;
  --gold-4: #7a4c12;
  --cream: #fff6e0;
  --muted: #c3c9ec;
  --emerald: #2fd36b;
  --emerald-deep: #0f7a3a;
  --elixir: #e83ad0;
  --elixir-deep: #7d0f75;
  --ruby: #ea3a3f;
  --ruby-deep: #8c0f1e;
  --sky: #4a8cf0;
  --sky-deep: #1c4aa8;
  --violet: #9b5cf0;
  --focus: #fff2b8;

  --font-display: 'Cinzel', 'Cinzel Decorative', Georgia, serif;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 24px;
  --gutter: clamp(10px, 2.2vw, 22px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --edge-top: calc(var(--gutter) + var(--safe-top));
  --edge-bottom: calc(var(--gutter) + var(--safe-bottom));
  --edge-left: calc(var(--gutter) + var(--safe-left));
  --edge-right: calc(var(--gutter) + var(--safe-right));

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-spring-soft: cubic-bezier(0.22, 1.3, 0.36, 1);
  --t-fast: 140ms;
  --t-med: 280ms;

  --gold-rim: linear-gradient(180deg, var(--gold-1), var(--gold-2) 35%, var(--gold-3) 70%, var(--gold-1));
  --panel-face: linear-gradient(180deg, var(--panel-top), var(--panel-bottom));
}

/* ---------- base + touch hygiene ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b1230;
  overscroll-behavior: none;             /* no pull-to-refresh / rubber-band */
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
body {
  font-family: var(--font-ui);
  color: var(--cream);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;           /* no long-press callout on iOS */
  touch-action: none;                    /* the game surface owns every gesture */
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; touch-action: manipulation; }   /* no double-tap zoom */
img, svg { -webkit-user-drag: none; }
.icon { width: 1.25em; height: 1.25em; flex: none; display: inline-block; vertical-align: -0.25em; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.35)); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* keyboard focus: one consistent gold ring, never shown for pointer clicks */
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.modal:focus-visible { outline: none; }

#canvas-container { position: fixed; inset: 0; touch-action: none; }
#canvas-container canvas { display: block; touch-action: none; }

.layer { position: fixed; inset: 0; pointer-events: none; }
.layer > * { pointer-events: auto; }
#ui > .layer { pointer-events: none; }   /* screens are click-through; only their controls take input */
.layer.leaving, .layer.leaving * { pointer-events: none !important; }
.hidden { display: none !important; }

/* ---------- typography ---------- */
.display {
  font-family: var(--font-display);
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fffbe8 10%, var(--gold-2) 55%, var(--gold-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 var(--gold-4)) drop-shadow(0 6px 10px rgba(0,0,0,0.5));
}
.eyebrow { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; font-weight: 900; }

/* ---------- panels ---------- */
.panel {
  position: relative;
  background: var(--panel-face);
  border-radius: var(--radius-m);
  box-shadow:
    0 0 0 2px var(--panel-edge),
    0 0 0 4px var(--gold-3),
    0 0 0 5px var(--gold-4),
    inset 0 2px 0 rgba(255,255,255,0.14),
    inset 0 -3px 0 rgba(0,0,0,0.35),
    0 14px 30px rgba(0,0,0,0.45);
}
.panel::before {        /* enamel sheen */
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 70% at 50% -10%, rgba(255,255,255,0.16), transparent 60%);
  pointer-events: none;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px 4px 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(10,13,31,0.9), rgba(20,26,58,0.9));
  box-shadow: 0 0 0 2px rgba(244,197,90,0.55), inset 0 1px 0 rgba(255,255,255,0.12);
  font-weight: 900;
  white-space: nowrap;
}

/* ---------- buttons ---------- */
.btn {
  --face-top: #6aa8ff; --face-bottom: #2f63d8; --lip: #163a8c; --glow: rgba(106,168,255,0.45);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px;
  padding: 10px 20px;
  border: 0;
  border-radius: 14px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
  cursor: pointer;
  background: linear-gradient(180deg, var(--face-top), var(--face-bottom));
  box-shadow: 0 0 0 2px var(--panel-edge), inset 0 2px 0 rgba(255,255,255,0.45), inset 0 -2px 0 rgba(0,0,0,0.2), 0 5px 0 var(--lip), 0 8px 14px rgba(0,0,0,0.4);
  transform: translateY(0);
  transition: transform 220ms var(--ease-spring), box-shadow var(--t-fast) var(--ease-out), filter var(--t-fast);
}
.btn::after {         /* glossy highlight band */
  content: ''; position: absolute; left: 6px; right: 6px; top: 4px; height: 40%;
  border-radius: 10px 10px 30px 30px / 10px 10px 14px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.38), rgba(255,255,255,0));
  pointer-events: none;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { filter: brightness(1.1) saturate(1.06); transform: translateY(-1px); }
}
.btn:active:not(:disabled), .btn.is-pressed {
  transform: translateY(4px) scale(0.97);
  transition-duration: 60ms;
  box-shadow: 0 0 0 2px var(--panel-edge), inset 0 2px 0 rgba(255,255,255,0.35), 0 1px 0 var(--lip), 0 3px 6px rgba(0,0,0,0.4);
}
.btn:disabled { filter: grayscale(0.85) brightness(0.7); cursor: not-allowed; }
.btn-gold  { --face-top: #ffe27a; --face-bottom: #f0a92a; --lip: #9a5c0e; color: #3a1f02; text-shadow: 0 1px 0 rgba(255,255,255,0.45); }
.btn-green { --face-top: #7cf09a; --face-bottom: #20b356; --lip: #0d6a30; color: #04230f; text-shadow: 0 1px 0 rgba(255,255,255,0.35); }
.btn-red   { --face-top: #ff8a7a; --face-bottom: #d42a33; --lip: #82101c; }
.btn-violet{ --face-top: #c99bff; --face-bottom: #7a3fe0; --lip: #3f1a8a; }
.btn-dark  { --face-top: #3a4478; --face-bottom: #20284e; --lip: #0c1030; }
.btn-xl { min-height: 64px; padding: 12px 34px; font-size: 1.35rem; border-radius: 18px; font-family: var(--font-display); }
.btn-round { width: 52px; height: 52px; min-height: 0; padding: 0; border-radius: 50%; }
.btn-round .icon { width: 28px; height: 28px; }
.btn-sm { min-height: 40px; padding: 6px 14px; font-size: 0.85rem; border-radius: 11px; }
.badge-dot {
  position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: linear-gradient(180deg, #ff6a5a, var(--ruby-deep));
  box-shadow: 0 0 0 2px var(--panel-edge); font-size: 0.75rem; font-weight: 900; line-height: 22px; text-align: center;
  animation: badge-bob 1.6s var(--ease-out) infinite;
}
@keyframes badge-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -3px; } }

/* ---------- loading (compositor-only motion: keeps moving while the main thread boots) ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50; overflow: hidden;
  display: grid; place-items: center;
  background:
    radial-gradient(60% 50% at 50% 40%, rgba(244,197,90,0.2), transparent 70%),
    radial-gradient(120% 80% at 50% 120%, #2b3c8a, transparent 60%),
    linear-gradient(180deg, #0b1230, #060818);
  transition: opacity 650ms var(--ease-out);
  touch-action: none;
}
#loading::before {      /* slow-turning sunburst behind the crest */
  content: ''; position: absolute; left: 50%; top: 42%; width: 110vmax; height: 110vmax; margin: -55vmax 0 0 -55vmax;
  background: repeating-conic-gradient(from 0deg, rgba(255,226,122,0.07) 0 6deg, transparent 6deg 15deg);
  -webkit-mask-image: radial-gradient(circle, #000 10%, transparent 60%); mask-image: radial-gradient(circle, #000 10%, transparent 60%);
  animation: spin 60s linear infinite;
  will-change: transform;
  pointer-events: none;
}
#loading.done { opacity: 0; pointer-events: none; }
#loading.done::before, #loading.done * { animation-play-state: paused; }   /* stop ticking once faded */
#loading .loading-inner { position: relative; transition: transform 650ms var(--ease-out); }
#loading.done .loading-inner { transform: scale(1.06); }
.loading-inner { display: grid; justify-items: center; gap: 18px; padding: 0 16px; text-align: center; }
#loading .crest { position: relative; animation: crest-float 3.6s ease-in-out infinite; will-change: transform; }
#loading .crest::before {     /* breathing gold halo */
  content: ''; position: absolute; inset: -18% -22%; z-index: -1; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255,214,110,0.42), rgba(255,180,60,0.12) 55%, transparent);
  animation: halo 2.8s ease-in-out infinite;
  will-change: opacity, transform;
}
@keyframes crest-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes halo { 0%, 100% { opacity: 0.55; transform: scale(0.94); } 50% { opacity: 1; transform: scale(1.04); } }
.crest {
  font-family: var(--font-display); font-weight: 900; line-height: 0.92;
  display: grid; justify-items: center;
}
.crest .crest-top { font-size: clamp(2.4rem, 9vw, 5.2rem); }
.crest .crest-num { font-size: clamp(3.6rem, 14vw, 8rem); margin-top: -0.12em; }
.crest .crest-sub {
  margin-top: 10px; padding: 6px 18px; border-radius: 6px; white-space: nowrap;
  font-family: var(--font-ui); font-size: clamp(0.6rem, 2vw, 0.85rem); font-weight: 900; letter-spacing: clamp(0.14em, 0.8vw, 0.32em);
  background: linear-gradient(180deg, #c8282e, #7a0d16); box-shadow: 0 0 0 2px var(--gold-3), 0 6px 14px rgba(0,0,0,0.4);
}
.loading-bar {
  position: relative; width: min(380px, 78vw); height: 18px; border-radius: 999px; background: #060818;
  box-shadow: 0 0 0 2px var(--gold-3), 0 0 0 4px rgba(10,14,36,0.9), inset 0 2px 6px rgba(0,0,0,0.8), 0 0 28px rgba(244,197,90,0.25);
  overflow: hidden;
}
.loading-bar > i {
  position: relative; display: block; height: 100%; width: 0; min-width: 18px; overflow: hidden; border-radius: inherit;
  background: linear-gradient(180deg, #fff0a8, #f6c242 45%, #d9871c);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 0 14px rgba(255,200,80,0.7);
  transition: width 420ms var(--ease-out);
}
.loading-bar > i::after {     /* light sweep */
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 60%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,0.75) 50%, transparent);
  transform: translateX(-120%);
  animation: shimmer 1.5s var(--ease-out) infinite;
  will-change: transform;
}
@keyframes shimmer { 0% { transform: translateX(-120%); } 70%, 100% { transform: translateX(260%); } }
.loading-tip { color: var(--muted); font-size: 0.9rem; max-width: 420px; text-wrap: balance; min-height: 2.6em; line-height: 1.35; animation: tip-in 600ms var(--ease-out) both 200ms; }
@keyframes tip-in { from { opacity: 0; transform: translateY(6px); } }

.loading-error { max-width: 420px; margin: 0; padding: 12px 16px; border-radius: 12px; line-height: 1.45; font-weight: 700; color: var(--cream); background: rgba(140,15,30,0.55); box-shadow: 0 0 0 2px rgba(234,58,63,0.7); animation: tip-in 400ms var(--ease-out) both; }
#loading.failed .crest { animation: none; }
#loading.failed .crest::before { animation: none; opacity: 0.35; }
#loading.failed .btn { pointer-events: auto; min-width: 160px; }

/* ---------- top bar (menu + game) ---------- */
.topbar {
  position: absolute; top: var(--edge-top); left: var(--edge-left); right: var(--edge-right);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end;
}
.level-badge {
  margin-right: auto; display: flex; align-items: center; gap: 10px; padding: 6px 16px 6px 6px; min-width: 0;
}
.level-badge .lvl {
  width: 46px; height: 46px; display: grid; place-items: center; flex: none;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--gold-rim); color: #3a1f02; font-weight: 900; font-size: 1.15rem;
}
.level-badge .xp { width: 120px; height: 10px; border-radius: 999px; background: #060818; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.8); }
.level-badge .xp > i { display: block; height: 100%; background: linear-gradient(90deg, #6bd0ff, #4a8cf0); transition: width 800ms var(--ease-out); }
.level-badge .name { font-weight: 900; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; display: block; }
.currency { position: relative; min-width: 108px; justify-content: flex-start; font-size: 1.02rem; }
.currency .icon { width: 30px; height: 30px; margin-left: -10px; }
.currency.flash { animation: currency-flash 600ms var(--ease-spring); }
@keyframes currency-flash { 0% { scale: 1; } 30% { scale: 1.16; } 100% { scale: 1; } }

/* ---------- main menu ---------- */
#menu .logo {
  position: absolute; left: 50%; top: calc(14px + var(--safe-top)); transform: translateX(-50%);
  pointer-events: none; text-align: center;
  animation: logo-in 900ms var(--ease-spring-soft) both;
}
#menu .logo .crest-top { font-size: clamp(1.6rem, 4.2vw, 2.7rem); }
#menu .logo .crest-num { font-size: clamp(2.4rem, 6.5vw, 4.1rem); }
#menu .logo .crest-sub { font-size: clamp(0.55rem, 1.4vw, 0.72rem); margin-top: 6px; }
@keyframes logo-in { from { opacity: 0; translate: 0 -30px; scale: 0.85; } }
.side-rail {
  position: absolute; left: var(--edge-left); top: 50%; transform: translateY(-50%);
  display: grid; gap: 12px; pointer-events: none;
}
.side-rail > * { pointer-events: auto; }
.rail-btn { flex-direction: column; gap: 2px; width: 72px; height: 72px; padding: 6px; border-radius: 18px; font-size: 0.68rem; letter-spacing: 0.04em; }
.rail-btn .icon { width: 34px; height: 34px; }
.mode-dock {
  position: absolute; left: 50%; bottom: var(--edge-bottom); transform: translateX(-50%);
  width: min(980px, calc(100vw - 2 * var(--gutter) - 2 * 96px));   /* never under the side rail */
  display: grid; gap: 14px; justify-items: center; pointer-events: none;
}
.mode-dock > * { pointer-events: auto; }
.mode-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; width: 100%; }
.mode-card {
  position: relative; text-align: left; cursor: pointer; border: 0; padding: 14px 14px 12px; min-height: 108px;
  color: var(--cream); display: grid; align-content: end; gap: 2px; overflow: hidden; font: inherit;
  transition: transform var(--t-med) var(--ease-spring), box-shadow var(--t-med);
}
.mode-card .art { position: absolute; right: -8px; top: -8px; width: 76px; height: 76px; opacity: 0.95; transform: rotate(-8deg); transition: transform var(--t-med) var(--ease-spring); }
.mode-card .art .icon { width: 100%; height: 100%; }
.mode-card .title { font-family: var(--font-display); font-weight: 900; font-size: 1.05rem; padding-right: 40px; }
.mode-card .desc { font-size: 0.78rem; color: var(--muted); padding-right: 54px; line-height: 1.3; }
.mode-card .best { font-size: 0.72rem; font-weight: 800; color: var(--gold-2); }
@media (hover: hover) and (pointer: fine) {
  .mode-card:hover { transform: translateY(-4px); }
  .mode-card:hover .art { transform: rotate(0deg) scale(1.08); }
}
.mode-card:active { transform: translateY(-2px) scale(0.98); transition-duration: 80ms; }
.mode-card.selected { box-shadow: 0 0 0 2px var(--panel-edge), 0 0 0 4px var(--gold-1), 0 0 0 6px var(--gold-3), 0 0 26px rgba(244,197,90,0.55), 0 14px 30px rgba(0,0,0,0.45); transform: translateY(-6px); }
.mode-card.selected .art { transform: rotate(0deg) scale(1.06); }
.mode-card.classic { --panel-top: #2f5aa8; --panel-bottom: #172a5c; }
.mode-card.defense { --panel-top: #8a2a36; --panel-bottom: #3a0e18; }
.mode-card.rush    { --panel-top: #a8681c; --panel-bottom: #4a2608; }
.mode-card.daily   { --panel-top: #5a2fa8; --panel-bottom: #241046; }
.mode-card .ribbon { position: absolute; left: 12px; top: 0; font-size: 0.58rem; font-weight: 900; letter-spacing: 0.14em; line-height: 1; padding: 4px 8px 4px; border-radius: 0 0 6px 6px; background: linear-gradient(180deg, #ff5a5f, var(--ruby-deep)); box-shadow: 0 2px 0 rgba(0,0,0,0.35); }
.play-row { display: flex; gap: 12px; align-items: center; }
.play-btn { min-width: 260px; }
.play-btn .icon { width: 34px; height: 34px; }
.play-btn { overflow: hidden; }   /* clips the glint; the lip is a box-shadow so it still shows */
.play-btn::before {     /* idle call-to-action glint (transform only) */
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; pointer-events: none;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,0.6) 50%, transparent);
  transform: translateX(-130%) skewX(-12deg);
  animation: cta-glint 4.8s var(--ease-out) 1.6s infinite;
}
@keyframes cta-glint { 0% { transform: translateX(-130%) skewX(-12deg); } 22%, 100% { transform: translateX(330%) skewX(-12deg); } }

/* screen enter / leave choreography (translate/scale props compose with layout transforms) */
#menu:not(.leaving) > .topbar { animation: drop-in 520ms var(--ease-out) both; }
#menu:not(.leaving) > .side-rail { animation: slide-right 560ms var(--ease-out) 80ms both; }
#menu:not(.leaving) .mode-card { animation: rise-in 560ms var(--ease-spring-soft) calc(120ms + var(--i, 0) * 55ms) both; }
#menu:not(.leaving) .play-row { animation: rise-in 560ms var(--ease-spring-soft) 360ms both; }
#menu.leaving > .topbar { animation: lift-out 220ms var(--ease-in) both; }
#menu.leaving > .side-rail { animation: slide-left-out 220ms var(--ease-in) both; }
#menu.leaving > .logo, #menu.leaving > .mode-dock { animation: sink-out 220ms var(--ease-in) both; }
#hud:not(.leaving) > .topbar { animation: drop-in 480ms var(--ease-out) both; }
#hud:not(.leaving) > .next-unit { animation: pop-in 520ms var(--ease-spring) 160ms both; }
#hud:not(.leaving) > .dock, #hud:not(.leaving) > .hud-right { animation: rise-in 520ms var(--ease-spring-soft) 120ms both; }
#hud.leaving > * { animation: fade-out 220ms var(--ease-in) both; }
@keyframes drop-in { from { opacity: 0; translate: 0 -24px; } }
@keyframes rise-in { from { opacity: 0; translate: 0 28px; scale: 0.96; } }
@keyframes slide-right { from { opacity: 0; translate: -36px 0; } }
@keyframes pop-in { from { opacity: 0; scale: 0.6; } }
@keyframes lift-out { to { opacity: 0; translate: 0 -18px; } }
@keyframes sink-out { to { opacity: 0; translate: 0 22px; } }
@keyframes slide-left-out { to { opacity: 0; translate: -28px 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* ---------- in-game HUD ---------- */
#hud .score-cluster { display: flex; gap: 10px; align-items: stretch; margin-right: auto; min-width: 0; }
.stat { padding: 8px 16px 9px; min-width: 112px; display: grid; gap: 1px; }
.stat .value { font-size: 1.55rem; line-height: 1.05; display: inline-block; transform-origin: left center; }
.stat.score .value { font-size: 1.85rem; }
.stat.pop .value { animation: stat-pop 380ms var(--ease-spring); }
@keyframes stat-pop { 40% { transform: scale(1.18); } }
.stat.best.record { box-shadow: 0 0 0 2px var(--panel-edge), 0 0 0 4px var(--gold-1), 0 0 0 5px var(--gold-3), 0 0 22px rgba(255,214,110,0.75), 0 14px 30px rgba(0,0,0,0.45); }
.stat.best.record .eyebrow { color: var(--gold-1); }
.score-gain {
  position: absolute; right: 10px; top: -4px; font-size: 1rem; color: #9dffb8; pointer-events: none;
  text-shadow: 0 2px 0 #06301a, 0 0 10px rgba(47,211,107,0.6);
  animation: gain-float 900ms var(--ease-out) both;
}
@keyframes gain-float { 0% { opacity: 0; transform: translateY(8px) scale(0.6); } 20% { opacity: 1; transform: translateY(0) scale(1.1); } 100% { opacity: 0; transform: translateY(-22px) scale(1); } }
.combo {
  align-self: center; display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 12px; font-family: var(--font-display); font-weight: 900; font-size: 1.15rem; white-space: nowrap;
  background: linear-gradient(180deg, #ffb347, #e8461c); box-shadow: 0 0 0 2px var(--panel-edge), 0 0 18px rgba(255,120,40,0.7);
  text-shadow: 0 2px 0 rgba(90,20,0,0.6);
  transform-origin: center;
  opacity: 0; transform: scale(0.4) rotate(-12deg); visibility: hidden;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-in), visibility 0s linear 200ms;
}
.combo.on { opacity: 1; transform: none; visibility: visible; transition: opacity 160ms var(--ease-out), transform 420ms var(--ease-spring), visibility 0s; }
.combo.bump { animation: combo-bump 420ms var(--ease-spring); }
@keyframes combo-bump { 0% { scale: 1; } 35% { scale: 1.3; rotate: 4deg; } 100% { scale: 1; rotate: 0deg; } }
@keyframes combo-pop { 0% { transform: scale(0.4) rotate(-12deg); } 60% { transform: scale(1.25) rotate(4deg); } 100% { transform: scale(1); } }
.mode-info { display: flex; gap: 8px; align-items: center; min-width: 0; }
.mode-info .chip { min-height: 36px; }
.mode-info .chip.wave-on { box-shadow: 0 0 0 2px rgba(234,58,63,0.85), 0 0 14px rgba(234,58,63,0.45), inset 0 1px 0 rgba(255,255,255,0.12); }
.hearts { display: flex; gap: 2px; }
.hearts .icon { width: 26px; height: 26px; }
.hearts .lost { filter: grayscale(1) brightness(0.4); }
.timer-chip { font-size: 1.2rem; min-width: 100px; position: relative; isolation: isolate; }
.timer-chip.urgent::before { content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: linear-gradient(180deg, #e0323a, #82101c); animation: urgent 1s ease-in-out infinite; }
.timer-chip.urgent { animation: urgent-beat 1s var(--ease-out) infinite; }
@keyframes urgent { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@keyframes urgent-beat { 0%, 100% { scale: 1; } 12% { scale: 1.08; } }
.next-unit { position: absolute; right: var(--edge-right); top: calc(96px + var(--safe-top)); padding: 8px 12px; display: grid; justify-items: center; gap: 4px; }
.next-unit .tile-chip { width: 54px; height: 54px; border-radius: 12px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 900; font-size: 1.3rem; text-shadow: 0 2px 0 rgba(0,0,0,0.5); box-shadow: 0 0 0 2px var(--gold-3), inset 0 2px 0 rgba(255,255,255,0.3), 0 4px 10px rgba(0,0,0,0.4); }
.next-unit .tile-chip.pop { animation: next-pop 360ms var(--ease-spring); }
@keyframes next-pop { 0% { transform: scale(0.6) rotate(-8deg); opacity: 0.4; } 100% { transform: none; opacity: 1; } }

.dock {
  position: absolute; left: 50%; bottom: var(--edge-bottom); transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: 12px; padding: 10px 14px 12px;
}
.elixir-meter { display: grid; gap: 4px; min-width: 150px; }
.elixir-meter .bar { position: relative; height: 18px; border-radius: 999px; background: #1a0618; box-shadow: inset 0 2px 5px rgba(0,0,0,0.85), 0 0 0 2px var(--elixir-deep); overflow: hidden; }
.elixir-meter .bar > i { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: linear-gradient(180deg, #ff9af0, var(--elixir) 55%, var(--elixir-deep)); box-shadow: 0 0 12px rgba(232,58,208,0.8); transition: width 450ms var(--ease-out); }
.elixir-meter .bar > b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.75rem; font-weight: 900; text-shadow: 0 1px 2px #000, 0 0 4px #000; }
.elixir-meter .ticks { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(0,0,0,0.45) calc(10% - 1px) 10%); }
.spell { position: relative; width: 68px; height: 68px; border-radius: 18px; flex-direction: column; gap: 0; padding: 4px; font-size: 0.62rem; }
.spell .icon { width: 34px; height: 34px; }
.spell .cost { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 1px 8px 1px 4px; border-radius: 999px; background: #1a0618; color: #fff; text-shadow: none; box-shadow: 0 0 0 2px var(--elixir-deep); font-size: 0.75rem; }
.spell .cost .icon { width: 16px; height: 16px; }
.spell:disabled .cost { filter: none; }
.spell.active { box-shadow: 0 0 0 2px var(--panel-edge), 0 0 0 4px #fff, 0 0 22px rgba(255,255,255,0.8), 0 5px 0 var(--lip); animation: spell-ready 900ms ease-in-out infinite; }
@keyframes spell-ready { 50% { scale: 1.05; } }
.undo-btn .count { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; border-radius: 999px; background: var(--ink); box-shadow: 0 0 0 2px var(--gold-3); font-size: 0.75rem; line-height: 22px; text-align: center; }
.hud-right { position: absolute; right: var(--edge-right); bottom: var(--edge-bottom); display: flex; gap: 10px; }

/* banners: centred with auto margins (not translateX) so long text can wrap on phones */
.target-banner, .center-banner {
  position: absolute; left: 0; right: 0; margin: 0 auto; width: fit-content; max-width: calc(100vw - 32px);
  font-family: var(--font-display); font-weight: 900; text-align: center; pointer-events: none; text-wrap: balance;
}
.target-banner { top: calc(150px + var(--safe-top)); padding: 8px 18px; border-radius: 12px; background: rgba(10,13,31,0.88); box-shadow: 0 0 0 2px var(--gold-2); font-size: 0.95rem; animation: target-in 320ms var(--ease-spring) both, target-glow 1.4s ease-in-out 320ms infinite; }
@keyframes target-in { from { opacity: 0; translate: 0 -10px; } }
@keyframes target-glow { 50% { scale: 1.03; } }
.center-banner { top: 30%; font-size: clamp(2rem, 7vw, 4.4rem); line-height: 1.02; animation: banner 2.1s var(--ease-out) both; }
.center-banner small { display: block; margin-top: 0.3em; font-family: var(--font-ui); font-size: max(0.75rem, 0.3em); letter-spacing: 0.26em; color: var(--cream); -webkit-text-fill-color: var(--cream); }
.center-banner.out { animation: banner-out 220ms var(--ease-in) forwards; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.9); }
  14% { opacity: 1; transform: scale(0.95); }
  24% { transform: scale(1.02); }
  32%, 80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-30px) scale(1); }
}
@keyframes banner-out { to { opacity: 0; transform: translateY(-16px) scale(0.92); } }
.swipe-hint { position: absolute; left: 0; right: 0; margin: 0 auto; width: fit-content; top: 58%; pointer-events: none; display: grid; justify-items: center; gap: 8px; font-weight: 900; text-shadow: 0 2px 6px #000; animation: hint-fade 4s ease-in-out infinite; }
.swipe-hint span { padding: 8px 16px; border-radius: 999px; background: rgba(10,13,31,0.82); box-shadow: 0 0 0 2px rgba(244,197,90,0.6); text-align: center; max-width: calc(100vw - 48px); }
.swipe-hint .hand { width: 54px; height: 54px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,0.95), rgba(255,255,255,0.2) 60%, transparent 70%); animation: swipe 1.6s var(--ease-out) infinite; }
@keyframes swipe { 0% { transform: translateX(-70px); opacity: 0; } 20% { opacity: 1; } 80% { transform: translateX(70px); opacity: 1; } 100% { opacity: 0; transform: translateX(70px); } }
@keyframes hint-fade { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; top: calc(86px + var(--safe-top)); left: 0; right: 0; margin: 0 auto; width: max-content; max-width: calc(100vw - 24px);
  display: grid; gap: 8px; z-index: 40; pointer-events: none; justify-items: center;
}
#toasts.over-modal { top: calc(8px + var(--safe-top)); bottom: auto; }   /* above the dialog: never over its action buttons */
.toast { padding: 10px 18px 10px 12px; display: flex; align-items: center; gap: 10px; font-weight: 800; max-width: min(92vw, 520px); animation: toast-in 420ms var(--ease-spring) both; }
.toast.out { animation: toast-out 260ms var(--ease-in) forwards; }
.toast .icon { width: 32px; height: 32px; }
.toast small { display: block; font-weight: 600; color: var(--muted); font-size: 0.78rem; line-height: 1.3; }
.toast-title { line-height: 1.25; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.92); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px) scale(0.96); } }
@keyframes toast { 0% { opacity: 0; transform: translateY(-16px) scale(0.9); } 10% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }

/* ---------- modals ---------- */
#modals { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; pointer-events: none; padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); touch-action: none; }
#modals::before {       /* backdrop fades independently of the dialog */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 40%, rgba(10,13,31,0.5), rgba(4,6,16,0.86));
  opacity: 0; transition: opacity 260ms var(--ease-out);
}
#modals.open { pointer-events: auto; }
#modals.open::before { opacity: 1; }
@media (hover: hover) and (pointer: fine) {
  #modals.open { backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }   /* desktop only: cheap enough there */
}
#modals > .modal { grid-area: 1 / 1; }   /* closing + opening dialogs overlap instead of stacking */
.modal {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom));
  max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden;
  animation: modal-in 440ms var(--ease-spring-soft) both;
}
.modal.closing { animation: modal-out 180ms var(--ease-in) forwards; pointer-events: none; }
.modal.wide { width: min(820px, calc(100vw - 32px)); }
@keyframes modal-in { from { opacity: 0; transform: translateY(22px) scale(0.9); } 60% { opacity: 1; } }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(0.95); } }
.modal-head { position: relative; padding: 18px 64px 10px 22px; }
.modal-head h2 { margin: 0; font-size: clamp(1.35rem, 4.5vw, 2rem); line-height: 1.15; }
.modal-head .close { position: absolute; right: 12px; top: 12px; width: 44px; height: 44px; }
.modal-head .close .icon { width: 22px; height: 22px; }
.modal-body { padding: 6px 22px 16px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--gold-3) transparent; }
.modal-body p { line-height: 1.45; }
.modal-foot:empty { display: none; }
.modal-foot { padding: 12px 22px 20px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; box-shadow: 0 -1px 0 rgba(244,197,90,0.14); }

.result-score { text-align: center; margin: 4px 0 10px; }
.result-score .big { font-size: clamp(2.8rem, 12vw, 4.6rem); line-height: 1; }
.record-ribbon { display: inline-block; margin-top: 6px; padding: 5px 16px; border-radius: 6px; font-weight: 900; letter-spacing: 0.18em; font-size: 0.8rem; background: linear-gradient(180deg, #ff6a5a, var(--ruby-deep)); box-shadow: 0 0 0 2px var(--gold-2), 0 0 24px rgba(255,90,70,0.6); animation: combo-pop 600ms var(--ease-spring) 600ms both; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0; }
.result-grid .cell { padding: 10px; border-radius: 12px; background: rgba(6,8,24,0.55); box-shadow: inset 0 0 0 1px rgba(244,197,90,0.25); text-align: center; }
.result-grid .cell .num { font-size: 1.25rem; display: block; line-height: 1.2; }
.reward-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.reward { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: rgba(6,8,24,0.65); box-shadow: 0 0 0 2px rgba(244,197,90,0.5); font-weight: 900; font-size: 1.1rem; animation: reward-in 500ms var(--ease-spring) both; }
.reward .icon { width: 30px; height: 30px; }
@keyframes reward-in { from { opacity: 0; transform: scale(0.3); } }
.xp-track { height: 14px; border-radius: 999px; background: #060818; box-shadow: inset 0 2px 4px rgba(0,0,0,0.8), 0 0 0 2px var(--sky-deep); overflow: hidden; margin: 8px 0 4px; }
.xp-track > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #6bd0ff, #4a8cf0); transition: width 1200ms var(--ease-out); }
.list { display: grid; gap: 10px; }
.row-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px; border-radius: 14px; background: rgba(6,8,24,0.5); box-shadow: inset 0 0 0 1px rgba(244,197,90,0.22); }
.row-card .icon-wrap { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 12px; background: rgba(255,255,255,0.06); }
.row-card .icon-wrap .icon { width: 36px; height: 36px; }
.row-card .title { font-weight: 900; }
.row-card .sub { font-size: 0.8rem; color: var(--muted); }
.row-card .sub .reward { padding: 2px 8px; font-size: 0.8rem; box-shadow: 0 0 0 1px rgba(244,197,90,0.4); margin: 2px 4px 0 0; }
.row-card .sub .reward .icon { width: 18px; height: 18px; }
.row-card > div:last-child:not(.icon-wrap) .reward { padding: 4px 10px; font-size: 0.85rem; }
.row-card > div:last-child:not(.icon-wrap) .reward .icon { width: 20px; height: 20px; }
.row-card.done { box-shadow: inset 0 0 0 2px rgba(47,211,107,0.6); }
.row-card.locked { opacity: 0.6; }
.progress { height: 8px; border-radius: 999px; background: #060818; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--emerald), #9cffb8); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs .btn { flex: 1; }
.tabs .btn[aria-selected='true'] { --face-top: #ffe27a; --face-bottom: #f0a92a; --lip: #9a5c0e; color: #3a1f02; text-shadow: 0 1px 0 rgba(255,255,255,0.45); }
.lb-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; background: rgba(6,8,24,0.5); }
.lb-row .rank { font-family: var(--font-display); font-weight: 900; font-size: 1.2rem; text-align: center; }
.lb-row:nth-child(1) .rank { color: #ffd84d; } .lb-row:nth-child(2) .rank { color: #dfe6f0; } .lb-row:nth-child(3) .rank { color: #e0955a; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.shop-item { display: grid; gap: 6px; justify-items: center; align-content: start; text-align: center; padding: 14px 10px 12px; border-radius: 16px; background: rgba(6,8,24,0.55); box-shadow: inset 0 0 0 1px rgba(244,197,90,0.3); }
.shop-item .art { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle, rgba(244,197,90,0.25), transparent 70%); }
.shop-item .art .icon { width: 56px; height: 56px; }
.shop-item .name { font-weight: 900; }
.shop-item .desc { font-size: 0.75rem; color: var(--muted); min-height: 2.4em; line-height: 1.3; }
.shop-item .btn { margin-top: auto; }
.shop-item.theme .art { width: 100%; height: 76px; border-radius: 10px; }
.settings-grid { display: grid; gap: 14px; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; min-height: 44px; }
.setting label, .setting .setting-label { font-weight: 800; }
.setting.stack { grid-template-columns: minmax(0, 1fr) auto; }
.setting input[type=range] { width: 190px; height: 32px; margin: 0; accent-color: var(--gold-2); cursor: pointer; touch-action: pan-x; }
.seg { display: inline-flex; border-radius: 12px; overflow: hidden; box-shadow: 0 0 0 2px var(--gold-3); }
.seg button { border: 0; min-height: 40px; padding: 8px 12px; background: var(--ink-2); font-weight: 800; font-size: 0.8rem; cursor: pointer; white-space: nowrap; transition: background var(--t-fast), color var(--t-fast); }
.seg button + button { box-shadow: inset 1px 0 0 rgba(244,197,90,0.18); }
.seg button[aria-pressed='true'] { background: linear-gradient(180deg, #ffe27a, #f0a92a); color: #3a1f02; }
.seg button:focus-visible { outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) { .seg button:not([aria-pressed='true']):hover { background: #222a58; } }
.toggle { flex: none; width: 58px; height: 32px; border-radius: 999px; border: 0; position: relative; cursor: pointer; background: #2a3058; box-shadow: inset 0 2px 4px rgba(0,0,0,0.6), 0 0 0 2px var(--gold-4); transition: background var(--t-fast); }
.toggle::before { content: ''; position: absolute; inset: -6px -2px; }   /* 44px touch target */
.toggle::after { content: ''; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--gold-rim); box-shadow: 0 2px 4px rgba(0,0,0,0.5); transition: transform var(--t-med) var(--ease-spring); }
.toggle[aria-pressed='true'] { background: var(--emerald-deep); }
.toggle[aria-pressed='true']::after { transform: translateX(26px); }

.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { position: relative; display: grid; justify-items: center; gap: 4px; padding: 10px 4px; border-radius: 12px; background: rgba(6,8,24,0.55); box-shadow: inset 0 0 0 1px rgba(244,197,90,0.25); font-size: 0.75rem; font-weight: 800; text-align: center; }
.day .icon { width: 30px; height: 30px; }
.day.claimed { opacity: 0.55; }
.day.claimed::after { content: '\2713'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 2rem; color: var(--emerald); text-shadow: 0 2px 0 #000; }
.day.today { box-shadow: 0 0 0 2px var(--gold-1), 0 0 18px rgba(244,197,90,0.6); animation: spell-ready 1.2s ease-in-out infinite; }

.unlock-card { text-align: center; display: grid; justify-items: center; gap: 10px; padding: 8px 0 4px; overflow: hidden; }
.unlock-card .sigil {
  width: 150px; height: 170px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 900; font-size: 2.6rem; text-shadow: 0 3px 0 rgba(0,0,0,0.4);
  clip-path: path('M75 0 L150 25 L150 95 C150 135 110 160 75 170 C40 160 0 135 0 95 L0 25 Z');
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,0.45), transparent 50%), var(--accent, #4f8df7);
  box-shadow: inset 0 0 0 8px rgba(255,255,255,0.25);
  animation: sigil-in 900ms var(--ease-spring) both;
}
@keyframes sigil-in { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } }
.unlock-card .lore { color: var(--muted); max-width: 380px; font-style: italic; line-height: 1.45; }
.rays { position: absolute; inset: -40%; background: repeating-conic-gradient(from 0deg, rgba(255,226,122,0.16) 0 10deg, transparent 10deg 20deg); animation: spin 14s linear infinite; pointer-events: none; mask-image: radial-gradient(circle, #000 30%, transparent 65%); -webkit-mask-image: radial-gradient(circle, #000 30%, transparent 65%); will-change: transform; }
@keyframes spin { to { transform: rotate(360deg); } }
.chest-stage { position: relative; height: 170px; display: grid; place-items: center; overflow: hidden; }
.chest-stage .icon { width: 130px; height: 130px; }
.chest-stage.shake .icon { animation: chest-shake 900ms ease-in-out both; }
.chest-stage.open .icon { animation: chest-open 500ms var(--ease-spring) both; }
@keyframes chest-shake { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(-9deg) scale(1.05); } 30% { transform: rotate(8deg); } 45% { transform: rotate(-7deg) scale(1.08); } 60% { transform: rotate(6deg); } 75% { transform: rotate(-4deg) scale(1.12); } }
@keyframes chest-open { 0% { transform: scale(1.12); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* ---------- responsive: mid-width desktop ---------- */
@media (max-width: 1100px) {
  .mode-card .desc { display: none; }
  .mode-card { min-height: 92px; }
}

/* ---------- responsive: compact sizing (phones, both orientations) ---------- */
@media (max-width: 760px), (max-height: 560px) {
  .stat { min-width: 0; padding: 6px 12px 7px; }
  .stat .value { font-size: 1.2rem; }
  .stat.score .value { font-size: 1.4rem; }
  .stat .eyebrow { font-size: 0.58rem; letter-spacing: 0.14em; }
  .combo { font-size: 0.98rem; padding: 5px 9px; gap: 4px; }
  .topbar .btn-round { width: 46px; height: 46px; flex: none; }
  .hearts .icon { width: 22px; height: 22px; }
  .mode-info .chip { font-size: 0.85rem; padding: 3px 10px 3px 6px; min-height: 34px; }
  .timer-chip { font-size: 1.05rem; min-width: 84px; }
  .next-unit { padding: 6px 8px; }
  .next-unit .tile-chip { width: 44px; height: 44px; font-size: 1.05rem; }
  .spell { width: 58px; height: 58px; border-radius: 16px; }
  .spell .icon { width: 30px; height: 30px; }
  .spell span.label { display: none; }
  .elixir-meter { min-width: 96px; }
  .toast { padding: 8px 14px 8px 10px; font-size: 0.88rem; }
  .toast .icon { width: 26px; height: 26px; }
  .modal-head { padding: 16px 62px 8px 18px; }
  .modal-body { padding: 6px 18px 14px; }
  .modal-foot { padding: 10px 16px 16px; }
  .center-banner { font-size: clamp(1.8rem, 9vw, 3rem); }
}

/* ---------- responsive: portrait phones (stacked menu, two-row HUD) ---------- */
@media (max-width: 760px) and (min-height: 561px) {
  .topbar { flex-wrap: nowrap; gap: 6px; }
  .level-badge { padding: 4px 10px 4px 4px; }
  .level-badge .lvl { width: 38px; height: 38px; font-size: 1rem; }
  .level-badge .xp { width: 64px; }
  .level-badge .name { display: none; }
  .currency { min-width: 0; padding-right: 10px; font-size: 0.9rem; }
  .currency .icon { width: 24px; height: 24px; margin-left: -6px; }
  .crest .crest-sub { letter-spacing: 0.16em; }

  /* menu becomes a column: bar, crest, open sky, rail row, mode dock */
  #menu { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left); }
  #menu > .topbar { position: static; width: 100%; }
  #menu .logo { position: static; transform: none; margin-top: 4px; }
  #menu .side-rail { position: static; transform: none; margin-top: auto; display: flex; gap: 8px; justify-content: center; width: 100%; }
  .rail-btn { flex: 1 1 0; max-width: 68px; width: auto; height: 60px; border-radius: 16px; font-size: 0.58rem; gap: 1px; padding: 4px 2px; }
  .rail-btn .icon { width: 28px; height: 28px; }
  .rail-btn .badge-dot { top: -7px; right: -4px; }
  #menu .mode-dock { position: static; transform: none; width: 100%; gap: 12px; }
  .mode-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .mode-card { min-height: 80px; padding: 10px 12px; }
  .mode-card .art { width: 54px; height: 54px; }
  .mode-card .title { font-size: 1rem; }
  .play-row { width: 100%; justify-content: center; }
  .play-btn { min-width: min(280px, 100%); }

  /* HUD: [score best combo] [pause] / [mode chips] */
  #hud .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "score pause" "mode mode"; align-items: start; row-gap: 8px; column-gap: 8px; }
  #hud .score-cluster { grid-area: score; gap: 6px; }
  #hud .mode-info { grid-area: mode; flex-wrap: wrap; }
  #hud .mode-info:empty { display: none; }
  #hud .topbar > .pause-btn { grid-area: pause; }
  .next-unit { top: calc(122px + var(--safe-top)); }
  .dock { gap: 8px; padding: 8px 10px 12px; bottom: calc(78px + var(--safe-bottom)); }
  .hud-right { left: 0; right: 0; margin: 0 auto; width: fit-content; }
  .target-banner { top: calc(176px + var(--safe-top)); font-size: 0.85rem; }
  #toasts { top: calc(124px + var(--safe-top)); }
  body:has(#hud:not(.hidden)) #toasts:not(.over-modal) { top: auto; bottom: calc(196px + var(--safe-bottom)); }   /* in-game: over the island, clear of board and HUD */
  .setting.stack { grid-template-columns: 1fr; gap: 8px; }
  .setting.stack .seg { display: flex; width: 100%; }
  .setting.stack .seg button { flex: 1 1 0; padding: 8px 4px; min-width: 0; }
  .setting input[type=range] { width: min(170px, 46vw); }
  .calendar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .shop-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}
@media (max-width: 760px) and (min-height: 561px) and (max-height: 720px) {
  #menu { gap: 8px; }
  #menu .logo .crest-top { font-size: 1.4rem; }
  #menu .logo .crest-num { font-size: 2.2rem; }
  .mode-card { min-height: 70px; }
  .mode-card .art { width: 46px; height: 46px; }
  .btn-xl { min-height: 56px; }
}

/* ---------- responsive: landscape phones / short windows ---------- */
@media (max-height: 560px) {
  #menu .logo { display: none; }
  .side-rail { top: calc(var(--edge-top) + 62px); bottom: var(--edge-bottom); transform: none; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
  .rail-btn { width: 52px; height: 48px; border-radius: 14px; font-size: 0; gap: 0; padding: 4px; }
  .rail-btn .icon { width: 28px; height: 28px; }
  .mode-dock { left: calc(var(--edge-left) + 64px); right: var(--edge-right); width: auto; transform: none; gap: 10px; }
  .mode-card { min-height: 66px; padding: 8px 10px; }
  .mode-card .art { width: 48px; height: 48px; }
  .mode-card .title { font-size: 0.95rem; }
  .btn-xl { min-height: 52px; font-size: 1.15rem; padding: 8px 28px; }
  .play-btn { min-width: 220px; }
  .play-btn .icon { width: 28px; height: 28px; }
  .level-badge .name { display: none; }
  .level-badge .xp { width: 80px; }

  /* HUD: spells move to a left column so the board stays clear */
  .dock { left: var(--edge-left); bottom: auto; top: calc(50% + 24px); transform: translateY(-50%); flex-direction: column; align-items: center; gap: 12px; padding: 8px 8px 14px; }
  .dock .elixir-meter { min-width: 0; width: 70px; }
  .dock .elixir-meter .eyebrow { font-size: 0; }
  .dock .elixir-meter .eyebrow .icon { font-size: 0.75rem; width: 16px; height: 16px; }
  .spell { width: 52px; height: 48px; }
  .spell .icon { width: 26px; height: 26px; }
  .next-unit { top: calc(var(--edge-top) + 64px); }
  .center-banner { top: 24%; }
  .target-banner { top: calc(var(--edge-top) + 64px); }
  .swipe-hint { top: 62%; }
  #toasts { top: calc(var(--edge-top) + 62px); }
  .modal { max-height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom)); }
  .modal-head h2 { font-size: 1.3rem; }
  .result-score .big { font-size: 2.6rem; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important; }
}
body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; transition-delay: 0ms !important; }
