:root {
  color-scheme: dark;
  --ink: #f8f7ff;
  --muted: #b8b8d3;
  --deep: #080a22;
  --panel: #14163d;
  --panel-2: #1b1e4a;
  --line: rgba(255,255,255,.1);
  --lime: #c9ff59;
  --pink: #ff6eb4;
  --violet: #8d72ff;
  --cyan: #51e5ff;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: var(--deep);
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -20%, #363477 0, transparent 42%),
    linear-gradient(180deg, #101235 0%, #07091e 100%);
}

button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

.app-shell {
  width: 414px;
  height: 766px;
  flex-shrink: 0;
  transform: scale(var(--game-scale, 1));
  transform-origin: center;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: 10px 12px;
  position: relative;
  background: linear-gradient(180deg, rgba(21,23,64,.94), rgba(7,9,30,.98));
  box-shadow: 0 0 80px rgba(0,0,0,.45);
  isolation: isolate;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.app-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  background-image: radial-gradient(circle, rgba(255,255,255,.9) 0 1px, transparent 1.5px);
  background-size: 37px 37px;
  mask-image: linear-gradient(#000, transparent 70%);
  z-index: -1;
}

.topbar {
  min-height: 52px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
}

.level-block { text-align: center; line-height: 1; }
.level-block strong { display: block; font-size: 1.45rem; margin-top: 2px; }
.eyebrow { font-size: .69rem; letter-spacing: .18em; color: var(--muted); font-weight: 800; }

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.07);
  color: var(--ink);
  font-weight: 900;
  font-size: 1.15rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-button:active { transform: scale(.94); }

.score-strip {
  display: grid;
  grid-template-columns: 1fr 1.8fr 1fr;
  align-items: center;
  min-height: 46px;
  padding: 5px 10px 8px;
  border-bottom: 1px solid var(--line);
}
.score-strip div { display: flex; flex-direction: column; gap: 3px; }
.score-strip div:last-child { text-align: right; }
.score-strip .goal { text-align: center; }
.score-strip span { font-size: .62rem; letter-spacing: .13em; color: var(--muted); font-weight: 800; }
.score-strip strong { font-size: .95rem; }
.score-strip .goal strong { font-size: .78rem; color: var(--lime); }

.game-wrap {
  min-height: 0;
  position: relative;
  overflow: hidden;
  border-radius: 0 0 28px 28px;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.danger-label {
  position: absolute;
  bottom: 112px;
  right: 8px;
  font-size: .55rem;
  letter-spacing: .12em;
  color: rgba(255,255,255,.28);
  pointer-events: none;
}

.controls {
  min-height: 58px;
  display: grid;
  grid-template-columns: 94px 1fr 94px;
  gap: 8px;
  align-items: center;
  padding-top: 8px;
}

.pill-button {
  min-height: 42px;
  border-radius: 15px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255,255,255,.07);
  font-weight: 800;
  cursor: pointer;
}
.pill-button:active { transform: translateY(1px); background: rgba(255,255,255,.12); }
.tip { text-align: center; font-size: .73rem; line-height: 1.25; color: var(--muted); }

.game-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5,7,25,.74);
  backdrop-filter: blur(8px);
  z-index: 5;
  animation: fade-in .25s ease both;
}
.game-message.hidden, .hidden { display: none !important; }
.message-card {
  width: min(100%, 310px);
  text-align: center;
  padding: 28px 22px 20px;
  border-radius: 28px;
  background: linear-gradient(145deg, #272a64, #15173e);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 24px 60px rgba(0,0,0,.45), inset 0 1px rgba(255,255,255,.12);
}
.message-spark { font-size: 2.6rem; color: var(--lime); filter: drop-shadow(0 0 14px rgba(201,255,89,.7)); }
.message-card h1 { margin: 6px 0 7px; font-size: 1.7rem; }
.message-card p { color: var(--muted); line-height: 1.5; margin: 0 0 20px; }

.primary-button {
  width: 100%;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 17px;
  color: #16182c;
  background: var(--lime);
  font-weight: 900;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(201,255,89,.2);
}
.primary-button:active { transform: translateY(2px); }
.text-button { color: var(--muted); border: 0; background: transparent; margin-top: 14px; padding: 8px; font-weight: 800; }

dialog {
  width: min(calc(100vw - 28px), 440px);
  max-height: min(760px, calc(100dvh - 30px));
  padding: 22px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 28px;
  color: var(--ink);
  background: linear-gradient(160deg, #222558, #111332);
  box-shadow: 0 30px 90px rgba(0,0,0,.65);
  overflow: auto;
}
dialog::backdrop { background: rgba(3,4,18,.76); backdrop-filter: blur(7px); }
.dialog-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.dialog-head h2 { margin: 4px 0 18px; font-size: 1.65rem; }
.close-button { flex: 0 0 auto; font-size: 1.5rem; }
.guide-grid { display: grid; gap: 10px; }
.guide-item { display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: center; background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.07); border-radius: 18px; padding: 11px 13px; }
.guide-item > b { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: #6e58ef; }
.guide-item p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.35; }
.guide-item strong { color: var(--ink); }
.install-card { margin-top: 16px; padding: 16px; border-radius: 18px; background: rgba(81,229,255,.09); border: 1px solid rgba(81,229,255,.18); }
.install-card p { color: var(--muted); line-height: 1.45; margin: 7px 0 13px; font-size: .9rem; }
.privacy-note { margin: 15px 4px 0; color: var(--muted); font-size: .78rem; text-align: center; line-height: 1.4; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.size-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0; }
.size-setting select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
