:root {
  --bg1: #101820;
  --bg2: #1b2e40;
  --panel: rgba(13, 21, 29, 0.86);
  --panel-soft: rgba(255, 255, 255, 0.08);
  --text: #f2f5f8;
  --muted: #aeb8c2;
  --accent: #ffb100;
  --accent-2: #ff5a00;
  --success: #6ce07e;
  --danger: #ff6161;
  --shadow: 0 16px 42px rgba(0,0,0,0.35);
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Arial, Helvetica, sans-serif; background: radial-gradient(circle at top, #274765, #101820 70%); color: var(--text); }
body { padding: 16px; }
button, select { font: inherit; }
.app { max-width: 1400px; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.brand { font-size: 28px; font-weight: 800; letter-spacing: 0.02em; }
.topbar-actions { display: flex; gap: 10px; }
.game-shell { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.07); border-radius: 24px; padding: 14px; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.hud { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.hud-item { background: var(--panel); border: 1px solid rgba(255,255,255,0.08); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 72px; }
.hud-item span { color: var(--muted); font-size: 13px; }
.hud-item strong { font-size: 20px; }
.stage-wrap { position: relative; border-radius: 22px; overflow: hidden; background: #000; aspect-ratio: 16/9; user-select: none; }
#gameCanvas { width: 100%; height: 100%; display: block; cursor: none; }
.center-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, rgba(0,0,0,0.12), rgba(0,0,0,0.52)); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.center-overlay.visible { opacity: 1; pointer-events: auto; }
.panel { background: var(--panel); border: 1px solid rgba(255,255,255,0.08); border-radius: var(--radius); box-shadow: var(--shadow); }
.intro-panel { max-width: 680px; padding: 26px 30px; text-align: center; }
.intro-panel h1 { margin: 0 0 12px; font-size: 34px; }
.intro-panel p { color: var(--muted); line-height: 1.55; margin: 0 0 18px; }
.intro-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.intro-grid div { background: var(--panel-soft); border-radius: 12px; padding: 12px; }
.intro-actions, .modal-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.primary-btn, .secondary-btn, .ghost-btn, .icon-btn { border: 0; border-radius: 12px; cursor: pointer; transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease; }
.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.primary-btn { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #111; font-weight: 800; padding: 12px 20px; }
.secondary-btn { background: rgba(255,255,255,0.12); color: var(--text); font-weight: 700; padding: 12px 20px; }
.ghost-btn { background: rgba(255,255,255,0.08); color: var(--text); padding: 10px 14px; }
.icon-btn { width: 40px; height: 40px; background: rgba(255,255,255,0.08); color: var(--text); font-size: 26px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.54); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; }
.modal.hidden { display: none; }
.modal-panel { width: min(760px, 100%); padding: 24px; }
.rules-panel { width: min(680px, 100%); }
.records-panel { width: min(760px, 100%); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 28px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 10px; }
.form-grid span { color: var(--muted); font-size: 14px; }
.form-grid select { background: rgba(255,255,255,0.08); color: var(--text); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 12px 14px; }
.form-grid select option { color: #101820; background: #ffffff; }
.form-grid select:focus { outline: 2px solid rgba(255,177,0,0.6); outline-offset: 2px; }
.settings-info { background: rgba(255,255,255,0.07); border-radius: 14px; padding: 14px; line-height: 1.6; color: var(--muted); margin-bottom: 16px; }
.rules-list { margin: 0; padding-left: 20px; color: var(--muted); display: grid; gap: 10px; line-height: 1.55; }
#floatingTextLayer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floating-text { position: absolute; transform: translate(-50%, -50%); font-size: 30px; font-weight: 800; text-shadow: 0 3px 12px rgba(0,0,0,0.45); animation: floatUp 0.9s ease forwards; white-space: nowrap; }
.floating-good { color: #ffd86d; }
.floating-bad { color: #ff7676; }
.floating-info { color: #70d7ff; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  10% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -120px) scale(1.1); }
}
.crosshair { position: absolute; width: 68px; height: 68px; transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: opacity 0.12s ease; z-index: 4; }
.stage-wrap:hover .crosshair { opacity: 1; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; inset: 0; }
.crosshair-0::before { border: 4px solid rgba(142, 244, 93, 0.95); border-radius: 50%; box-shadow: 0 0 16px rgba(142,244,93,0.45); }
.crosshair-0::after { inset: 22px; border: 3px solid rgba(142, 244, 93, 0.95); border-radius: 50%; }
.crosshair-1::before { border-radius: 50%; border: 3px dashed rgba(87, 196, 255, 0.95); box-shadow: 0 0 16px rgba(87,196,255,0.45); }
.crosshair-1::after { background: linear-gradient(transparent 31px, rgba(87,196,255,0.95) 31px, rgba(87,196,255,0.95) 37px, transparent 37px), linear-gradient(90deg, transparent 31px, rgba(87,196,255,0.95) 31px, rgba(87,196,255,0.95) 37px, transparent 37px); }
.crosshair-2::before { border: 4px solid rgba(255, 71, 151, 0.98); border-radius: 16px; transform: rotate(45deg); box-shadow: 0 0 18px rgba(255,71,151,0.45); }
.crosshair-2::after { background: radial-gradient(circle at center, rgba(255,71,151,1) 0 3px, transparent 4px), linear-gradient(transparent 31px, rgba(255,71,151,0.92) 31px, rgba(255,71,151,0.92) 37px, transparent 37px), linear-gradient(90deg, transparent 31px, rgba(255,71,151,0.92) 31px, rgba(255,71,151,0.92) 37px, transparent 37px); }
.crosshair-3::before { inset: 8px; border-radius: 50%; border: 4px solid rgba(255, 211, 71, 0.98); box-shadow: 0 0 18px rgba(255,211,71,0.45); }
.crosshair-3::after { background: conic-gradient(from 0deg, rgba(255,211,71,0.95) 0 5%, transparent 5% 20%, rgba(255,211,71,0.95) 20% 25%, transparent 25% 45%, rgba(255,211,71,0.95) 45% 50%, transparent 50% 70%, rgba(255,211,71,0.95) 70% 75%, transparent 75% 95%, rgba(255,211,71,0.95) 95% 100%); mask: radial-gradient(circle at center, transparent 0 24px, #000 24px); }
.crosshair-4::before { background: linear-gradient(transparent 33px, rgba(255,76,76,0.96) 33px, rgba(255,76,76,0.96) 35px, transparent 35px), linear-gradient(90deg, transparent 33px, rgba(255,76,76,0.96) 33px, rgba(255,76,76,0.96) 35px, transparent 35px); box-shadow: 0 0 18px rgba(255,76,76,0.42); }
.crosshair-4::after { inset: 24px; border-radius: 50%; border: 2px solid rgba(255,76,76,0.96); }
@media (max-width: 1100px) {
  .hud { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  body { padding: 10px; }
  .brand { font-size: 22px; }
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .record-row { grid-template-columns: 44px 1fr; }
  .record-row.record-head { display: none; }
  .mode-chip-grid { grid-template-columns: 1fr; }
  .intro-panel { padding: 20px; }
  .intro-panel h1 { font-size: 28px; }
  .intro-grid { grid-template-columns: 1fr; }
}

.records-list { display: grid; gap: 10px; max-height: 420px; overflow: auto; margin-bottom: 16px; }
.record-row { display: grid; grid-template-columns: 60px 1fr 120px 110px 90px; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,0.07); }
.record-row.record-head { font-weight: 700; color: var(--muted); background: rgba(255,255,255,0.04); position: sticky; top: 0; }
.record-rank { font-weight: 800; color: var(--accent); }
.empty-records { color: var(--muted); padding: 16px; background: rgba(255,255,255,0.05); border-radius: 14px; }
.status-badge { display: inline-flex; align-items: center; justify-content: center; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,0.12); font-size: 12px; font-weight: 700; }
.status-live { background: rgba(108,224,126,0.16); color: #9af4a5; }
.status-paused { background: rgba(255,177,0,0.18); color: #ffd56c; }
.status-police { background: rgba(255,97,97,0.20); color: #ff9b9b; }
.mode-chip-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; margin: 14px 0 18px; }
.mode-chip { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.08); border-radius: 14px; padding: 12px; }
.mode-chip b { display: block; margin-bottom: 6px; }
.police-flash { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: screen; z-index: 3; }
.stage-wrap.police-active .police-flash { animation: policeSiren 0.5s linear infinite; }
@keyframes policeSiren {
  0% { background: linear-gradient(90deg, rgba(255,0,0,0.22) 0 50%, rgba(0,120,255,0.0) 50% 100%); }
  50% { background: linear-gradient(90deg, rgba(255,0,0,0.0) 0 50%, rgba(0,120,255,0.22) 50% 100%); }
  100% { background: linear-gradient(90deg, rgba(255,0,0,0.22) 0 50%, rgba(0,120,255,0.0) 50% 100%); }
}


/* v8 fullscreen + smartphone adaptation */
html,
body {
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  overscroll-behavior: none;
}

body {
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  overflow: hidden;
  touch-action: none;
}

.app {
  width: 100%;
  max-width: none;
  min-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  margin-bottom: 8px;
}

.game-shell {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px;
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: auto;
  height: calc(100dvh - 168px);
}

#gameCanvas {
  width: 100%;
  height: 100%;
}

.hud {
  flex: 0 0 auto;
}

.stage-wrap:fullscreen,
.stage-wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  background: #000;
}

.stage-wrap:fullscreen #gameCanvas,
.stage-wrap:-webkit-full-screen #gameCanvas {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.stage-wrap:fullscreen .center-overlay,
.stage-wrap:-webkit-full-screen .center-overlay,
.stage-wrap:fullscreen #floatingTextLayer,
.stage-wrap:-webkit-full-screen #floatingTextLayer {
  position: absolute;
  inset: 0;
}

.mobile-controls {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  pointer-events: none;
  z-index: 7;
}

.mobile-fire-btn,
.mobile-pause-btn,
.mobile-fullscreen-btn {
  pointer-events: auto;
  border: 1px solid rgba(255,255,255,0.20);
  color: var(--text);
  background: rgba(13, 21, 29, 0.68);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.28);
}

.mobile-fire-btn {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  font-size: 34px;
  font-weight: 900;
  background: radial-gradient(circle at 35% 28%, rgba(255,255,255,0.24), transparent 22%),
              linear-gradient(135deg, rgba(255,177,0,0.88), rgba(255,90,0,0.86));
  color: #111;
}

.mobile-side-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mobile-pause-btn,
.mobile-fullscreen-btn {
  min-width: 60px;
  min-height: 48px;
  border-radius: 16px;
  font-size: 22px;
}

@media (pointer: coarse), (max-width: 860px) {
  body {
    padding: 6px;
  }

  .topbar {
    gap: 8px;
    margin-bottom: 6px;
  }

  .brand {
    font-size: clamp(16px, 4.8vw, 22px);
  }

  .topbar-actions {
    gap: 6px;
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 2px;
  }

  .ghost-btn {
    padding: 9px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .game-shell {
    padding: 6px;
    border-radius: 16px;
  }

  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    margin-bottom: 6px;
  }

  .hud-item {
    min-height: 44px;
    padding: 6px 7px;
    border-radius: 10px;
    gap: 2px;
  }

  .hud-item span {
    font-size: 10px;
  }

  .hud-item strong {
    font-size: 13px;
    line-height: 1.1;
  }

  .stage-wrap {
    border-radius: 14px;
    height: calc(100dvh - 126px);
  }

  .mobile-controls {
    display: flex;
  }

  .intro-panel {
    max-width: min(94vw, 680px);
    max-height: 88dvh;
    overflow: auto;
    padding: 16px;
  }

  .intro-panel h1 {
    font-size: clamp(22px, 7vw, 34px);
  }

  .intro-panel p {
    font-size: 14px;
  }

  .intro-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .intro-grid div {
    padding: 8px;
    font-size: 13px;
  }

  .intro-actions {
    gap: 8px;
  }

  .primary-btn,
  .secondary-btn {
    min-height: 44px;
    padding: 10px 13px;
  }

  .modal {
    padding: 8px;
  }

  .modal-panel {
    max-height: 92dvh;
    overflow: auto;
    padding: 16px;
  }

  .form-grid {
    gap: 10px;
  }

  .crosshair {
    width: 58px;
    height: 58px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .topbar {
    display: none;
  }

  .hud {
    position: absolute;
    top: max(6px, env(safe-area-inset-top));
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    z-index: 6;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    opacity: 0.88;
  }

  .game-shell {
    padding: 0;
    border: none;
    background: transparent;
  }

  .stage-wrap {
    height: calc(100dvh - 12px);
    border-radius: 0;
  }

  .hud-item {
    min-height: 38px;
  }

  .hud-item span {
    font-size: 9px;
  }

  .hud-item strong {
    font-size: 12px;
  }
}

@media (max-width: 520px) {
  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-wrap {
    height: calc(100dvh - 210px);
  }

  .mobile-fire-btn {
    width: 82px;
    height: 82px;
  }

  .intro-grid {
    grid-template-columns: 1fr;
  }
}
