/* Crumblast UI — "Enchanted cartoon": navy glass, gold frames, gem buttons (05-art-direction.md) */
:root {
  --ink: #1b1030;
  --glass: rgba(21, 18, 58, 0.88);
  --gold-1: #ffe08a; --gold-2: #f6c453; --gold-3: #b9822b;
  --gem: #7ff3ff; --pink: #ff8fd0; --text: #fff8e7;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #120e38; color: var(--text); font-family: var(--font);
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
canvas#world { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }
button { font-family: var(--font); }

/* text with an outline */
.outlined, .title, .timer, .logo h1, .banner, .gem {
  paint-order: stroke fill; -webkit-text-stroke: 5px var(--ink);
}

/* ---------- gem buttons ---------- */
.gem {
  position: relative; border: 0; cursor: pointer; color: var(--text); font-weight: 900; font-size: 20px; letter-spacing: .5px;
  min-width: 48px; min-height: 48px; padding: 10px 26px; border-radius: 18px;
  background: linear-gradient(180deg, #8b6cff 0%, #5b3bd6 55%, #3d2499 100%);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold-2), 0 0 0 8px var(--ink), 0 8px 0 8px rgba(27,16,48,.55), 0 0 26px rgba(127,243,255,.25);
  transition: transform .08s ease, filter .15s ease;
}
.gem::after { content: ""; position: absolute; left: 10%; right: 10%; top: 5px; height: 38%; border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,0)); pointer-events: none; }
.gem:hover { filter: brightness(1.12); }
.gem:active { transform: translateY(3px) scale(.94); filter: brightness(1.25) drop-shadow(0 0 12px var(--gem)); }
.gem.huge { font-size: 30px; padding: 16px 54px; border-radius: 24px;
  background: linear-gradient(180deg, #ffe08a 0%, #f6a93b 55%, #d9761f 100%); color: #fff;
  animation: breathe 2.4s ease-in-out infinite; }
.gem.wide { width: 100%; margin: 7px 0; }
.gem.small { padding: 8px; min-width: 52px; min-height: 52px; border-radius: 16px; font-size: 16px; }
.gem.ghost { background: linear-gradient(180deg, #3b3570, #241f52); }
.gem svg { width: 24px; height: 24px; fill: var(--text); stroke: var(--ink); stroke-width: 1.5; vertical-align: middle; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* ---------- screens ---------- */
#screens { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); pointer-events: auto; }
.screen.on { display: flex; animation: fadein .35s ease; }
.screen.dim { background: radial-gradient(ellipse at center, rgba(21,18,58,.55), rgba(10,8,30,.85)); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.row { display: flex; gap: 22px; align-items: center; justify-content: center; flex-wrap: wrap; }
.panel { position: relative; background: var(--glass); border-radius: 26px; padding: 22px 30px; min-width: 300px; max-width: 92vw; max-height: 92vh; overflow: auto;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px var(--gold-2), 0 0 0 9px var(--ink), 0 0 60px rgba(127,243,255,.25), inset 0 0 40px rgba(127,243,255,.08);
  display: flex; flex-direction: column; align-items: center; }
.panel::before, .panel::after { content: "◆"; position: absolute; top: -14px; color: var(--gem); font-size: 22px; text-shadow: 0 0 10px var(--gem); -webkit-text-stroke: 2px var(--ink); }
.panel::before { left: 18px; } .panel::after { right: 18px; }
.title { margin: 0 0 10px; font-size: 30px; font-weight: 900; color: var(--gold-1); text-align: center; letter-spacing: 1px; }
.title.big { font-size: 46px; }
.sub { margin: 0 0 12px; opacity: .9; font-weight: 700; }

/* title / logo */
.logo { position: relative; text-align: center; }
.logo h1 { margin: 0; font-size: clamp(52px, 11vw, 112px); line-height: .95; font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(180deg, #fff6c8 0%, #ffd24a 45%, #f0901f 80%, #c8561a 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 7px var(--ink); filter: drop-shadow(0 6px 0 var(--ink)) drop-shadow(0 0 28px rgba(255,210,74,.45));
  transform: rotate(-3deg); animation: float 4s ease-in-out infinite; }
.logo .crack { display: inline-block; transform: rotate(8deg) translateY(4px); background: inherit; -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo .tag { margin: 14px 0 0; font-size: clamp(14px, 2.4vw, 20px); font-weight: 800; color: #e8ddff; text-shadow: 0 2px 0 var(--ink); }
.sparkle { position: absolute; color: #fff6c8; text-shadow: 0 0 12px #ffd24a, 0 0 24px #ff8fd0; animation: twinkle 1.8s ease-in-out infinite; font-size: 34px; }
.sparkle.s1 { left: -6%; top: -10%; } .sparkle.s2 { right: -4%; top: 10%; animation-delay: .6s; font-size: 26px; } .sparkle.s3 { left: 40%; bottom: 18%; animation-delay: 1.1s; font-size: 20px; }
@keyframes twinkle { 0%,100% { opacity: .2; transform: scale(.6) rotate(0); } 50% { opacity: 1; transform: scale(1.2) rotate(30deg); } }
@keyframes float { 0%,100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(-2deg) translateY(-8px); } }
.version { position: absolute; bottom: calc(10px + var(--safe-b)); right: calc(14px + var(--safe-r)); font-size: 12px; opacity: .6; font-weight: 700; }

/* unit cards */
.cards { display: flex; gap: 28px; }
.card { width: min(240px, 38vw); background: var(--glass); border-radius: 22px; padding: 14px 16px 16px; cursor: pointer; text-align: center;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px #4a3f8a, 0 0 0 8px var(--ink); transition: transform .15s ease, box-shadow .15s ease; }
.card.sel { transform: translateY(-6px) scale(1.04); box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold-2), 0 0 0 8px var(--ink), 0 0 40px rgba(255,210,74,.5); }
.card canvas { width: 100%; max-width: 150px; aspect-ratio: 1; display: block; margin: 0 auto 6px; }
.card h3 { margin: 0; font-size: 26px; font-weight: 900; color: var(--gold-1); paint-order: stroke fill; -webkit-text-stroke: 4px var(--ink); }
.card .role { font-size: 13px; font-weight: 800; color: var(--gem); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
.stat { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 800; margin: 3px 0; }
.pips { display: flex; gap: 4px; } .pip { width: 16px; height: 9px; border-radius: 4px; background: #3b3570; box-shadow: 0 0 0 2px var(--ink); }
.pip.on { background: linear-gradient(180deg, #ffe08a, #f6a93b); }
.skilltxt { margin-top: 8px; font-size: 13px; font-weight: 700; line-height: 1.3; color: #e8ddff; }
.skilltxt b { color: var(--pink); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.topbar { position: absolute; top: calc(8px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r));
  display: flex; align-items: center; justify-content: center; gap: 10px; }
.topbar #btn-pause { position: absolute; left: 0; top: 0; pointer-events: auto; }
.topbar .spacer { display: none; }
.plates { display: flex; gap: 8px; }
.plate { display: flex; align-items: center; gap: 6px; background: var(--glass); border-radius: 14px; padding: 4px 9px 4px 4px;
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--c, #555), 0 0 0 6px var(--ink); min-width: 96px; transition: opacity .3s; }
.plate canvas { width: 34px; height: 34px; }
.plate .nm { font-size: 11px; font-weight: 900; color: var(--c); paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); white-space: nowrap; max-width: 64px; overflow: hidden; }
.plate .hp { height: 7px; width: 56px; border-radius: 4px; background: #2b2560; overflow: hidden; box-shadow: 0 0 0 1.5px var(--ink); margin-top: 2px; }
.plate .hp i { display: block; height: 100%; background: linear-gradient(180deg, #b6f58a, #5cc23a); transition: width .2s; }
.plate.low .hp i { background: linear-gradient(180deg, #ff9a9a, #e84848); }
.plate.out { opacity: .45; filter: grayscale(.8); }
.plate.out canvas { opacity: .5; }
.timer { min-width: 96px; text-align: center; font-size: 30px; font-weight: 900; color: var(--gold-1); background: var(--glass); border-radius: 16px; padding: 2px 14px;
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--gold-2), 0 0 0 8px var(--ink); }
.timer.hot { color: var(--pink); animation: pulse .6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.1); } }
.feed { position: absolute; right: calc(14px + var(--safe-r)); top: calc(70px + var(--safe-t)); display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.feed div { background: var(--glass); padding: 4px 10px; border-radius: 10px; font-size: 13px; font-weight: 800; box-shadow: 0 0 0 2px var(--ink); animation: fadein .2s; }
.banner { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: clamp(40px, 9vw, 90px); font-weight: 900; color: var(--gold-1);
  -webkit-text-stroke: 8px var(--ink); filter: drop-shadow(0 0 24px rgba(255,210,74,.6)); opacity: 0; }
.banner.show { animation: bannerpop 1s ease forwards; }
.banner.small { font-size: clamp(24px, 5vw, 44px); color: var(--pink); filter: drop-shadow(0 0 20px rgba(255,79,216,.8)); }
@keyframes bannerpop { 0% { opacity: 0; transform: scale(.4); } 20% { opacity: 1; transform: scale(1.15); } 35% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(1.05); } }

/* touch controls (only on touch devices) */
.stick-zone, .action-cluster { display: none; }
body.touch .stick-zone, body.touch .action-cluster { display: block; }
body.touch .desk-help { display: none; }
.stick-zone { position: absolute; left: 0; top: 70px; bottom: 0; width: 45%; pointer-events: auto; }
.stick-base { position: absolute; left: 0; top: 0; width: 120px; height: 120px; border-radius: 50%; opacity: 0; transition: opacity .15s;
  background: radial-gradient(circle, rgba(127,243,255,.12), rgba(21,18,58,.5)); box-shadow: 0 0 0 3px rgba(27,16,48,.8), 0 0 0 5px rgba(246,196,83,.6), 0 0 24px rgba(127,243,255,.3); }
.stick-base.on { opacity: 1; }
.stick-knob { position: absolute; left: 32px; top: 32px; width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c8, #f6c453 50%, #b9822b); box-shadow: 0 0 0 3px var(--ink), 0 0 16px rgba(255,210,74,.6); }
.action-cluster { position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); width: 250px; height: 230px; }
.fire { position: absolute; right: 0; bottom: 0; width: 100px; height: 100px; border-radius: 50%; pointer-events: auto; touch-action: none;
  background: radial-gradient(circle at 35% 30%, #ffb3e6, #ff4fd8 55%, #8a1f9e); box-shadow: 0 0 0 4px var(--ink), 0 0 0 8px var(--gold-2), 0 0 0 10px var(--ink), 0 0 30px rgba(255,79,216,.6);
  display: flex; align-items: center; justify-content: center; }
.fire.active { transform: scale(.92); filter: brightness(1.3); }
.fire .icon svg, .skill .icon svg, .wbtn svg { width: 54%; height: 54%; }
.skill { position: absolute; right: 116px; bottom: 6px; width: 76px; height: 76px; border-radius: 50%; border: 0; padding: 0; pointer-events: auto;
  background: radial-gradient(circle at 35% 30%, #9ffcff, #2aa3cc 60%, #154a7a); box-shadow: 0 0 0 3px var(--ink), 0 0 0 5px #4a3f8a, 0 0 0 7px var(--ink);
  display: flex; align-items: center; justify-content: center; filter: grayscale(.6) brightness(.8); }
.skill.ready { filter: none; animation: breathe 1.2s ease-in-out infinite; box-shadow: 0 0 0 3px var(--ink), 0 0 0 5px var(--gold-2), 0 0 0 7px var(--ink), 0 0 26px rgba(127,243,255,.8); }
.skill .ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(27,16,48,.6); stroke-width: 6; }
.ring-fg { fill: none; stroke: var(--gem); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 220; stroke-dashoffset: 220; filter: drop-shadow(0 0 4px var(--gem)); }
.weapons { position: absolute; right: 0; bottom: 116px; display: flex; gap: 10px; }
.wbtn { position: relative; width: 62px; height: 62px; border-radius: 18px; border: 0; padding: 0; pointer-events: auto; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #3b3570, #241f52); box-shadow: 0 0 0 3px var(--ink), 0 0 0 5px #4a3f8a, 0 0 0 7px var(--ink); }
.wbtn.sel { background: linear-gradient(180deg, #8b6cff, #4b2bc0); box-shadow: 0 0 0 3px var(--ink), 0 0 0 5px var(--gold-2), 0 0 0 7px var(--ink), 0 0 18px rgba(255,210,74,.5); }
.wbtn.empty { filter: grayscale(1) brightness(.6); }
.wbtn .ammo { position: absolute; right: -6px; top: -8px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--gold-2); color: var(--ink);
  font-weight: 900; font-size: 14px; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--ink); padding: 0 5px; }
.wbtn.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* desktop: weapon bar bottom-centre */
body:not(.touch) .action-cluster { display: block; width: auto; height: auto; right: 50%; transform: translateX(50%); bottom: calc(16px + var(--safe-b)); }
body:not(.touch) .action-cluster .fire { display: none; }
body:not(.touch) .action-cluster .weapons { position: static; }
body:not(.touch) .action-cluster .skill { right: auto; left: calc(100% + 20px); bottom: -7px; }
.desk-help { position: absolute; left: 14px; bottom: 10px; font-size: 12px; opacity: .55; font-weight: 700; }

.dead-bar { position: absolute; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); display: flex; gap: 16px; align-items: center;
  background: var(--glass); padding: 10px 16px; border-radius: 18px; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--pink), 0 0 0 8px var(--ink); pointer-events: auto; font-weight: 900; }

/* results */
.podium { display: flex; flex-direction: column; gap: 8px; width: min(560px, 86vw); margin: 4px 0 16px; }
.prow { display: grid; grid-template-columns: 40px 44px 1fr repeat(3, 70px); align-items: center; gap: 8px; background: rgba(255,255,255,.05); border-radius: 14px; padding: 6px 10px;
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--c); font-weight: 800; font-size: 14px; }
.prow.me { background: rgba(255,210,74,.14); }
.prow .place { font-size: 22px; font-weight: 900; color: var(--gold-1); text-align: center; paint-order: stroke fill; -webkit-text-stroke: 4px var(--ink); }
.prow canvas { width: 40px; height: 40px; }
.prow .who { color: var(--c); paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); }
.prow .bot { font-size: 10px; background: #4a3f8a; color: #fff; padding: 2px 5px; border-radius: 6px; margin-left: 6px; -webkit-text-stroke: 0; }
.prow .num { text-align: center; } .prow .num small { display: block; font-size: 10px; opacity: .7; }

/* rotate + loading + debug */
#rotate { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: #120e38; z-index: 50; }
@media (orientation: portrait) and (pointer: coarse) { #rotate { display: flex; } }
#rotate .phone { width: 46px; height: 80px; border-radius: 10px; border: 4px solid var(--gold-2); margin: 10px auto 18px; animation: rot 1.6s ease-in-out infinite; }
#rotate p { font-weight: 900; font-size: 20px; text-align: center; }
@keyframes rot { 50% { transform: rotate(-90deg); } }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 900; color: var(--gold-1); background: #120e38; z-index: 40; }
#debug { position: fixed; left: 8px; bottom: 8px; font: 12px ui-monospace, monospace; background: rgba(0,0,0,.6); padding: 4px 8px; border-radius: 6px; z-index: 60; }

@media (max-height: 430px) {
  .gem.huge { font-size: 24px; padding: 12px 40px; }
  .title.big { font-size: 34px; }
  .cards { gap: 16px; } .card canvas { max-width: 96px; } .card { padding: 10px 12px; }
  .screen { gap: 14px; }
  .plate { min-width: 0; padding-right: 6px; } .plate .nm { max-width: 44px; } .plate .hp { width: 40px; } .plate canvas { width: 28px; height: 28px; }
  .timer { font-size: 24px; min-width: 80px; }
  .prow { grid-template-columns: 30px 34px 1fr repeat(3, 56px); padding: 4px 8px; font-size: 12px; } .prow canvas { width: 32px; height: 32px; }
  .podium { gap: 5px; margin-bottom: 10px; }
  .wbtn { width: 52px; height: 52px; border-radius: 15px; }
  .weapons { bottom: 104px; gap: 8px; }
  .fire { width: 92px; height: 92px; }
  .skill { width: 66px; height: 66px; right: 108px; }
  .action-cluster { width: 230px; height: 200px; }
}
@media (prefers-reduced-motion: reduce) { .gem.huge, .logo h1, .sparkle, .skill.ready { animation: none; } }
