/* Prismfall: page, overlays and on-screen buttons. The game itself is drawn on the canvas. */
:root {
  --accent: #8f7bff;
  --accent2: #5ef0ff;
  --st: env(safe-area-inset-top, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden; background: #07081c; color: #fff;
  font-family: var(--font); overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none;
}
body { position: fixed; inset: 0; height: 100dvh; }
canvas#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#safe { position: fixed; top: var(--st); right: var(--sr); bottom: var(--sb); left: var(--sl); pointer-events: none; visibility: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* ---- Corner buttons ---- */
#corner { position: fixed; top: calc(var(--st) + 6px); right: calc(var(--sr) + 8px); display: flex; gap: 6px; z-index: 30; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(14, 16, 44, .62); border: 1px solid rgba(255, 255, 255, .16); color: #dfe5ff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(.92); background: rgba(60, 64, 130, .7); }
#btn-mute .off, body.muted #btn-mute .on { display: none; }
body.muted #btn-mute .off { display: block; }

/* ---- On-screen game buttons ---- */
#touch { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; gap: 10px;
  padding: 6px calc(8px + var(--sr)) calc(8px + var(--sb)) calc(8px + var(--sl)); pointer-events: none; }
.pad { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; pointer-events: auto; }
.pad button {
  height: 60px; min-width: 48px; border-radius: 16px; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(180deg, rgba(120, 130, 255, .26), rgba(40, 44, 110, .34));
  border: 1.5px solid rgba(190, 200, 255, .34); color: #f1f4ff;
  box-shadow: 0 4px 0 rgba(4, 5, 24, .55), inset 0 1px 0 rgba(255, 255, 255, .25);
  font-weight: 800; font-size: 13px; letter-spacing: .12em; touch-action: none;
}
.pad button svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.pad button.span2 { grid-column: span 2; }
.pad button.primary { background: linear-gradient(180deg, rgba(94, 240, 255, .4), rgba(60, 90, 200, .4)); border-color: rgba(150, 240, 255, .6); }
.pad button.pressed { transform: translateY(3px) scale(.97); box-shadow: 0 1px 0 rgba(4, 5, 24, .55), 0 0 18px rgba(130, 220, 255, .65); background: linear-gradient(180deg, rgba(170, 220, 255, .6), rgba(90, 110, 240, .55)); }
body.wide #touch { top: 0; display: block; padding: 0; }
body.wide .pad { position: absolute; bottom: calc(10px + var(--sb)); width: 148px; }
body.wide .pad-l { left: calc(10px + var(--sl)); }
body.wide .pad-r { right: calc(10px + var(--sr)); }
body.wide .pad button { height: 58px; }

/* ---- Overlay screens ---- */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--st) + 10px) calc(var(--sr) + 12px) calc(var(--sb) + 10px) calc(var(--sl) + 12px); overflow: hidden; }
.screen.dim { background: rgba(4, 5, 20, .66); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); z-index: 40; animation: fade .18s ease-out; }
#screen-title { background: radial-gradient(ellipse at 50% 40%, rgba(6, 7, 26, .8), rgba(4, 5, 20, .93)); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } }

.card {
  width: min(420px, 100%); max-height: 100%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  padding: 20px 20px 18px; border-radius: 22px; text-align: center;
  background: linear-gradient(180deg, rgba(34, 36, 88, .92), rgba(12, 13, 40, .94));
  border: 1px solid rgba(180, 190, 255, .28);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), 0 18px 60px rgba(0, 0, 0, .6), 0 0 50px rgba(120, 110, 255, .25), inset 0 1px 0 rgba(255, 255, 255, .16);
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.2);
}
.card h2 { margin: 0 0 14px; font-size: 26px; font-weight: 900; letter-spacing: .16em;
  background: linear-gradient(90deg, #7df9ff, #b59bff 55%, #ff7ac0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.col { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn {
  min-height: 46px; padding: 0 18px; border-radius: 14px; font-weight: 800; font-size: 15px; letter-spacing: .04em;
  background: linear-gradient(180deg, rgba(120, 128, 240, .3), rgba(50, 54, 130, .36)); border: 1px solid rgba(190, 200, 255, .32);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 3px 0 rgba(3, 4, 20, .5); transition: transform .08s, filter .12s;
}
.btn.big { min-height: 52px; font-size: 16px; flex: 1 1 auto; }
.btn.primary { background: linear-gradient(180deg, #8f7bff, #5a48e0); border-color: rgba(220, 215, 255, .7); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4), 0 3px 0 #2c2190, 0 0 24px rgba(143, 123, 255, .5); }
.btn.glow { background: linear-gradient(180deg, #32d9c8, #1a8fb0); border-color: rgba(200, 255, 250, .7); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4), 0 3px 0 #0b5670, 0 0 24px rgba(60, 230, 220, .5); width: 100%; margin: 4px 0 10px; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(2px) scale(.98); }

/* ---- Title ---- */
.chip { position: absolute; top: calc(var(--st) + 6px); left: calc(var(--sl) + 8px); height: 44px; padding: 0 14px 0 8px; border-radius: 22px;
  display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; max-width: 46vw;
  background: rgba(14, 16, 44, .7); border: 1px solid rgba(255, 255, 255, .2); }
.chip-avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; background: rgba(255, 255, 255, .12); }
.chip-avatar:empty::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: #cfd6ff; box-shadow: 0 11px 0 4px #cfd6ff; transform: translateY(-5px) scale(.8); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: clamp(14px, 4vh, 34px); width: min(520px, 100%); max-height: 100%; }
.brand { text-align: center; }
.logo-mark { width: clamp(46px, 11vh, 84px); filter: drop-shadow(0 0 16px rgba(150, 140, 255, .8)); animation: float 5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px) rotate(3deg); } }
.logo { margin: 2px 0 0; font-size: clamp(40px, 12.5vw, 84px); line-height: 1; font-weight: 900; letter-spacing: .06em; font-style: italic;
  background: linear-gradient(100deg, #7df9ff 5%, #9aa2ff 40%, #c58bff 60%, #ff73b9 95%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(140, 130, 255, .55)) drop-shadow(0 3px 0 rgba(10, 8, 50, .8)); padding: 0 .1em; }
.logo span { font-weight: 300; }
.tagline { margin: 8px 0 0; font-size: clamp(13px, 2.2vh, 17px); letter-spacing: .22em; text-transform: uppercase; color: rgba(220, 226, 255, .8); font-weight: 600; }
.menu { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu .preview-note { margin: 0; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.mode { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; padding: 14px 14px 12px; border-radius: 18px; min-height: 104px;
  background: linear-gradient(160deg, rgba(110, 100, 255, .42), rgba(30, 32, 90, .5)), #0e0f2c; border: 1.5px solid rgba(190, 200, 255, .3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 4px 0 rgba(3, 4, 20, .55); transition: transform .1s, box-shadow .15s, border-color .15s; }
.mode[data-mode="sprint"] { background: linear-gradient(160deg, rgba(40, 210, 220, .34), rgba(30, 32, 90, .5)), #0e0f2c; }
#screen-title .btn { background: linear-gradient(180deg, rgba(120, 128, 240, .34), rgba(50, 54, 130, .4)), #0e0f2c; }
.mode b { font-size: clamp(17px, 4.6vw, 22px); font-weight: 900; letter-spacing: .08em; }
.mode i { font-style: normal; font-size: 12.5px; line-height: 1.3; color: rgba(225, 230, 255, .78); }
.mode em { font-style: normal; margin-top: auto; font-size: 12px; font-weight: 800; letter-spacing: .06em; color: #ffe27a; }
.mode.selected { border-color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 4px 0 rgba(3, 4, 20, .55), 0 0 26px rgba(150, 140, 255, .75); }
.mode:hover { transform: translateY(-2px); }
.mode:active { transform: translateY(2px) scale(.98); }
.hint { margin: 2px 0 0; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: rgba(220, 226, 255, .7); animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }
.preview-note { margin: 8px 0 0; font-size: 11.5px; color: rgba(200, 208, 255, .5); }

/* ---- Results ---- */
.results h2 { margin-bottom: 6px; }
.badge { display: inline-block; margin: 2px 0 4px; padding: 5px 14px; border-radius: 999px; font-weight: 900; font-size: 13px; letter-spacing: .14em; color: #2a1600;
  background: linear-gradient(90deg, #ffe66b, #ffa93a); box-shadow: 0 0 22px rgba(255, 200, 80, .8); animation: badge 0.9s ease-in-out infinite alternate; }
@keyframes badge { to { transform: scale(1.08) rotate(-1.5deg); } }
.res-score small { display: block; font-size: 11px; letter-spacing: .2em; font-weight: 800; color: rgba(210, 220, 255, .7); }
.res-score strong { display: block; font-size: clamp(38px, 11vw, 56px); line-height: 1.05; font-weight: 900; letter-spacing: .01em; text-shadow: 0 0 26px rgba(140, 160, 255, .7); font-variant-numeric: tabular-nums; }
.res-best { margin: 2px 0 8px; font-size: 13px; color: rgba(215, 222, 255, .75); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0 0 10px; }
.stats div { padding: 7px 2px 6px; border-radius: 10px; background: rgba(255, 255, 255, .06); }
.stats b { display: block; font-size: 17px; font-weight: 800; }
.stats span { display: block; font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: rgba(210, 220, 255, .65); }
.rank { margin: 0 0 8px; font-size: 16px; font-weight: 800; }
.rank.podium { font-size: 19px; background: linear-gradient(90deg, #ffe66b, #ff9de0, #7df9ff); -webkit-background-clip: text; background-clip: text; color: transparent; animation: badge .8s ease-in-out infinite alternate; }
.rank small { display: block; font-size: 12px; font-weight: 700; color: #8dfcc7; -webkit-text-fill-color: #8dfcc7; }
.res-note { margin: -2px 0 8px; font-size: 12px; color: rgba(205, 213, 255, .62); }
.res-note.bad { color: #ffb1b1; }
.top { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 3px; text-align: left; }
.top li { display: grid; grid-template-columns: 26px 26px 1fr auto; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 9px; background: rgba(255, 255, 255, .05); font-size: 14px; font-weight: 700; }
.top li .r { color: rgba(210, 220, 255, .6); font-variant-numeric: tabular-nums; }
.top li .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top li .n small { margin-left: 6px; font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; opacity: .6; }
.top li.guest .n { opacity: .78; }
.top li .s { font-variant-numeric: tabular-nums; }
.top li.me { background: linear-gradient(90deg, rgba(143, 123, 255, .5), rgba(94, 240, 255, .28)); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .45); }
.top li.gap { background: none; padding: 0 10px; height: 10px; color: rgba(210, 220, 255, .4); display: block; text-align: center; line-height: 6px; }
.confirm-text { margin: 0 0 4px; font-size: 16px; font-weight: 700; }

/* ---- Settings ---- */
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 50px; padding: 2px 0; text-align: left; font-weight: 700; font-size: 15px; }
.field.stack { flex-direction: column; align-items: stretch; gap: 8px; margin: 6px 0 14px; }
.field input[type=range] { flex: 0 1 190px; min-width: 0; height: 44px; accent-color: var(--accent); touch-action: pan-x; }
.toggle { position: relative; width: 60px; height: 44px; flex: none; }
.toggle::before { content: ""; position: absolute; left: 3px; right: 3px; top: 8px; bottom: 8px; border-radius: 14px; background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .22); transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 11px; left: 7px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle[aria-checked=true]::before { background: linear-gradient(90deg, #7b68ff, #5ef0ff); }
.toggle[aria-checked=true]::after { transform: translateX(24px); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { min-height: 46px; padding: 4px 6px; border-radius: 12px; font-size: 12.5px; font-weight: 800; line-height: 1.15; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .18); }
.seg button.on { background: linear-gradient(180deg, #8f7bff, #5a48e0); border-color: #fff; }

/* ---- How to play ---- */
.howto { width: min(560px, 100%); }
.howto p { margin: 0 0 12px; font-size: 14.5px; line-height: 1.45; color: rgba(232, 236, 255, .92); }
.howto p.small { font-size: 12.5px; color: rgba(210, 218, 255, .7); }
.howto .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; text-align: left; margin-bottom: 10px; }
.howto h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: #9fdcff; }
.keys { list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 1.95; color: rgba(225, 230, 255, .9); }
.keys b { color: #fff; margin-right: 4px; }
kbd { display: inline-block; min-width: 22px; padding: 0 6px; margin-right: 3px; border-radius: 6px; text-align: center; font: 700 12px var(--font); line-height: 20px; background: rgba(255, 255, 255, .13); border: 1px solid rgba(255, 255, 255, .28); border-bottom-width: 2px; }
.rainbow { background: linear-gradient(90deg, #ff6b6b, #ffd166, #6bffb0, #6bd0ff, #c58bff); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---- Small and sideways screens ---- */
@media (max-height: 520px) and (orientation: landscape) {
  .title-wrap { flex-direction: row; width: min(860px, 100%); gap: 24px; align-items: center; }
  .brand { flex: 1; }
  .menu { flex: 1.15; gap: 8px; }
  .logo { font-size: clamp(28px, 5.4vw, 52px); }
  .tagline { font-size: 11px; letter-spacing: .16em; }
  .logo-mark { width: 44px; }
  .mode { min-height: 88px; padding: 10px 12px; }
  .card { padding: 12px 16px; width: min(560px, 100%); }
  .card h2 { font-size: 20px; margin-bottom: 8px; }
  .col { display: grid; grid-template-columns: 1fr 1fr; }
  .confirm-text { grid-column: span 2; }
  .field { min-height: 44px; }
  .results { width: min(640px, 100%); }
  .howto p { font-size: 13px; margin-bottom: 8px; }
  .keys { line-height: 1.7; font-size: 12.5px; }
}
@media (max-width: 480px) {
  .tagline { letter-spacing: .12em; font-size: 12px; }
  .results .row .primary { flex-basis: 100%; }
}
@media (max-width: 360px) {
  .mode i { font-size: 11.5px; }
  .btn { padding: 0 12px; font-size: 14px; }
}
