:root {
  --bg: #090d16;
  --card: rgba(12, 16, 27, .86);
  --card-strong: rgba(19, 25, 40, .94);
  --text: #f7f8ff;
  --muted: #aeb7cc;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --danger: #ff4e62;
  --gold: #ffd166;
  --border: rgba(255,255,255,.14);
}
* { box-sizing: border-box; }
html, body, button, a, .button-link, .menu, .game-panel, canvas, .touch-button, .mobile-controls {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button, a, .button-link, canvas, .touch-button { touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }

html, body {
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}
body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(0,0,0,.70), rgba(0,0,0,.24));
  pointer-events: none;
}
.app-shell { position: relative; z-index: 1; width: min(1180px, calc(100% - 24px)); margin: 0 auto; padding: 28px 0; }
.card { width: min(820px,100%); margin: 24px auto; padding: 28px; border: 1px solid var(--border); border-radius: 28px; background: var(--card); backdrop-filter: blur(14px); box-shadow: 0 24px 80px rgba(0,0,0,.42); text-align: center; }
.top-row { display:flex; justify-content:flex-end; align-items:center; gap:12px; margin-bottom:12px; }
.feedback-link { color: var(--accent-2); text-decoration:none; font-weight:700; }
.top-links { display:flex; align-items:center; justify-content:flex-end; gap:12px; flex-wrap:wrap; }
.legal-link { color: var(--muted); }
.feedback-link:hover { text-decoration: underline; }
.game-logo { width: 140px; height: 140px; object-fit: cover; border-radius: 28px; box-shadow: 0 18px 40px rgba(0,0,0,.35); }
.eyebrow { margin: 18px 0 8px; color: var(--accent-2); text-transform: uppercase; letter-spacing: .18em; font-size: 12px; font-weight: 800; }
h1,h2,h3,p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(44px,8vw,82px); line-height: .95; }
h2 { font-size: clamp(30px,5vw,46px); }
h3 { margin-bottom: 14px; }
.muted { color: var(--muted); }
.small-text { font-size: 14px; }
.menu-actions { display: grid; gap: 12px; width: min(420px,100%); margin: 22px auto; }
.inline-actions { display:flex; justify-content:center; gap:12px; flex-wrap:wrap; }
button, select, .button-link { font: inherit; }
button, .button-link { border: 1px solid var(--border); border-radius: 16px; padding: 13px 18px; background: rgba(255,255,255,.08); color: var(--text); cursor: pointer; transition: transform .16s ease, background .16s ease, border-color .16s ease; text-decoration:none; display:inline-block; }
button:hover, .button-link:hover { transform: translateY(-2px); background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.28); }
button:disabled { opacity:.45; cursor:not-allowed; transform:none; }
.primary-button { border-color: transparent; background: linear-gradient(135deg,var(--accent),var(--accent-2)); color: white; font-weight: 800; }
.primary-button:hover { background: linear-gradient(135deg,#9279ff,#26dcff); }
.small-button { padding: 8px 12px; border-radius: 12px; }
.stats-grid { display:grid; grid-template-columns: repeat(3,1fr); gap:12px; margin-top:20px; }
.stat-box { padding:16px; border:1px solid var(--border); border-radius:18px; background: rgba(255,255,255,.07); }
.stat-box span { display:block; color: var(--muted); font-size:13px; }
.stat-box strong { display:block; margin-top:4px; font-size:30px; }
.message { margin-top:16px; padding:14px; border-radius:16px; background: rgba(255,255,255,.08); }
.danger { background: rgba(255,78,98,.22); border:1px solid rgba(255,78,98,.36); }
.feedback-prompt {
  position: fixed;
  inset: 0;
  z-index: 80;
  margin: 0;
  padding: 18px;
  border: 0;
  border-radius: 0;
  background: rgba(3, 6, 14, .72);
  backdrop-filter: blur(10px);
  align-content: center;
  justify-items: center;
  text-align: center;
}
.feedback-modal-card {
  width: min(620px, 100%);
  padding: 24px;
  border: 1px solid rgba(0,212,255,.28);
  border-radius: 22px;
  background: rgba(19,25,40,.96);
  box-shadow: 0 24px 80px rgba(0,0,0,.48);
}
.feedback-modal-card p { margin: 0 0 18px; font-size: 19px; line-height: 1.35; }

.achievement-toast { position: fixed; right:20px; bottom:20px; z-index:30; padding:14px 18px; border-radius:18px; color:#201600; background:var(--gold); box-shadow:0 12px 40px rgba(0,0,0,.35); font-weight:800; }
.settings-section { margin:18px 0; padding:18px; border:1px solid var(--border); border-radius:20px; background:rgba(255,255,255,.06); text-align:left; }
.setting-row { display:grid; grid-template-columns: 1fr auto auto auto auto; align-items:center; gap:10px; margin:10px 0; }
.two-columns { display:grid; grid-template-columns: 1fr 1fr; gap:14px; }
.two-columns label, .toggle-row { display:grid; grid-template-columns: 1fr auto; align-items:center; gap:12px; }
select { width:100%; padding:12px; border-radius:14px; border:1px solid var(--border); background:rgba(255,255,255,.1); color:var(--text); }
option { background:#111827; }
.background-preview { display:grid; grid-template-columns: repeat(auto-fit,minmax(130px,1fr)); gap:12px; }
.background-option { min-height:94px; padding:8px; display:grid; gap:8px; align-items:center; justify-items:center; }
.background-option img, .theme-swatch { width:100%; height:58px; object-fit:cover; border-radius:12px; display:block; }
.background-option.active { border-color: var(--accent-2); box-shadow:0 0 0 2px rgba(0,212,255,.22) inset; }
.skin-list { display:grid; grid-template-columns: repeat(auto-fit,minmax(160px,1fr)); gap:14px; margin-top:18px; }
.skin-card { display:grid; gap:10px; padding:14px; border:1px solid var(--border); border-radius:18px; background:rgba(255,255,255,.06); }
.skin-preview { width:46px; height:46px; margin:0 auto; border-radius:12px; box-shadow:0 8px 20px rgba(0,0,0,.28); }
#game-container { width:100%; touch-action:none; }
.game-panel { position:relative; width:min(100%, 980px); margin:0 auto; border:1px solid var(--border); border-radius:24px; overflow:hidden; background:rgba(0,0,0,.42); box-shadow:0 24px 80px rgba(0,0,0,.45); }
#gameCanvas { width:100%; aspect-ratio: 3 / 2; display:block; background:rgba(2,6,23,.45); touch-action:none; }
#hud { position:absolute; top:12px; left:12px; display:flex; gap:10px; flex-wrap:wrap; }
#hud div, #powerup-bar span { padding:8px 10px; border:1px solid var(--border); border-radius:999px; background:rgba(8,13,24,.72); backdrop-filter: blur(8px); }
#powerup-bar { position:absolute; top:12px; right:86px; display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; max-width:50%; }
.pause-game { position:absolute; right:12px; top:12px; padding:8px 12px; border-radius:999px; }
.warning-message { position:absolute; left:50%; bottom:22px; transform:translateX(-50%); width:min(620px, calc(100% - 24px)); padding:12px 14px; border-radius:16px; background:rgba(255,78,98,.22); border:1px solid rgba(255,78,98,.45); text-align:center; font-weight:700; }
.overlay, .tutorial-overlay { position:absolute; inset:0; display:grid; place-items:center; padding:28px; background:rgba(4,7,16,.78); backdrop-filter: blur(9px); text-align:center; }
.tutorial-overlay { align-items:center; justify-items:center; }
.tutorial-card { width:min(720px, calc(100% - 24px)); display:grid; gap:12px; justify-items:center; padding:28px; border:1px solid var(--border); border-radius:24px; background:rgba(10,15,27,.88); box-shadow:0 24px 70px rgba(0,0,0,.45); text-align:center; }
.tutorial-overlay p { max-width:650px; margin:0 auto; font-size:19px; line-height:1.45; color:var(--muted); text-align:center; }
.step-count { width:max-content; margin:0 auto; padding:6px 10px; border-radius:999px; color:var(--accent-2); background:rgba(0,212,255,.12); border:1px solid rgba(0,212,255,.22); font-weight:800; }
.countdown-overlay { position:absolute; inset:0; display:grid; place-items:center; font-size:90px; font-weight:900; color:white; background:rgba(4,7,16,.46); text-shadow:0 14px 42px rgba(0,0,0,.6); }
.modal-backdrop { position:fixed; inset:0; z-index:50; background:rgba(0,0,0,.72); display:grid; place-items:center; padding:20px; }
.modal-card { width:min(520px,100%); }
@media (max-width: 720px) {
  .card { padding:20px; border-radius:22px; }
  .stats-grid, .two-columns { grid-template-columns:1fr; }
  .setting-row { grid-template-columns:1fr; text-align:center; }
  #hud { font-size:13px; }
  #powerup-bar { top:58px; right:12px; max-width:calc(100% - 24px); }
  h1 { font-size:48px; }
  .game-logo { width:110px; height:110px; }
}

/* V6 refinements */
#main-menu h1 { line-height: 1.08; margin-bottom: 18px; }
#menu-subtitle { margin-top: 8px; }
.beta-notice { margin: 14px auto 0; max-width: 720px; background: rgba(255, 209, 102, .13); border: 1px solid rgba(255, 209, 102, .30); color: #ffe6a3; }
.setting-help { display: block; grid-column: 1 / -1; margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.two-columns label { align-content: start; }
.toggle-row { grid-template-columns: 1fr auto; }
.toggle-row .setting-help { padding-right: 20px; }
.tutorial-overlay { place-items: start center; padding-top: 18px; background: linear-gradient(180deg, rgba(4,7,16,.38), rgba(4,7,16,0)); backdrop-filter: none; pointer-events: none; }
.tutorial-card { width: min(760px, calc(100% - 24px)); padding: 16px 18px; gap: 8px; pointer-events: auto; background: rgba(10,15,27,.82); }
.tutorial-card h2 { font-size: clamp(22px, 3.4vw, 34px); margin-bottom: 2px; }
.tutorial-overlay p { font-size: 16px; line-height: 1.38; }
.tutorial-card .inline-actions { margin-top: 4px; }
.tutorial-card button { padding: 9px 14px; }
.step-count { font-size: 13px; padding: 4px 9px; }
@media (max-width: 720px) {
  #main-menu h1 { margin-bottom: 14px; }
  .tutorial-overlay { padding-top: 8px; }
  .tutorial-card { padding: 12px; }
}

/* V7 refinements */
.top-row { justify-content: space-between; }
.beta-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 209, 102, .35);
  background: rgba(255, 209, 102, .14);
  color: #ffe6a3;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .12em;
}
#beta-notice {
  max-width: 780px;
  line-height: 1.45;
}
#main-menu h1 {
  line-height: 1.12;
  margin-bottom: 24px;
}
#menu-subtitle {
  margin-top: 0;
}
.tutorial-overlay {
  place-items: center;
  padding: 28px;
  background: rgba(4,7,16,.78);
  backdrop-filter: blur(9px);
  pointer-events: auto;
}
.tutorial-card {
  width: min(760px, calc(100% - 24px));
  padding: 28px;
  gap: 12px;
  background: rgba(10,15,27,.92);
}
.tutorial-card h2 {
  font-size: clamp(30px, 5vw, 46px);
}
.tutorial-overlay p {
  font-size: 19px;
  line-height: 1.45;
}
@media (max-width: 720px) {
  .top-row { align-items: flex-start; gap: 10px; }
  .feedback-link { text-align: right; }
  #main-menu h1 { margin-bottom: 18px; }
  .tutorial-overlay { padding: 16px; }
  .tutorial-card { padding: 20px; }
}

/* Mobile quick fix: touch controls for phone/tablet browsers */
.mobile-controls {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  padding: 0 14px;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 12;
}
.touch-button {
  pointer-events: auto;
  width: clamp(74px, 22vw, 132px);
  height: clamp(74px, 22vw, 132px);
  border-radius: 999px;
  font-size: clamp(40px, 11vw, 68px);
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(255,255,255,.11);
  border: 1px solid rgba(255,255,255,.20);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0,0,0,.30);
  touch-action: none;
}
.touch-button:active, .touch-button.active {
  transform: scale(.96);
  background: rgba(0,212,255,.20);
  border-color: rgba(0,212,255,.48);
}
.mobile-hint {
  display:none;
  position:absolute;
  left:50%;
  bottom: 10px;
  transform:translateX(-50%);
  z-index: 11;
  width: min(520px, calc(100% - 190px));
  text-align:center;
  font-size: 12px;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(8,13,24,.60);
  border: 1px solid rgba(255,255,255,.10);
}
@media (pointer: coarse), (max-width: 900px) {
  body { overflow-x: hidden; }
  .app-shell { width: 100%; padding: max(10px, env(safe-area-inset-top)) 8px max(10px, env(safe-area-inset-bottom)); }
  .card { margin: 10px auto; padding: 18px; border-radius: 22px; }
  .game-panel { width: 100%; max-width: 100vw; border-radius: 18px; }
  #gameCanvas { height: min(68vh, calc(100vw * 0.6667)); min-height: 360px; }
  .mobile-controls { display: flex; }
  .mobile-hint { display: block; }
  #hud { top: 8px; left: 8px; gap: 6px; font-size: 13px; }
  #hud div, #powerup-bar span { padding: 6px 8px; }
  #powerup-bar { top: 48px; right: 8px; max-width: 58%; }
  .pause-game { top: 8px; right: 8px; padding: 7px 10px; }
  .warning-message { bottom: 104px; font-size: 13px; }
}
@media (max-width: 520px) {
  .top-row { flex-direction: column; align-items: stretch; }
  .top-links { justify-content: flex-start; }
  .stats-grid { grid-template-columns: 1fr; }
  .setting-row { grid-template-columns: 1fr; }
  .two-columns { grid-template-columns: 1fr; }
  #gameCanvas { min-height: 330px; height: 62vh; }
  .mobile-hint { width: calc(100% - 170px); bottom: 18px; }
}
@media (orientation: landscape) and (pointer: coarse) {
  .app-shell { padding: 6px; }
  #gameCanvas { height: calc(100vh - 16px); min-height: 0; aspect-ratio: auto; }
  .mobile-hint { bottom: 8px; }
}


/* Mobile Hotfix 2: better phone/tablet game view and no accidental text selection */
body.game-active {
  overflow: hidden;
  position: fixed;
  width: 100%;
  min-height: 100dvh;
}
@media (pointer: coarse), (max-width: 900px) {
  body.game-active .app-shell {
    width: 100%;
    max-width: none;
    height: 100dvh;
    margin: 0;
    padding: 0;
  }
  body.game-active #game-container {
    width: 100vw;
    height: 100dvh;
  }
  body.game-active .game-panel {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  body.game-active #gameCanvas {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    aspect-ratio: auto;
  }
  body.game-active #hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    max-width: calc(100% - 92px);
  }
  body.game-active #hud div {
    font-size: 12px;
    padding: 6px 8px;
  }
  body.game-active #powerup-bar {
    top: max(46px, calc(env(safe-area-inset-top) + 44px));
    right: max(8px, env(safe-area-inset-right));
    max-width: calc(100% - 16px);
  }
  body.game-active .pause-game {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }
  body.game-active .mobile-controls {
    bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  body.game-active .mobile-hint {
    bottom: max(18px, env(safe-area-inset-bottom));
    opacity: .86;
  }
}
@media (max-width: 520px) {
  .feedback-modal-card { padding: 20px; border-radius: 20px; }
  .feedback-modal-card p { font-size: 17px; }
  .feedback-modal-card .inline-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .feedback-modal-card .button-link, .feedback-modal-card button { width: 100%; }
}
