:root {
  --bg: #050505;
  --panel: rgba(12, 12, 14, 0.76);
  --panel-strong: rgba(18, 18, 22, 0.92);
  --text: #f4efe8;
  --muted: #a8a09a;
  --accent: #ff6a2a;
  --accent-soft: rgba(255, 106, 42, 0.24);
  --stroke: rgba(255, 255, 255, 0.14);
  --shadow: rgba(0, 0, 0, 0.55);
  --app-height: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body {
  height: var(--app-height);
  min-height: var(--app-height);
}

button { font: inherit; color: inherit; -webkit-touch-callout: none; }
button:focus-visible { outline: 2px solid rgba(255, 155, 54, 0.9); outline-offset: 3px; }

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--app-height);
  min-height: var(--app-height);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 106, 42, 0.08), transparent 27%),
    radial-gradient(circle at 50% 20%, #24201f 0%, #080808 42%, #020202 100%);
  isolation: isolate;
}

#app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025), transparent 18%, transparent 82%, rgba(255,255,255,0.025)),
    radial-gradient(circle at 50% 0%, rgba(255,255,255,0.055), transparent 42%);
  z-index: 1;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100vw;
  height: var(--app-height);
  z-index: 0;
  touch-action: none;
}

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  z-index: 5;
  pointer-events: none;
  opacity: 0.96;
}

.hud > div {
  padding: 9px 10px;
  border: 1px solid var(--stroke);
  border-radius: 15px;
  background: rgba(0, 0, 0, 0.30);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 26px var(--shadow);
  min-width: 0;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.hud strong {
  display: block;
  margin-top: 1px;
  font-size: clamp(15px, 3.6vw, 20px);
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-badge {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  z-index: 6;
  padding: 8px 11px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  background: rgba(0,0,0,0.36);
  color: rgba(244,239,232,0.92);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 0.10em;
  pointer-events: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.mode-badge.heavy { color: #160802; background: linear-gradient(135deg, #ff6a2a, #ffb34b); border-color: rgba(255,255,255,0.22); }
.mode-badge.overdrive { color: #fff3ef; background: linear-gradient(135deg, #bb1118, #ff4b2a); border-color: rgba(255,255,255,0.25); }
.mode-badge.hidden { display: none; }

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(91vw, 430px);
  max-height: calc(var(--app-height) - max(28px, env(safe-area-inset-top)) - max(28px, env(safe-area-inset-bottom)));
  overflow: auto;
  padding: 28px 22px 22px;
  border: 1px solid var(--stroke);
  border-radius: 30px;
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.68);
  text-align: center;
  z-index: 10;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  scrollbar-width: none;
}
.panel::-webkit-scrollbar { display: none; }
.panel.hidden { display: none; }
.panel.visible { display: block; animation: pop 180ms ease-out; }

.logo {
  width: 78px;
  height: 78px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 25px;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.16), transparent 22%),
    radial-gradient(circle at 35% 30%, #4d4d4d, #141414 58%, #050505 100%);
  border: 1px solid rgba(255,255,255,0.16);
  color: var(--accent);
  font-size: 38px;
  text-shadow: 0 0 26px var(--accent);
  box-shadow: inset 0 0 28px rgba(0,0,0,0.55), 0 20px 40px rgba(0,0,0,0.42);
}

h1 { margin: 0; font-size: clamp(40px, 12vw, 62px); letter-spacing: -0.06em; line-height: 0.92; }
h2 { margin: 0 0 10px; font-size: 34px; letter-spacing: -0.04em; }
.tagline { margin: 10px 0 22px; color: var(--accent); font-weight: 900; letter-spacing: 0.03em; }
.hint { margin: 15px auto 0; color: var(--muted); max-width: 338px; font-size: 14px; line-height: 1.45; }
.install-hint { margin: 12px auto 0; color: rgba(255, 155, 54, 0.88); max-width: 340px; font-size: 12px; line-height: 1.35; }
#finalScore { margin: 8px 0 0; font-size: 22px; font-weight: 850; }
#finalBest { margin: 4px 0 18px; color: var(--muted); }

.primary,
.secondary {
  width: 100%;
  border: 0;
  border-radius: 18px;
  padding: 15px 18px;
  margin-top: 10px;
  cursor: pointer;
  font-weight: 850;
  letter-spacing: -0.02em;
}
.primary {
  background: linear-gradient(135deg, var(--accent), #ff9b36);
  color: #160802;
  box-shadow: 0 15px 35px rgba(255, 106, 42, 0.26);
}
.secondary { background: rgba(255, 255, 255, 0.08); color: var(--text); border: 1px solid var(--stroke); }
.secondary.compact { padding: 11px 16px; font-size: 14px; opacity: 0.92; }
.primary:active,
.secondary:active,
.icon-button:active { transform: translateY(1px) scale(0.99); }

.icon-button {
  position: fixed;
  width: 52px;
  height: 52px;
  border-radius: 18px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 7;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(0,0,0,0.34);
}
.pause {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 14px));
}
.fullscreen {
  right: max(74px, calc(env(safe-area-inset-right) + 74px));
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 14px));
  font-size: 22px;
  line-height: 1;
}
.icon-button.hidden { display: none; }

.touch-cue {
  position: fixed;
  left: 50%;
  bottom: max(78px, calc(env(safe-area-inset-bottom) + 78px));
  transform: translateX(-50%);
  z-index: 4;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(0,0,0,0.24);
  color: rgba(244,239,232,0.55);
  border: 1px solid rgba(255,255,255,0.09);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.13em;
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.touch-cue.hidden { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(82px, calc(env(safe-area-inset-bottom) + 82px));
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.58);
  border: 1px solid var(--stroke);
  color: var(--text);
  z-index: 11;
  white-space: nowrap;
}
.toast.hidden { display: none; }

@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@media (display-mode: standalone) {
  .install-hint,
  #fullscreenStartBtn { display: none; }
}

@media (max-width: 430px) {
  .hud { gap: 6px; }
  .hud > div { padding: 8px 9px; border-radius: 14px; }
  .label { font-size: 9px; }
  .panel { width: min(92vw, 398px); padding-left: 20px; padding-right: 20px; }
  .icon-button { width: 50px; height: 50px; border-radius: 17px; }
  .fullscreen { right: max(70px, calc(env(safe-area-inset-right) + 70px)); }
}

@media (max-height: 670px) {
  .panel { padding: 20px 18px 18px; border-radius: 25px; }
  .logo { width: 58px; height: 58px; border-radius: 19px; font-size: 30px; margin-bottom: 9px; }
  h1 { font-size: clamp(34px, 10vw, 52px); }
  .tagline { margin-bottom: 14px; }
  .hint { font-size: 13px; margin-top: 12px; }
  .install-hint { font-size: 11px; margin-top: 8px; }
  .hud > div { padding: 7px 8px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .hud { top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); right: auto; width: min(44vw, 360px); }
  .panel { width: min(72vw, 430px); }
  .touch-cue { display: none; }
}
