:root {
  --bg: #0d0618; --panel: rgba(18, 10, 34, 0.92); --panel2: rgba(34, 20, 60, 0.95); --line: rgba(95, 227, 255, 0.22);
  --ink: #eef6ff; --muted: #a9a2c8; --cyan: #5fe3ff; --pink: #ff4fc3; --amber: #ffb347; --green: #3dffb0; --red: #ff4d6d;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom); --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: "Titillium Web", "Nunito", system-ui, sans-serif; -webkit-text-size-adjust: 100%; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.touch { -webkit-user-select: none; user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; }
body.touch .key-only, body:not(.touch) .touch-only { display: none; }
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--bg); z-index: 50; }
#loading b { font-size: 36px; letter-spacing: 6px; font-weight: 700; color: var(--cyan); text-shadow: 0 0 20px var(--cyan); } #loading span { color: var(--muted); }

/* ------------------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; z-index: 8; pointer-events: none; } #hud > * { pointer-events: auto; }
.bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 14px; padding: max(6px, var(--sat)) max(10px, var(--sar)) 6px max(10px, var(--sal)); background: linear-gradient(180deg, rgba(13, 6, 24, 0.95), rgba(13, 6, 24, 0.75)); border-bottom: 1px solid var(--line); }
.bar small { display: block; font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.bar b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lvl { min-width: 0; } .lvl b { color: var(--cyan); text-shadow: 0 0 10px rgba(95, 227, 255, 0.5); }
.m.wide { min-width: 130px; } .pbar { display: block; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin-top: 2px; width: 100%; min-width: 80px; } .pbar u { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.3s; }
.m.anger .pbar u { background: linear-gradient(90deg, var(--amber), var(--red)); }
.m.warn b { color: var(--red); text-shadow: 0 0 8px rgba(255, 77, 109, 0.6); }
.speed { display: flex; gap: 2px; background: rgba(0, 0, 0, 0.35); border-radius: 8px; padding: 2px; margin-left: auto; }
.speed button { background: transparent; border: 0; border-radius: 6px; padding: 3px 7px; font-weight: 700; font-size: 12.5px; color: var(--muted); }
.speed button.on { background: var(--cyan); color: #06121a; }
.menu-b { width: 36px; height: 36px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
.event { position: absolute; top: calc(max(6px, var(--sat)) + 60px); left: 50%; transform: translateX(-50%); background: rgba(255, 79, 195, 0.18); border: 1px solid var(--pink); color: #fff; border-radius: 12px; padding: 8px 16px; text-align: center; box-shadow: 0 0 24px rgba(255, 79, 195, 0.4); animation: pulse 1s infinite; pointer-events: none; }
.event b { display: block; font-size: 17px; letter-spacing: 1px; text-transform: uppercase; } .event span { font-size: 13px; color: #ffd8f2; }
.event.blk { background: rgba(255, 77, 109, 0.22); border-color: var(--red); }
#hud > .event, #hud > .coach, #hud > .info { pointer-events: none; }   /* display only: taps go through to the board */
@keyframes pulse { 50% { box-shadow: 0 0 40px rgba(255, 79, 195, 0.7); } }
.coach { position: absolute; left: max(12px, var(--sal)); top: calc(max(6px, var(--sat)) + 62px); max-width: min(330px, 32vw); background: var(--panel); border: 1px solid var(--cyan); border-radius: 12px; padding: 9px 12px; font-size: 14px; line-height: 1.4; box-shadow: 0 0 20px rgba(95, 227, 255, 0.25); pointer-events: none; }
.info { position: absolute; right: max(12px, var(--sar)); top: calc(max(6px, var(--sat)) + 62px); width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 11px; font-size: 13px; pointer-events: none; }
.info b { color: var(--cyan); display: block; font-size: 14px; } .info .row { display: flex; justify-content: space-between; color: var(--muted); } .info .row span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }
.tools { position: absolute; left: 50%; transform: translateX(-50%); bottom: max(10px, var(--sab)); display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 6px; }
.tools button { width: 74px; background: rgba(255, 255, 255, 0.04); border: 1px solid transparent; border-radius: 11px; padding: 5px 2px 4px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11.5px; font-weight: 700; color: var(--ink); }
.tools button i { font-style: normal; font-size: 20px; line-height: 1.1; } .tools button small { color: var(--amber); font-size: 11px; } .tools button kbd { font-size: 9px; padding: 0 3px; opacity: 0.7; }
.tools button.on { border-color: var(--cyan); background: rgba(95, 227, 255, 0.14); box-shadow: 0 0 14px rgba(95, 227, 255, 0.35); }
.tools button:disabled { opacity: 0.4; }
body.touch .tools button kbd { display: none; }
#rotate { display: none; position: fixed; inset: 0; z-index: 40; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 24px; }
#rotate b { font-size: 54px; color: var(--cyan); } #rotate p { font-size: 17px; max-width: 280px; }
@media (orientation: portrait) and (pointer: coarse) { body.playing #rotate { display: flex; } }

/* ------------------------------------------------------------ screens */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.screen { position: absolute; inset: 0; display: none; pointer-events: auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: max(16px, var(--sat)) max(16px, var(--sar)) max(16px, var(--sab)) max(16px, var(--sal)); background: rgba(9, 4, 20, 0.55); }
.screen.active { display: flex; } .screen > * { margin: auto; }
#title.screen { background: linear-gradient(90deg, rgba(9, 4, 20, 0.92) 0%, rgba(9, 4, 20, 0.6) 46%, rgba(9, 4, 20, 0) 100%); gap: 24px; align-items: center; }
.t-main { max-width: 500px; width: 100%; margin: auto auto auto clamp(0px, 5vw, 80px); }
.kicker { color: var(--pink); letter-spacing: 2px; text-transform: uppercase; font-size: 12.5px; font-weight: 700; margin: 0; }
.logo { margin: 4px 0 10px; font-size: clamp(56px, 9vw, 104px); line-height: 0.9; font-weight: 700; letter-spacing: 4px; color: #eef6ff; text-shadow: 0 0 18px rgba(95, 227, 255, 0.7), 0 0 50px rgba(95, 227, 255, 0.35); font-style: italic; }
.logo span { color: var(--pink); text-shadow: 0 0 18px rgba(255, 79, 195, 0.8), 0 0 50px rgba(255, 79, 195, 0.4); }
.lead { color: #dcd6f2; font-size: 16px; line-height: 1.5; margin: 0 0 16px; font-family: "Nunito", system-ui, sans-serif; }
.challenge:empty { display: none; } .challenge { background: rgba(255, 79, 195, 0.12); border: 1px solid rgba(255, 79, 195, 0.5); padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.menu { display: flex; flex-direction: column; gap: 8px; } .menu .row { display: flex; gap: 8px; } .menu .row button { flex: 1; }
.menu button, .buttons button { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; font-size: 17px; font-weight: 700; text-align: left; letter-spacing: 0.5px; }
.menu button:hover, .buttons button:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(95, 227, 255, 0.3); }
button.primary { background: linear-gradient(90deg, #5fe3ff, #ff4fc3) !important; color: #0d0618 !important; border-color: transparent !important; }
button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--muted); }
.disclaimer { color: var(--muted); font-size: 12px; margin-top: 14px; line-height: 1.45; font-family: "Nunito", sans-serif; } .disclaimer a { color: var(--muted); }
.t-side { width: 320px; max-width: 100%; margin: auto clamp(0px, 4vw, 60px) auto auto; display: flex; flex-direction: column; gap: 10px; font-family: "Nunito", sans-serif; } .t-side > div:empty { display: none; }
.gw-board { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 20px; width: 100%; max-width: 760px; box-shadow: 0 0 40px rgba(95, 227, 255, 0.08); }
.sheet.wide { max-width: 980px; } .sheet.narrow { max-width: 430px; }
.sheet header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; } .sheet header h2 { flex: 1; }
.sheet h2 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: 1px; } .sheet h4 { margin: 12px 0 6px; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--pink); }
.lvls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lv { text-align: left; border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); background: linear-gradient(160deg, rgba(95, 227, 255, 0.1), rgba(255, 79, 195, 0.06)); display: flex; flex-direction: column; gap: 3px; min-height: 92px; }
.lv small { color: var(--pink); font-weight: 700; letter-spacing: 1.5px; font-size: 11px; text-transform: uppercase; } .lv b { font-size: 17px; } .lv span { font-size: 12.5px; color: var(--muted); font-family: "Nunito", sans-serif; }
.lv .st { color: #ffd23f; letter-spacing: 3px; margin-top: auto; } .lv:disabled { opacity: 0.4; } .lv:not(:disabled):hover { border-color: var(--cyan); }
.lv.endless { background: linear-gradient(160deg, rgba(255, 79, 195, 0.2), rgba(95, 227, 255, 0.05)); }
.target { background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 10px 12px; font-size: 15px; line-height: 1.55; font-family: "Nunito", sans-serif; } .target b { color: var(--green); }
.big { width: 100%; margin-top: 14px; padding: 14px !important; font-size: 19px !important; text-align: center !important; border-radius: 12px; font-weight: 700; border: 0; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); } .srow input[type=range] { flex: 1; max-width: 170px; accent-color: var(--cyan); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; } .chip { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; font-weight: 700; font-size: 13.5px; } .chip.on { background: var(--cyan); color: #06121a; border-color: var(--cyan); }
.help { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; } .help p { font-size: 14px; line-height: 1.5; color: #dcd6f2; margin: 0 0 10px; font-family: "Nunito", sans-serif; }
.rh { margin: 2px 0 4px; font-size: 30px; font-weight: 700; letter-spacing: 0.5px; } .stars { color: #ffd23f; font-size: 26px; letter-spacing: 4px; text-shadow: 0 0 12px rgba(255, 210, 63, 0.5); }
.near { color: var(--amber); font-size: 14px; margin: 4px 0 0; font-family: "Nunito", sans-serif; }
.kv { list-style: none; padding: 0; margin: 12px 0 0; font-size: 14px; display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; font-family: "Nunito", sans-serif; }
.kv li { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; color: var(--muted); } .kv li b { color: var(--ink); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; position: sticky; bottom: -20px; background: var(--panel); padding: 6px 0; } .buttons button { flex: 1 1 140px; text-align: center; }
.e-board:empty { display: none; } .e-board { margin: 12px 0 0; font-family: "Nunito", sans-serif; }

@media (max-width: 1100px) { .bar { gap: 9px; } .m:nth-of-type(4) { display: none; } }
@media (max-height: 460px), (max-width: 760px) {
  .bar { gap: 7px; padding-top: max(4px, var(--sat)); padding-bottom: 4px; } .bar small { font-size: 9px; } .bar b { font-size: 13px; } .lvl small { display: none; } .lvl b { font-size: 12px; max-width: 90px; display: block; overflow: hidden; text-overflow: ellipsis; }
  .m.wide { min-width: 90px; } .pbar { min-width: 56px; } .speed button { padding: 2px 5px; font-size: 11px; } .menu-b { width: 30px; height: 30px; }
  .m:nth-of-type(4) { display: none; } .m.anger .pbar { min-width: 44px; }
  .tools { gap: 3px; padding: 4px; border-radius: 12px; } .tools button { width: 54px; padding: 3px 1px 2px; font-size: 9.5px; } .tools button i { font-size: 16px; } .tools button small { font-size: 9.5px; }
  .event { top: calc(max(4px, var(--sat)) + 46px); padding: 5px 12px; } .event b { font-size: 14px; } .event span { font-size: 11.5px; }
  .coach { top: calc(max(4px, var(--sat)) + 46px); max-width: 30vw; font-size: 12px; padding: 6px 9px; }
  .info { top: calc(max(4px, var(--sat)) + 46px); width: 170px; font-size: 11.5px; padding: 6px 8px; }
  #title.screen { gap: 14px; } .logo { font-size: 52px; } .lead { font-size: 13.5px; margin-bottom: 10px; line-height: 1.4; } .menu button { padding: 8px 14px; font-size: 15px; } .menu { gap: 6px; } .disclaimer { margin-top: 8px; font-size: 11px; }
  .t-side { width: 260px; } .t-side .gw-board { max-height: 62vh; overflow: auto; }
  .sheet { padding: 12px 14px; } .sheet h2 { font-size: 22px; } .lvls { gap: 6px; } .lv { min-height: 70px; padding: 6px 9px; } .lv b { font-size: 14px; } .lv span { font-size: 11px; }
  .help p { font-size: 12.5px; } .rh { font-size: 22px; } .kv { font-size: 12.5px; margin-top: 6px; }
}
@media (max-width: 760px) and (orientation: portrait) { .help { grid-template-columns: 1fr; } .lvls { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) and (orientation: portrait) {
  #title.screen { flex-direction: column; align-items: stretch; background: linear-gradient(180deg, rgba(9, 4, 20, 0.2), rgba(9, 4, 20, 0.92) 38%); }
  .t-main { margin: 30vh 0 0; } .t-side { width: 100%; margin: 0; }
}
