* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; position: fixed; inset: 0; overscroll-behavior: none;
  background: #2a1a4a; color: #fff; font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; touch-action: manipulation; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.screen.show { display: flex; }
.screen.overlay { background: rgba(20, 12, 40, 0.55); z-index: 20; }
.panel { background: rgba(255, 252, 245, 0.94); color: #3a2a4a; border-radius: 26px; padding: clamp(14px, 3vmin, 30px); max-width: 640px; width: 100%;
  max-height: 100%; overflow-y: auto; text-align: center; box-shadow: 0 10px 0 rgba(0,0,0,0.18), 0 20px 50px rgba(0,0,0,0.35); }
.panel.wide { max-width: 980px; }
h2 { margin: 0 0 10px; font-size: clamp(22px, 4.2vmin, 36px); color: #6a3a9a; }
.logo { line-height: 0.95; }
.logo span { display: block; font-size: clamp(22px, 5vmin, 40px); color: #2a8f8f; font-weight: 800; letter-spacing: 1px; }
.logo b { display: block; font-size: clamp(48px, 12vmin, 96px); color: #e07a30; text-shadow: 0 5px 0 #6a3a9a; letter-spacing: 4px; }
.sub { margin: 6px 0; font-weight: 800; color: #6a3a9a; font-size: clamp(15px, 2.6vmin, 22px); }
.story { font-size: clamp(14px, 2.4vmin, 19px); line-height: 1.35; margin: 8px auto 14px; max-width: 560px; }
.keys { font-size: 13px; opacity: 0.75; margin: 12px 0 0; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.big { background: #e07a30; color: #fff; font-size: clamp(18px, 3.2vmin, 26px); font-weight: 800; padding: 14px 26px; border-radius: 999px; box-shadow: 0 5px 0 #a0501a; min-width: 200px; }
.big small { display: block; font-size: 0.6em; opacity: 0.9; }
.big.alt { background: #2a8f8f; box-shadow: 0 5px 0 #1a5a5a; }
.big:active, .card:active { transform: translateY(3px); }
.small { background: #ddd3ee; color: #3a2a4a; padding: 8px 16px; border-radius: 999px; font-weight: 700; }
.back { margin-top: 12px; background: none; color: #6a3a9a; font-weight: 700; font-size: 16px; padding: 8px; }

.cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.card { background: #fff; border: 4px solid #eadff7; border-radius: 20px; padding: 10px; width: clamp(150px, 28vw, 260px); color: #3a2a4a; text-align: center; }
.card:hover, .card:focus-visible { border-color: #e07a30; outline: none; }
.card img, .card .emo { width: 100%; max-width: 150px; aspect-ratio: 1; object-fit: cover; border-radius: 14px; display: block; margin: 0 auto 6px; }
.card .nm { font-weight: 800; font-size: 20px; }
.card .tg { font-size: 13px; min-height: 2.4em; margin: 2px 0 6px; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 6px; font-size: 12px; text-align: left; align-items: center; }
.bar { height: 9px; border-radius: 6px; background: #eee; overflow: hidden; } .bar i { display: block; height: 100%; background: linear-gradient(90deg, #f0c030, #e07a30); }
.tracks .card { width: clamp(150px, 21vw, 220px); }
.tracks .sw { height: 70px; border-radius: 12px; margin-bottom: 6px; display: flex; align-items: center; justify-content: center; font-size: 34px; }
.emo { display: flex !important; align-items: center; justify-content: center; font-size: 80px; background: #f0e8fb; }

/* Name card */
.namecard { background: #fffaf0; color: #3a2a4a; border-radius: 26px; padding: 18px 22px; display: flex; gap: 18px; align-items: center; max-width: 560px; width: 100%;
  box-shadow: 0 8px 0 #6a3a9a, 0 20px 60px rgba(0,0,0,0.4); flex-wrap: wrap; justify-content: center; animation: pop 0.35s ease-out; cursor: pointer; }
@keyframes pop { from { transform: scale(0.6) rotate(-4deg); opacity: 0; } to { transform: none; opacity: 1; } }
.namecard .pic img, .namecard .pic .emo { width: 130px; height: 130px; border-radius: 18px; object-fit: cover; display: block; }
.namecard .txt { flex: 1; min-width: 200px; text-align: left; }
.cname { font-size: clamp(26px, 5vmin, 40px); font-weight: 900; color: #6a3a9a; }
.ctag { font-size: clamp(17px, 3vmin, 22px); font-weight: 700; margin-top: 2px; }
.cmore { font-size: 15px; margin-top: 6px; opacity: 0.85; }
.tap { width: 100%; text-align: center; font-size: 13px; opacity: 0.6; }

/* Intro */
#intro { background: #000; z-index: 50; }
#intro video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#introPlay { position: relative; z-index: 2; }
#introSkip { position: absolute; z-index: 3; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); background: rgba(255,255,255,0.92); color: #3a2a4a;
  font-weight: 800; font-size: 18px; padding: 12px 22px; border-radius: 999px; }

/* Victory video */
#winv { position: fixed; inset: 0; z-index: 60; background: #000; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
#winv.on { opacity: 1; pointer-events: auto; }
#winv video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#winSkip, #winUnmute { position: absolute; z-index: 2; top: max(14px, env(safe-area-inset-top)); background: rgba(255,255,255,0.92); color: #3a2a4a; font-weight: 800; font-size: 18px; padding: 12px 22px; border-radius: 999px; }
#winSkip { right: max(14px, env(safe-area-inset-right)); } #winUnmute { left: max(14px, env(safe-area-inset-left)); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; text-shadow: 0 2px 0 rgba(0,0,0,0.45); }
#hudPos { position: absolute; left: max(12px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); font-weight: 900; }
#hudPos b { font-size: clamp(40px, 9vmin, 72px); color: #ffe060; -webkit-text-stroke: 2px #6a3a9a; }
#hudPos span { font-size: clamp(18px, 3.5vmin, 28px); margin-left: 2px; }
#hudMid { position: absolute; left: 50%; transform: translateX(-50%); top: max(10px, env(safe-area-inset-top)); text-align: center; }
#hudLap { font-size: clamp(20px, 4.2vmin, 34px); font-weight: 900; background: rgba(40,20,70,0.55); padding: 4px 16px; border-radius: 999px; }
#hudName { font-size: clamp(13px, 2.4vmin, 18px); font-weight: 800; margin-top: 4px; }
#hudItem { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); width: clamp(76px, 14vmin, 110px); text-align: center;
  background: rgba(255,255,255,0.88); color: #3a2a4a; border-radius: 18px; padding: 6px 4px; border: 4px solid #f0c030; text-shadow: none; }
#hudItem .ico { font-size: clamp(32px, 7vmin, 52px); height: 1.2em; line-height: 1.2em; }
#hudItem .nm { font-size: 11px; font-weight: 800; }
#hudItem.empty { border-color: #ccc; opacity: 0.7; } #hudItem.rolling .ico { animation: shake 0.15s infinite; }
@keyframes shake { 50% { transform: translateY(-3px) rotate(8deg); } }
#mini { position: absolute; right: max(12px, env(safe-area-inset-right)); top: calc(max(10px, env(safe-area-inset-top)) + clamp(96px, 19vmin, 140px)); width: clamp(90px, 18vmin, 150px); height: clamp(90px, 18vmin, 150px); opacity: 0.9; }
#btnPause { pointer-events: auto; position: absolute; left: max(12px, env(safe-area-inset-left)); top: calc(max(10px, env(safe-area-inset-top)) + clamp(56px, 11vmin, 86px)); width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,0.8); color: #3a2a4a; font-size: 14px; font-weight: 900; }
#toast { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); max-width: 90vw; width: max-content; text-align: center; font-weight: 800; font-size: clamp(16px, 3.4vmin, 26px);
  background: rgba(106,58,154,0.85); padding: 8px 18px; border-radius: 16px; opacity: 0; transition: opacity 0.25s; }
#toast.on { opacity: 1; } #toast.big { font-size: clamp(26px, 6vmin, 48px); background: rgba(224,122,48,0.88); }
#count { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); font-size: clamp(80px, 22vmin, 180px); font-weight: 900; color: #ffe060; -webkit-text-stroke: 4px #6a3a9a; }
#wrong { position: absolute; left: 50%; top: 36%; transform: translateX(-50%); font-size: 28px; font-weight: 900; color: #fff; background: #d03030; padding: 6px 18px; border-radius: 14px; }
#fxBadge { position: absolute; left: 50%; bottom: calc(190px + env(safe-area-inset-bottom)); transform: translateX(-50%); font-weight: 800; background: rgba(42,143,143,0.85); padding: 6px 14px; border-radius: 999px; }
body:not(.touch) #fxBadge { bottom: 40px; }

/* Touch buttons: always >= 78px + safe area above the bottom edge */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.tb { pointer-events: auto; position: absolute; bottom: calc(78px + env(safe-area-inset-bottom)); width: 84px; height: 84px; border-radius: 50%;
  background: rgba(255,255,255,0.78); color: #3a2a4a; font-size: 30px; font-weight: 900; box-shadow: 0 4px 0 rgba(0,0,0,0.25); touch-action: none; }
.tb.on { background: #ffe060; transform: translateY(3px); }
#tLeft { left: calc(14px + env(safe-area-inset-left)); }
#tRight { left: calc(110px + env(safe-area-inset-left)); }
#tItem { right: calc(14px + env(safe-area-inset-right)); width: 96px; height: 96px; font-size: 18px; background: rgba(240,192,48,0.9); }
#tBrake { right: calc(122px + env(safe-area-inset-right)); width: 74px; height: 74px; font-size: 13px; background: rgba(255,170,170,0.85); }

/* Results */
#resTable { margin: 6px auto 14px; border-collapse: collapse; font-size: clamp(14px, 2.4vmin, 18px); min-width: min(100%, 420px); }
#resTable td, #resTable th { padding: 4px 10px; text-align: left; }
#resTable th { font-size: 12px; text-transform: uppercase; opacity: 0.6; }
#resTable tr.me { background: #ffe9a8; font-weight: 800; } #resTable tr.boss td:nth-child(2) { color: #6a3a9a; font-weight: 800; }

@media (max-height: 500px) and (orientation: landscape) {
  .panel { padding: 10px 16px; border-radius: 18px; }
  .story { margin: 4px auto 8px; } .logo b { font-size: 44px; } .logo span { font-size: 20px; }
  .card { padding: 6px; width: 180px; } .card img, .card .emo { max-width: 70px; } .card .emo { font-size: 44px; } .card .tg { min-height: 0; }
  .tracks .sw { height: 40px; font-size: 24px; } .tracks .card { width: 150px; }
  .namecard .pic img, .namecard .pic .emo { width: 90px; height: 90px; } .namecard { padding: 12px 16px; }
  .big { padding: 10px 20px; min-width: 160px; }
  .tb { width: 72px; height: 72px; } #tRight { left: calc(96px + env(safe-area-inset-left)); } #tItem { width: 84px; height: 84px; } #tBrake { right: calc(108px + env(safe-area-inset-right)); width: 64px; height: 64px; }
  #fxBadge { bottom: calc(170px + env(safe-area-inset-bottom)); }
}
@media (max-width: 500px) and (orientation: portrait) {
  .card { width: 100%; display: grid; grid-template-columns: 74px 1fr; grid-template-rows: auto auto auto; column-gap: 10px; text-align: left; padding: 8px; }
  .card img, .card .emo { grid-row: 1 / 4; max-width: 74px; margin: 0; } .card .emo { font-size: 44px; } .card .nm { font-size: 18px; } .card .tg { min-height: 0; margin: 0 0 4px; }
  .tracks .card { width: 100%; grid-template-columns: 60px 1fr; } .tracks .sw { grid-row: 1 / 4; height: 60px; margin: 0; }
}
