:root {
  --bg: #050505;
  --panel: rgba(12, 12, 15, 0.84);
  --panel-strong: rgba(20, 20, 24, 0.96);
  --text: #f5f0ea;
  --muted: #a69d95;
  --accent: #ff6b2c;
  --accent-2: #ffb347;
  --danger: #ff334a;
  --stroke: rgba(255, 255, 255, 0.14);
  --app-height: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  width: 100%;
  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); }
button { font: inherit; color: inherit; }
button:focus-visible { outline: 2px solid rgba(255, 163, 69, 0.95); outline-offset: 3px; }

#app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--app-height);
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 89, 28, 0.075), transparent 36%),
    radial-gradient(circle at 50% 50%, #1a1919 0%, #080808 47%, #020202 100%);
}
#app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  box-shadow: inset 0 0 110px rgba(0,0,0,0.92);
  background: linear-gradient(90deg, rgba(255,255,255,0.018), transparent 18%, transparent 82%, rgba(255,255,255,0.018));
}

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

.hidden { display: none !important; }

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(4, minmax(66px, 110px));
  gap: 6px;
  pointer-events: none;
}
.hud-cell {
  padding: 7px 10px 8px;
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 14px;
  background: rgba(0,0,0,0.33);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.34);
  min-width: 0;
  text-align: center;
}
.hud-cell span,
.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.hud-cell strong {
  display: block;
  margin-top: 1px;
  font-size: clamp(14px, 2.5vw, 19px);
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(86vw, 490px);
  max-height: calc(var(--app-height) - 24px);
  overflow: auto;
  z-index: 12;
  padding: 22px 24px 20px;
  border: 1px solid var(--stroke);
  border-radius: 28px;
  background:
    linear-gradient(160deg, rgba(255,255,255,0.035), transparent 32%),
    linear-gradient(180deg, var(--panel-strong), var(--panel));
  box-shadow: 0 28px 90px rgba(0,0,0,0.74), inset 0 1px rgba(255,255,255,0.05);
  text-align: center;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  scrollbar-width: none;
}
.panel::-webkit-scrollbar { display: none; }
.panel.visible { display: block; animation: panel-in 190ms ease-out; }

.mark {
  width: 76px;
  height: 52px;
  margin: 0 auto 7px;
  position: relative;
  filter: drop-shadow(0 0 20px rgba(255,102,38,0.30));
}
.mark span {
  position: absolute;
  width: 26px;
  height: 17px;
  border: 5px solid #2b2928;
  border-left-color: var(--accent);
  border-radius: 50%;
  transform: rotate(-13deg);
}
.mark span:nth-child(1) { left: 2px; top: 25px; }
.mark span:nth-child(2) { left: 18px; top: 15px; }
.mark span:nth-child(3) { left: 36px; top: 8px; }
.mark span:nth-child(4) { left: 52px; top: 1px; width: 18px; height: 15px; border-color: var(--accent); }

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.19em;
}
h1 {
  margin: 0;
  font-size: clamp(42px, 9vw, 69px);
  line-height: 0.76;
  letter-spacing: -0.075em;
  text-transform: uppercase;
}
h1 em { color: var(--accent); font-style: normal; }
h2 { margin: 3px 0 14px; font-size: clamp(35px, 7vw, 55px); letter-spacing: -0.06em; }
.tagline { margin: 17px 0 16px; color: var(--muted); font-weight: 780; letter-spacing: 0.025em; }
.hint { margin: 13px auto 0; max-width: 430px; color: var(--muted); font-size: 12px; line-height: 1.42; }
.hint b { color: var(--text); }
.install-hint { margin: 10px 0 0; color: rgba(255,164,81,0.80); font-size: 10px; letter-spacing: 0.04em; }

.primary, .secondary {
  width: 100%;
  border: 0;
  border-radius: 17px;
  padding: 13px 17px;
  margin-top: 9px;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #170801;
  box-shadow: 0 15px 38px rgba(255,95,31,0.24);
}
.secondary { background: rgba(255,255,255,0.07); border: 1px solid var(--stroke); }
.secondary.compact { padding: 10px 14px; font-size: 13px; }
.primary:active, .secondary:active, .icon-button:active, .burst:active { transform: translateY(1px) scale(0.985); }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 8px;
}
.result-grid > div {
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 16px;
  background: rgba(255,255,255,0.035);
}
.result-grid strong { display: block; margin-top: 2px; font-size: 26px; }

.icon-button {
  position: fixed;
  z-index: 8;
  width: 42px;
  height: 42px;
  border-radius: 15px;
  border: 1px solid var(--stroke);
  background: rgba(0,0,0,0.34);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.34);
  cursor: pointer;
  font-weight: 900;
}
.pause {
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
}
.fullscreen {
  top: max(10px, env(safe-area-inset-top));
  right: max(60px, calc(env(safe-area-inset-right) + 60px));
  font-size: 20px;
}

.joystick {
  position: fixed;
  left: max(24px, calc(env(safe-area-inset-left) + 24px));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 22px));
  width: 112px;
  height: 112px;
  border-radius: 50%;
  z-index: 7;
  pointer-events: none;
  border: 1px solid rgba(255,255,255,0.09);
  background: radial-gradient(circle, rgba(255,255,255,0.035), rgba(0,0,0,0.18) 68%, rgba(0,0,0,0.28));
  box-shadow: inset 0 0 34px rgba(0,0,0,0.5);
  opacity: 0.82;
}
.joystick::before, .joystick::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,0.075);
}
.joystick::before { left: 16px; right: 16px; top: 50%; height: 1px; }
.joystick::after { top: 16px; bottom: 16px; left: 50%; width: 1px; }
.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.14);
  background: radial-gradient(circle at 35% 30%, #58514c, #1b1a1a 58%, #080808 100%);
  box-shadow: 0 8px 24px rgba(0,0,0,0.44), 0 0 18px rgba(255,101,35,0.08);
  transition: transform 60ms linear;
}

.burst {
  position: fixed;
  right: max(25px, calc(env(safe-area-inset-right) + 25px));
  bottom: max(23px, calc(env(safe-area-inset-bottom) + 23px));
  width: 100px;
  height: 100px;
  z-index: 8;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: radial-gradient(circle at 42% 35%, #353131 0%, #121212 52%, #050505 100%);
  box-shadow: inset 0 0 28px rgba(0,0,0,0.55), 0 14px 34px rgba(0,0,0,0.46);
  cursor: pointer;
  overflow: hidden;
}
.burst-ring {
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.10);
  clip-path: polygon(50% 50%, 50% 0, 100% 0, 100% 100%, 0 100%, 0 0, 50% 0);
  pointer-events: none;
}
.burst b, .burst small { position: relative; z-index: 2; display: block; }
.burst b { color: var(--muted); font-size: 13px; letter-spacing: 0.10em; }
.burst small { margin-top: 2px; color: #766f69; font-size: 10px; font-weight: 900; }
.burst.ready {
  background: radial-gradient(circle at 42% 35%, #ffb34b, #ff672b 43%, #6d1708 72%, #160502 100%);
  box-shadow: inset 0 0 28px rgba(255,210,140,0.22), 0 0 34px rgba(255,85,20,0.34), 0 14px 34px rgba(0,0,0,0.46);
  animation: ready-pulse 900ms ease-in-out infinite alternate;
}
.burst.ready b, .burst.ready small { color: #190701; }
.burst.firing { transform: scale(0.94); }

.mode-badge {
  position: fixed;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
  transform: translateX(-50%);
  z-index: 7;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.30);
  color: var(--muted);
  font-size: 9px;
  font-weight: 950;
  letter-spacing: 0.14em;
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.mode-badge.frenzy { color: #fff2ef; border-color: rgba(255,65,72,0.38); background: rgba(170,10,22,0.62); box-shadow: 0 0 24px rgba(255,30,55,0.22); }
.mode-badge.bursting { color: #1b0701; border-color: rgba(255,255,255,0.22); background: linear-gradient(135deg, #ff6a2b, #ffc05d); }

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  padding: 11px 17px;
  border-radius: 999px;
  background: rgba(0,0,0,0.68);
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--text);
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 0.05em;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: none;
}

.rotate-card {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  place-content: center;
  justify-items: center;
  gap: 9px;
  padding: 30px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #282323, #080808 50%, #020202);
}
.phone-icon {
  width: 72px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 5px;
  border: 3px solid var(--accent);
  border-radius: 12px;
  color: var(--accent-2);
  font-size: 31px;
  box-shadow: 0 0 30px rgba(255,99,36,0.20);
}
.rotate-card strong { font-size: 20px; }
.rotate-card span { color: var(--muted); font-size: 13px; }

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-card { display: grid; }
}

@media (hover: hover) and (pointer: fine) {
  .joystick { opacity: 0.30; }
  .primary:hover { filter: brightness(1.06); }
  .secondary:hover { background: rgba(255,255,255,0.10); }
}

@media (max-height: 430px) {
  .panel { width: min(78vw, 470px); padding: 15px 19px 14px; border-radius: 23px; }
  .mark { transform: scale(0.78); margin-top: -8px; margin-bottom: -5px; }
  h1 { font-size: clamp(38px, 8vw, 58px); }
  .tagline { margin: 11px 0 9px; }
  .hint { font-size: 11px; margin-top: 9px; }
  .install-hint { margin-top: 6px; }
  .primary, .secondary { padding: 10px 14px; margin-top: 7px; }
  .joystick { width: 96px; height: 96px; }
  .burst { width: 88px; height: 88px; }
}

@keyframes panel-in { from { opacity: 0; transform: translate(-50%, -48%) scale(0.975); } }
@keyframes ready-pulse { to { box-shadow: inset 0 0 28px rgba(255,210,140,0.28), 0 0 48px rgba(255,85,20,0.48), 0 14px 34px rgba(0,0,0,0.46); } }
