:root {
  --brand: #ffcb05;
  --ink: #222222;
  --night: #07091a;
  --glass: rgba(12, 15, 34, 0.74);
  --line: rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(circle at 50% 30%, #1b2150, var(--night) 70%);
}

body {
  display: flex;
  justify-content: center;
  color: #fff;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

#stage {
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: min(100vw, 60vh);
  width: min(100vw, 60dvh);
  overflow: hidden;
  touch-action: none;
  background: #0b1026;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#boostfx { opacity: 0; }

#fps {
  position: absolute;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 6;
  padding: 4px 9px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.6);
  font: 600 12px/1.2 ui-monospace, Menlo, monospace;
  pointer-events: none;
}

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px 6px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.pill {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 78px;
  padding: 5px 16px 5px 6px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
}
.pill.bad { justify-self: end; min-width: 0; gap: 3px; padding: 7px 12px; }
.pill.bad svg path { fill: rgba(255, 255, 255, 0.18); }
.pill.bad svg rect, .pill.bad svg circle { fill: rgba(255, 255, 255, 0.35); }
.pill.bad svg.on path { fill: #ef4444; stroke: #fff; stroke-width: 1.4; stroke-linejoin: round; }
.pill.bad svg.on rect, .pill.bad svg.on circle { fill: #fff; }
.pill.bad.last { border-color: #f87171; box-shadow: 0 0 18px rgba(239, 68, 68, 0.6); }
.pill b { font-size: 22px; font-weight: 800; line-height: 1; }
.pill canvas { width: 34px; height: 34px; }
.pill svg { width: 24px; height: 24px; margin: 3px 0; }

.clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
}
.clock b { font-size: 34px; font-weight: 900; letter-spacing: -0.02em; line-height: 1; }
.clock span { font-size: 13px; font-weight: 800; opacity: 0.9; }


#boost {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 70px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px 10px;
  border-radius: 16px;
  background: rgba(21, 128, 61, 0.82);
  border: 1px solid rgba(187, 247, 208, 0.6);
  box-shadow: 0 0 26px rgba(74, 222, 128, 0.55);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
#boost i { display: block; height: 4px; margin-top: 6px; border-radius: 9px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
#boost em { display: block; height: 100%; background: #bbf7d0; transform-origin: left center; }

#count {
  position: absolute;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: min(34vw, 20vh);
  font-weight: 900;
  line-height: 1;
  color: var(--brand);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 40px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
#count.word { font-size: min(15vw, 9vh); color: #fff; }

#mute {
  position: absolute;
  right: 12px;
  top: max(12px, env(safe-area-inset-top));
  width: 42px;
  height: 42px;
  padding: 9px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  color: #fff;
  z-index: 5;
  cursor: pointer;
}
#stage.live #mute { top: auto; right: auto; left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
#mute svg { width: 100%; height: 100%; display: block; }
#mute .cross { display: none; }
#mute.off .cross { display: inline; }
#mute.off .waves { display: none; }

.screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(max(16px, env(safe-area-inset-bottom)) + 4px);
  background: linear-gradient(180deg, rgba(7, 9, 26, 0.5) 0%, rgba(7, 9, 26, 0.08) 30%, rgba(7, 9, 26, 0.08) 40%, rgba(7, 9, 26, 0.82) 58%, rgba(7, 9, 26, 0.97) 74%);
}
#stage.fps .screen { padding-bottom: calc(max(16px, env(safe-area-inset-bottom)) + 38px); }
#result { justify-content: center; background: rgba(7, 9, 26, 0.64); }

.top { text-align: center; margin-top: 2vh; }
.logo {
  display: block;
  width: 104px;
  height: auto;
  margin: 0 auto;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.45));
}

h1 {
  margin: 14px 0 0;
  font-size: min(24vw, 14vh);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.04em;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.28), 0 14px 40px rgba(0, 0, 0, 0.5);
}
.record { display: inline-block; margin: 10px 0 0; padding: 5px 12px; border-radius: 99px; background: rgba(12, 15, 34, 0.6); border: 1px solid var(--line); font-size: 13px; font-weight: 800; color: var(--brand); }
.lead { margin: 8px 0 0; font-size: 16px; font-weight: 600; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7); }

.panel { padding: 0 4px; }

.legend { list-style: none; margin: 0 0 22px; padding: 0; display: grid; gap: 14px; }
.legend li { display: flex; align-items: center; gap: 14px; }
.ico { position: relative; flex: none; width: 52px; height: 48px; display: grid; place-items: center; }
.ico canvas { width: 66px; height: 66px; flex: none; }
.ico.trio canvas { position: absolute; width: 46px; height: 46px; }
.ico.trio canvas:nth-child(1) { left: -9px; top: -5px; }
.ico.trio canvas:nth-child(2) { left: 17px; top: -9px; }
.ico.trio canvas:nth-child(3) { left: 4px; top: 13px; }
.txt { display: grid; gap: 2px; min-width: 0; }
.txt b { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.txt span { font-size: 13.5px; line-height: 1.3; color: rgba(255, 255, 255, 0.7); }
.legend li.bad .txt span { color: #fca5a5; }

.btn {
  display: block;
  width: 100%;
  padding: 17px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--brand);
  color: var(--ink);
  font: inherit;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -0.01em;
  box-shadow: 0 5px 0 #b98f00, 0 14px 28px rgba(255, 203, 5, 0.22);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b98f00, 0 6px 14px rgba(255, 203, 5, 0.18); }
.btn:focus-visible, .credit a:focus-visible, #mute:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
@media (hover: hover) {
  .btn:hover { filter: brightness(1.06); }
}
.hint { margin: 16px 0 0; text-align: center; font-size: 12.5px; color: rgba(255, 255, 255, 0.6); }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 2px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
}

@media (max-height: 700px) {
  .logo { width: 86px; }
  h1 { margin-top: 8px; font-size: min(20vw, 12vh); }
  .lead { font-size: 14px; }
  .legend { gap: 8px; margin-bottom: 14px; }
  .ico { height: 40px; }
  .ico canvas { width: 56px; height: 56px; }
  .btn { padding: 14px; }
  .hint { margin-top: 10px; }
}
