*,
*::before,
*::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  overflow: hidden;
  background: #0b0410;
  color: #f3e7d6;
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body {
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

button { font-family: inherit; user-select: none; -webkit-user-select: none; }

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0b0410;
}

/* ---------------- HUD ---------------- */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 10px;
  min-height: 48px;
  background: linear-gradient(#1d0b28, #120616);
  border-bottom: 2px solid #4b1e6b;
  box-shadow: 0 4px 0 rgba(0,0,0,.45);
  z-index: 30;
  position: relative;
}

.hud-cluster { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto; }

.hud-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 6px;
  border: 1px solid #6b3a8f;
  background: #241030;
  color: #e6cfae;
  padding: 0;
  cursor: pointer;
  transition: background .12s, transform .1s;
}
.hud-btn:hover { background: #341843; }
.hud-btn:active { transform: scale(.94); background: #431d57; }
.hud-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 2px; }

.hud-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .04em;
  color: #ffd166;
  background: #1b0a24;
  border: 1px solid #3d1a53;
  border-radius: 6px;
  padding: 4px 7px;
  line-height: 1;
  white-space: nowrap;
}

.hud-zone {
  flex: 1 1 auto;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #d9c2ea;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
  min-width: 0;
}

.hud-eyes { flex-direction: column; align-items: flex-end; gap: 3px; }

.hud-eye-label {
  font-size: 12px;
  font-weight: 700;
  color: #e2d3f2;
  white-space: nowrap;
  line-height: 1;
}
.hud-eye-label b { color: #7ef7a8; font-size: 14px; }
.hud-eye-label span { color: #8d76a3; font-size: 11px; }

.pips { display: flex; gap: 3px; }
.pip {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #2a1338;
  border: 1px solid #4a2263;
  transition: background .2s, box-shadow .2s, transform .2s;
}
.pip.on {
  background: #7ef7a8;
  border-color: #b6ffcf;
  box-shadow: 0 0 6px #7ef7a8;
  transform: scale(1.12);
}

/* ---------------- STAGE ---------------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #1a0722;
}

#scene {
  display: block;
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.crt {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,.16) 0px, rgba(0,0,0,.16) 1px, rgba(0,0,0,0) 1px, rgba(0,0,0,0) 3px);
  mix-blend-mode: multiply;
  opacity: .55;
  z-index: 4;
}

.flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: #e10600;
  z-index: 6;
}
.flash.fire { animation: flashfade .45s ease-out; }
.flash.white { background: #ffffff; }
@keyframes flashfade {
  0% { opacity: .85; }
  100% { opacity: 0; }
}

.zone-banner {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(20px, 6vw, 34px);
  font-weight: 900;
  color: #ffe9bd;
  text-shadow: 0 0 18px rgba(193,39,45,.9), 0 3px 0 #3b0d16;
  letter-spacing: .01em;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  white-space: nowrap;
}
.zone-banner.show { animation: bannerpop 2.2s ease-out; }
@keyframes bannerpop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.86); }
  15% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.05); }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: min(92%, 460px);
  background: rgba(18, 6, 22, .92);
  border: 1px solid #6b3a8f;
  border-inline-start: 4px solid #ffd166;
  border-radius: 8px;
  padding: 9px 13px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  color: #f6ead9;
  text-align: center;
  z-index: 7;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.55);
}
.toast.hidden { display: none; }

/* ---------------- CONTROLS ---------------- */
.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px 12px;
  background: linear-gradient(#120616, #08030c);
  border-top: 1px solid #2c1038;
  z-index: 25;
}

.ctl-group { display: flex; align-items: flex-end; }

.joy {
  --joy: clamp(84px, 20vh, 128px);
  position: relative;
  width: var(--joy);
  height: var(--joy);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, rgba(123,60,160,.30), rgba(18,6,24,.85) 70%);
  border: 2px solid rgba(193,39,45,.55);
  box-shadow: inset 0 0 20px rgba(0,0,0,.75), 0 0 14px rgba(91,42,134,.35);
  touch-action: none;
  cursor: grab;
}
.joy:active { cursor: grabbing; }

.joy-ring {
  position: absolute;
  inset: 16%;
  border-radius: 50%;
  border: 1px dashed rgba(214,178,255,.18);
  pointer-events: none;
}

.joy-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 46%; height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #f2e5d0, #9a72ad 62%, #2f1638);
  border: 2px solid rgba(255,209,102,.55);
  box-shadow: 0 4px 10px rgba(0,0,0,.6);
  transform: translate(-50%, -50%);
  will-change: transform;
  pointer-events: none;
}

.act-btn {
  --sz: clamp(62px, 13vh, 86px);
  width: var(--sz);
  height: var(--sz);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 2px solid #8e2b2b;
  background: radial-gradient(circle at 50% 35%, #7c1d2c, #3b0c17 72%);
  color: #ffd9a8;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 5px 0 #240710, inset 0 0 14px rgba(0,0,0,.6);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s, filter .12s;
  touch-action: none;
}
.act-btn:active, .act-btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #240710, inset 0 0 14px rgba(0,0,0,.7);
  filter: brightness(1.25);
}
.act-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 3px; }
.act-btn.cool { filter: grayscale(.6) brightness(.7); }

/* ---------------- OVERLAYS ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 0%, rgba(91,42,134,.55), rgba(10,3,14,.94) 62%),
    rgba(8,2,12,.92);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none !important; }

.panel {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, rgba(31,12,42,.97), rgba(15,5,20,.98));
  border: 2px solid #5b2a86;
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(255,209,102,.10), 0 18px 50px rgba(0,0,0,.7), inset 0 0 40px rgba(91,42,134,.16);
  padding: 18px 18px 20px;
  text-align: center;
  margin: auto;
  animation: panelin .34s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes panelin {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to { opacity: 1; transform: none; }
}

.small-panel { max-width: 340px; }
.win-panel { max-width: 380px; }

.eyebrow {
  font-size: 10.5px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: #a274c4;
  font-weight: 700;
  margin-bottom: 4px;
}

.title {
  margin: 0;
  font-size: clamp(30px, 10vw, 46px);
  font-weight: 900;
  letter-spacing: .12em;
  line-height: 1;
  color: #f7e6c8;
  text-shadow: 0 0 24px rgba(193,39,45,.75), 0 4px 0 #5b0f1a, 0 6px 18px rgba(0,0,0,.8);
}

.subtitle {
  margin: 8px 0 0;
  font-size: 13px;
  color: #c9a9e0;
  font-weight: 500;
}

.start-art { display: flex; justify-content: center; margin: 14px 0 6px; }

.eye-art {
  width: 96px; height: 62px;
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  background: radial-gradient(circle at 50% 46%, #fdf6e8 0%, #efe3c8 58%, #b49bc6 100%);
  display: grid; place-items: center;
  box-shadow: 0 0 26px rgba(46,196,241,.4), inset 0 0 16px rgba(91,42,134,.55);
  border: 2px solid #4b1e6b;
  animation: eyewob 5s ease-in-out infinite;
}
@keyframes eyewob {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(.08); }
}
.eye-iris {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #0b0410 0%, #0b0410 34%, #2ec4f1 36%, #1c7fa3 78%, #0d3a4c 100%);
  box-shadow: 0 0 12px rgba(46,196,241,.85);
  animation: irismove 7s ease-in-out infinite;
}
@keyframes irismove {
  0%, 100% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
}

.blurb {
  font-size: 13.5px;
  line-height: 1.65;
  color: #cdbcdd;
  margin: 10px 0 16px;
}

.primary-btn {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 2px solid #d8a04a;
  border-radius: 8px;
  background: linear-gradient(180deg, #c1272d, #7d1219);
  color: #fff4dd;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 5px 0 #43060d, 0 0 22px rgba(193,39,45,.42);
  transition: transform .1s, box-shadow .1s, filter .14s;
  padding: 12px;
}
.primary-btn:hover { filter: brightness(1.1); }
.primary-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #43060d; }
.primary-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 3px; }

.ghost-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: 1px solid #5b2a86;
  border-radius: 8px;
  background: rgba(30,12,42,.8);
  color: #cbb3e0;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 10px;
  transition: background .14s, transform .1s;
}
.ghost-btn:hover { background: rgba(48,20,66,.9); }
.ghost-btn:active { transform: scale(.98); }
.ghost-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 3px; }

.how { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; text-align: start; }
.how-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12px;
  line-height: 1.5;
  color: #b9a3cd;
  background: rgba(0,0,0,.28);
  border: 1px solid #35164a;
  border-radius: 7px;
  padding: 8px 10px;
}
.how-row .k {
  flex: 0 0 auto;
  color: #ffd166;
  font-weight: 700;
  font-size: 11px;
  border-inline-end: 1px solid #4b1e6b;
  padding-inline-end: 8px;
}

.panel-title { margin: 4px 0 10px; font-size: 22px; font-weight: 900; color: #f2e0c6; }
.muted { font-size: 13px; color: #a992bd; margin: 6px 0 14px; line-height: 1.55; }

.win-title {
  margin: 4px 0 6px;
  font-size: 24px;
  font-weight: 900;
  color: #ffe9bd;
  text-shadow: 0 0 20px rgba(126,247,168,.35);
}
.win-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 6px 0 4px;
  color: #7ef7a8;
  font-weight: 900;
  font-size: 40px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(126,247,168,.45);
}
.win-time small { font-size: 13px; color: #9fdcb6; font-weight: 700; }
.win-actions { margin-top: 14px; }

.score-panel {
  margin-top: 14px;
  border-top: 1px solid #35164a;
  padding-top: 12px;
}
.score-panel.hidden { display: none; }
.score-title { font-size: 12px; font-weight: 700; color: #a274c4; letter-spacing: .1em; margin-bottom: 8px; }
.score-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  padding: 3px 0;
  color: #cbb3e0;
}
.score-row.you { color: #7ef7a8; font-weight: 700; }
.score-note { font-size: 10.5px; color: #7b678e; margin-top: 8px; }

@media (max-height: 480px) {
  .joy { --joy: 78px; }
  .act-btn { --sz: 58px; }
  .hud { min-height: 42px; padding: 4px 8px; }
  .hud-timer { font-size: 12px; }
  .controls { padding: 5px 12px 7px; }
  .panel { padding: 12px 14px 14px; }
  .start-art { display: none; }
  .blurb { display: none; }
}

@media (max-width: 360px) {
  .hud-zone { font-size: 11px; }
  .hud-eye-label { font-size: 11px; }
  .pip { width: 7px; height: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .eye-art, .eye-iris { animation: none !important; }
  .panel { animation: none !important; }
}