/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0f1a;
  --bg2:       #14172a;
  --text:      #e8e8f2;
  --text-dim:  #6b6f8a;
  --gold:      #f0c040;
  --gold-glow: rgba(240,192,64,.55);
  --blue:      #4aa8ff;
  --blue-glow: rgba(74,168,255,.55);
  --red:       #ff4455;
  --red-glow:  rgba(255,68,85,.55);
  --green:     #3ddc84;
  --green-glow:rgba(61,220,132,.55);
  --grey:      #4a4e6a;
  --radius:    12px;
  --dot-size:  clamp(64px, 17vw, 88px);
}

html, body {
  width: 100%; min-height: 100%;
  background: var(--bg);
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  overflow-x: hidden;
}

/* ── Flash overlay ───────────────────────────────────────────────────────── */
.flash-overlay {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 999;
  opacity: 0; transition: opacity .1s;
}
.flash-overlay.flash-success { background: var(--green); animation: flashIn .35s ease; }
.flash-overlay.flash-fail    { background: var(--red);   animation: flashIn .35s ease; }
.flash-overlay.flash-target  { background: var(--gold);  animation: flashIn .3s ease; }

@keyframes flashIn {
  0%   { opacity: .35; }
  100% { opacity: 0; }
}

/* ── App layout ──────────────────────────────────────────────────────────── */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.level-label  { font-size: 11px; font-weight: 800; letter-spacing: .15em; color: var(--text-dim); }
.phase-label  {
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  padding: 3px 10px; border-radius: 20px;
  background: rgba(255,255,255,.08); color: var(--text-dim);
  transition: background .3s, color .3s;
}
.phase-label.confirm { background: rgba(74,168,255,.2); color: var(--blue); }
.phase-label.success { background: rgba(61,220,132,.2); color: var(--green); }

.click-badge {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg2); border-radius: 10px;
  padding: 6px 14px; min-width: 52px;
}
.click-badge #click-count { font-size: 22px; font-weight: 900; line-height: 1; color: var(--gold); }
.click-badge .click-label { font-size: 9px; letter-spacing: .1em; color: var(--text-dim); }
.click-badge.bump { animation: bumpAnim .25s cubic-bezier(.36,.07,.19,.97); }

@keyframes bumpAnim {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── Info bar ────────────────────────────────────────────────────────────── */
.info-bar {
  width: 100%;
  display: flex; gap: 8px; align-items: stretch;
}
.info-chip {
  flex: 1;
  background: var(--bg2); border-radius: var(--radius);
  padding: 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.chip-label { font-size: 9px; letter-spacing: .12em; color: var(--text-dim); font-weight: 700; }
.chip-value { font-size: 15px; font-weight: 800; color: var(--text); }
.hazard-value { color: var(--red); }
.target-value { color: var(--gold); font-size: 20px; }

.timer-chip { flex: 2; }
#timer-bar {
  width: 100%; height: 8px;
  background: rgba(255,255,255,.08); border-radius: 4px; overflow: hidden;
}
#timer-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--gold), #ff9020);
  border-radius: 4px;
  transform-origin: left;
}

/* ── Message box ─────────────────────────────────────────────────────────── */
#message-box {
  width: 100%; text-align: center;
  background: var(--bg2); border-radius: var(--radius);
  padding: 12px 16px; min-height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.msg-main { font-size: 15px; font-weight: 700; color: var(--text); }
.msg-sub  { font-size: 12px; color: var(--text-dim); }

/* ── Dot grid ────────────────────────────────────────────────────────────── */
#dot-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--dot-size));
  gap: clamp(8px, 2.5vw, 14px);
}

/* ── Dot button ──────────────────────────────────────────────────────────── */
.dot {
  width: var(--dot-size); height: var(--dot-size);
  border: none; border-radius: 50%;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, filter .2s ease;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
}
.dot:active { transform: scale(.88) !important; }

.dot-num {
  font-size: 13px; font-weight: 800;
  color: rgba(255,255,255,.65);
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  position: relative; z-index: 1;
}

/* ── Dot states ──────────────────────────────────────────────────────────── */

/* idle */
.dot.idle {
  background-image: url('assets/buttons/dot_grey.png');
  box-shadow: 0 4px 0 rgba(0,0,0,.4), 0 0 0 0 transparent;
  filter: brightness(.7);
}
.dot.idle:hover { transform: scale(1.08); filter: brightness(.9); }

/* target */
.dot.target {
  background-image: url('assets/buttons/dot_yellow.png');
  filter: brightness(1.1);
  animation: targetPulse 1.2s ease-in-out infinite;
}
@keyframes targetPulse {
  0%, 100% { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 16px 4px var(--gold-glow); transform: scale(1); }
  50%       { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 32px 10px var(--gold-glow); transform: scale(1.07); }
}

/* dead */
.dot.dead {
  background-image: url('assets/buttons/dot_red.png');
  filter: brightness(1.0);
  animation: deadPulse 1.6s ease-in-out infinite;
}
@keyframes deadPulse {
  0%, 100% { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 10px 2px var(--red-glow); }
  50%       { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 24px 8px var(--red-glow); }
}

/* trail — lit by a passing sequence */
.dot.trail {
  background-image: url('assets/buttons/dot_blue.png');
  filter: brightness(1.2);
  animation: trailPop .3s cubic-bezier(.34,1.56,.64,1) forwards, trailGlow .5s ease forwards;
}
@keyframes trailPop {
  0%   { transform: scale(.7); }
  100% { transform: scale(1.05); }
}
@keyframes trailGlow {
  0%   { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 0 0 var(--blue-glow); }
  50%  { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 28px 10px var(--blue-glow); }
  100% { box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 14px 4px var(--blue-glow); }
}

/* confirm — idle state in confirm phase */
.dot.confirm-idle {
  background-image: url('assets/buttons/dot_grey_flat.png');
  filter: brightness(.45);
  transition: transform .12s, filter .2s;
}
.dot.confirm-idle:hover { filter: brightness(.75); transform: scale(1.06); }

/* confirm — correctly tapped */
.dot.confirm-ok {
  background-image: url('assets/buttons/dot_green.png');
  animation: confirmOk .3s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes confirmOk {
  0%   { transform: scale(.8); box-shadow: 0 0 0 0 var(--green-glow); }
  60%  { transform: scale(1.15); box-shadow: 0 0 24px 8px var(--green-glow); }
  100% { transform: scale(1.0);  box-shadow: 0 0 12px 4px var(--green-glow); }
}

/* confirm — wrong tap */
.dot.confirm-err {
  background-image: url('assets/buttons/dot_red.png');
  animation: confirmErr .4s ease;
}
@keyframes confirmErr {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-8px); }
  40%     { transform: translateX(8px); }
  60%     { transform: translateX(-5px); }
  80%     { transform: translateX(5px); }
}

/* dead hit */
.dot.hit-dead {
  animation: hitDead .5s ease;
}
@keyframes hitDead {
  0%   { transform: scale(1.3); filter: brightness(2); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* bounce — out-of-bounds click */
.dot.bounce {
  animation: bounceAnim .4s cubic-bezier(.36,.07,.19,.97);
}
@keyframes bounceAnim {
  0%,100% { transform: scale(1); }
  30%     { transform: scale(.75) rotate(-4deg); }
  70%     { transform: scale(1.1) rotate(2deg); }
}

/* success — level complete cascade */
.dot.success-pop {
  background-image: url('assets/buttons/dot_green.png');
  animation: successPop .5s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes successPop {
  0%   { transform: scale(0); filter: brightness(2); }
  70%  { transform: scale(1.2); }
  100% { transform: scale(1); filter: brightness(1.1); }
}

/* ── Legend ──────────────────────────────────────────────────────────────── */
.legend {
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
}
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-dim); }
.legend-dot  { width: 12px; height: 12px; border-radius: 50%; }
.legend-grey  { background: var(--grey); }
.legend-gold  { background: var(--gold); }
.legend-red   { background: var(--red);  }
.legend-blue  { background: var(--blue); }

/* ── Restart button ──────────────────────────────────────────────────────── */
.btn-restart {
  background: transparent; border: 1px solid rgba(255,255,255,.1);
  color: var(--text-dim); border-radius: 8px;
  padding: 8px 20px; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.btn-restart:hover { border-color: rgba(255,255,255,.3); color: var(--text); }

/* ── Level complete overlay ──────────────────────────────────────────────── */
#level-complete {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.8);
  align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.complete-card {
  background: var(--bg2);
  border-radius: 20px;
  padding: 32px 40px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  border: 1px solid rgba(255,255,255,.08);
  animation: slideUp .35s cubic-bezier(.34,1.56,.64,1);
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.complete-card h2 { font-size: 20px; color: var(--gold); }

.complete-stars {
  display: flex; gap: 8px; align-items: center;
}
.complete-stars .star { width: 44px; height: 44px; opacity: .25; transition: all .3s; }
.complete-stars .star-earned {
  opacity: 1;
  animation: starEarn .5s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes starEarn {
  0%   { transform: scale(0) rotate(-30deg); }
  70%  { transform: scale(1.3) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}
.complete-stars .star:nth-child(1) { animation-delay: .1s; }
.complete-stars .star:nth-child(2) { animation-delay: .25s; }
.complete-stars .star:nth-child(3) { animation-delay: .4s; }

.complete-clicks { font-size: 13px; color: var(--text-dim); }

.btn-next {
  padding: 14px 40px;
  background: var(--gold); color: #111;
  font-size: 16px; font-weight: 800; letter-spacing: .06em;
  border: none; border-radius: 12px; cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  box-shadow: 0 4px 0 #a07800;
}
.btn-next:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 #a07800; }
.btn-next:active { transform: translateY(2px);  box-shadow: 0 2px 0 #a07800; }

/* ── Screen management ───────────────────────────────────────────────────── */
.screen {
  display: none;
  position: fixed; inset: 0;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: block; }

/* ── Main Menu ───────────────────────────────────────────────────────────── */
#screen-menu {
  background:
    radial-gradient(ellipse at 30% 40%, rgba(240,192,64,0.06), transparent 50%),
    radial-gradient(ellipse at 70% 60%, rgba(74,168,255,0.06), transparent 50%),
    var(--bg);
}
.menu-inner {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 36px; padding: 40px 24px;
}
.menu-logo { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.menu-title {
  font-size: clamp(36px, 12vw, 56px);
  font-weight: 900; letter-spacing: .08em;
  background: linear-gradient(135deg, var(--gold) 20%, #ffdd70 50%, var(--blue));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px var(--gold-glow));
}
.menu-sub { font-size: 11px; letter-spacing: .2em; color: var(--text-dim); text-transform: uppercase; }

.menu-dots { display: flex; gap: 22px; align-items: center; }
.deco-dot  {
  width: 48px; height: 48px; border-radius: 50%; display: block;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  -webkit-appearance: none; appearance: none; border: none;
}
.d-gold  { background-image: url('assets/buttons/dot_yellow.png'); box-shadow: 0 0 22px 6px var(--gold-glow);  animation: dotFloat 2.4s ease-in-out infinite; }
.d-blue  { background-image: url('assets/buttons/dot_blue.png');   box-shadow: 0 0 22px 6px var(--blue-glow);  animation: dotFloat 2.4s ease-in-out infinite .3s; }
.d-red   { background-image: url('assets/buttons/dot_red.png');    box-shadow: 0 0 22px 6px var(--red-glow);   animation: dotFloat 2.4s ease-in-out infinite .6s; }
.d-green { background-image: url('assets/buttons/dot_green.png');  box-shadow: 0 0 22px 6px var(--green-glow); animation: dotFloat 2.4s ease-in-out infinite .9s; }
@keyframes dotFloat {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 260px; }
.btn-primary {
  padding: 16px; border-radius: 14px;
  background: linear-gradient(135deg, var(--gold), #ffb020);
  color: #111;
  font-size: 18px; font-weight: 800; letter-spacing: .04em;
  border: none; cursor: pointer;
  box-shadow: 0 4px 0 #a07800, 0 0 20px var(--gold-glow);
  transition: transform .1s, box-shadow .1s;
  -webkit-appearance: none; appearance: none;
}
.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 #a07800, 0 0 28px var(--gold-glow); }
.btn-primary:active { transform: translateY(2px);  box-shadow: 0 2px 0 #a07800, 0 0 14px var(--gold-glow); }
.btn-secondary {
  padding: 14px; border-radius: 14px;
  background: var(--bg2); color: var(--text);
  font-size: 16px; font-weight: 700;
  border: 1px solid rgba(255,255,255,.1); cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.btn-secondary:hover { border-color: var(--blue); box-shadow: 0 0 12px var(--blue-glow); }

/* ── Level Select ────────────────────────────────────────────────────────── */
.levels-inner {
  padding: 16px; max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
}
.levels-header { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.levels-title  { font-size: 18px; font-weight: 800; }

.btn-back {
  background: transparent; border: none;
  color: var(--text-dim); font-size: 14px; cursor: pointer;
  padding: 6px 0; transition: color .15s;
  -webkit-appearance: none; appearance: none;
}
.btn-back:hover { color: var(--text); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.level-btn {
  background: var(--bg2); border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px; padding: 12px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s;
  -webkit-appearance: none; appearance: none;
  min-height: 76px;
}
.level-btn:hover:not(:disabled) {
  border-color: var(--gold);
  box-shadow: 0 0 14px var(--gold-glow);
  transform: translateY(-2px);
}
.level-btn.locked { opacity: 0.3; cursor: default; filter: grayscale(.6); }
.ls-num  { font-size: 18px; font-weight: 900; color: var(--gold); line-height: 1; }
.ls-name { font-size: 8px; color: var(--text-dim); text-align: center; line-height: 1.3; }
.ls-stars { display: flex; gap: 1px; }
.ls-star-full  { color: var(--gold); font-size: 10px; text-shadow: 0 0 6px var(--gold-glow); }
.ls-star-empty { color: var(--text-dim); font-size: 10px; opacity: .4; }
.ls-lock { font-size: 12px; }

/* ── In-game menu button ──────────────────────────────────────────────────── */
.btn-back-inline {
  background: transparent; border: none;
  color: var(--text-dim); font-size: 18px; cursor: pointer;
  padding: 4px 8px 4px 0; line-height: 1;
  transition: color .15s;
  -webkit-appearance: none; appearance: none;
}
.btn-back-inline:hover { color: var(--text); }

/* ── Confirm progress ─────────────────────────────────────────────────────── */
.confirm-progress {
  font-size: 14px; font-weight: 800;
  color: var(--blue); letter-spacing: .08em;
  margin-top: 2px;
}

/* ── Menu link in complete card ───────────────────────────────────────────── */
.btn-menu-link {
  background: transparent; border: none;
  color: var(--text-dim); font-size: 13px; cursor: pointer;
  padding: 4px; transition: color .15s;
  -webkit-appearance: none; appearance: none;
}
.btn-menu-link:hover { color: var(--text); }
