:root {
  --bg: #090b0f;
  --panel: #11151b;
  --panel-2: #171c24;
  --metal: #222933;
  --metal-2: #2d3540;
  --text: #f4f6f8;
  --muted: #8d97a5;
  --accent: #d7ff3f;
  --danger: #ff5d5d;
  --shadow: rgba(0, 0, 0, 0.45);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button { font: inherit; }

.app-shell {
  position: relative;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: var(--safe-top) 18px var(--safe-bottom);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -15%, rgba(215, 255, 63, 0.08), transparent 36%),
    linear-gradient(180deg, #0d1015, #090b0f 45%);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

.brand-wrap { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 42px;
  height: 42px;
  border: 1px solid #343b46;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font: 800 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
  background: #11151a;
  box-shadow: inset 0 0 20px rgba(215, 255, 63, 0.03);
}

.brand { font-size: 14px; font-weight: 900; letter-spacing: 0.14em; }
.microcopy { margin-top: 3px; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: 0.16em; }

.best-box {
  min-width: 58px;
  padding: 7px 10px;
  border: 1px solid #2a3039;
  border-radius: 10px;
  text-align: right;
  background: rgba(17, 21, 27, 0.78);
}
.best-box span { display: block; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: 0.12em; }
.best-box strong { font: 800 18px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; }

.elevator {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(340px, 1fr) auto;
  border: 1px solid #252b34;
  border-radius: 24px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 24px 70px var(--shadow);
}

.floor-panel {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border-bottom: 1px solid #242a32;
  background: linear-gradient(#171c23, #11151b);
}

.floor-caption { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.18em; }
.floor-number { min-width: 64px; font: 900 34px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.08em; color: var(--accent); text-shadow: 0 0 18px rgba(215, 255, 63, 0.18); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #49515d; box-shadow: 0 0 0 5px rgba(73, 81, 93, 0.08); transition: 180ms ease; }
.status-dot.live { background: var(--accent); box-shadow: 0 0 0 5px rgba(215, 255, 63, 0.08), 0 0 18px rgba(215, 255, 63, 0.38); }
.status-dot.dead { background: var(--danger); }

.stage {
  position: relative;
  min-height: 340px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px) 0 0 / 26px 26px,
    #0c1015;
}

.challenge {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

.challenge .kicker { color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .2em; }
.challenge h2 { margin: 0; max-width: 360px; font-size: clamp(24px, 6vw, 34px); line-height: 1.04; letter-spacing: -0.035em; }
.challenge p { margin: 0; max-width: 360px; color: #a7b0bc; font-size: 14px; line-height: 1.5; }

.challenge-button,
.choice-button {
  border: 1px solid #39414c;
  background: #191f27;
  color: var(--text);
  border-radius: 16px;
  min-height: 56px;
  padding: 14px 20px;
  font-weight: 900;
  letter-spacing: .04em;
  box-shadow: inset 0 1px rgba(255,255,255,.04), 0 8px 28px rgba(0,0,0,.2);
  -webkit-tap-highlight-color: transparent;
}
.challenge-button:active,
.choice-button:active { transform: scale(.97); }
.challenge-button.accent { border-color: rgba(215,255,63,.36); color: #0a0b0d; background: var(--accent); }
.challenge-button.danger { border-color: rgba(255,93,93,.35); color: #ffdada; background: #2a171a; }

.choice-grid { width: min(340px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice-grid.two { grid-template-columns: repeat(2, 1fr); }
.choice-button { min-width: 0; font: 900 18px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }

.sequence { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }
.sequence span { min-width: 48px; padding: 13px 12px; border: 1px solid #303744; border-radius: 13px; background: #151a21; font: 900 20px/1 ui-monospace, monospace; }
.sequence span.missing { color: var(--accent); border-color: rgba(215,255,63,.35); }

.memory-symbol { font-size: 62px; filter: grayscale(.15); }
.counter { min-width: 128px; padding: 16px 22px; border: 1px solid #303844; border-radius: 14px; background: #11161d; font: 900 42px/1 ui-monospace, monospace; color: var(--accent); }

.hold-ring {
  width: 128px;
  height: 128px;
  border: 2px solid #313947;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background: #12171e;
  font-weight: 900;
  letter-spacing: .08em;
}
.hold-ring::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: var(--hold, 0%);
  background: rgba(215,255,63,.2);
  transition: height 40ms linear;
}
.hold-ring span { position: relative; z-index: 1; }

.cat-target {
  position: absolute;
  z-index: 4;
  width: 74px;
  height: 74px;
  border: 0;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: 42px;
  background: #171d24;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}

.door {
  position: absolute;
  z-index: 6;
  top: 0;
  bottom: 0;
  width: 50.5%;
  background:
    linear-gradient(90deg, rgba(255,255,255,.04), transparent 14%, rgba(0,0,0,.12) 88%),
    linear-gradient(180deg, #343c46 0%, #222933 12%, #2b333e 48%, #20262f 100%);
  transition: transform 560ms cubic-bezier(.7,0,.2,1);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.025);
}
.door-left { left: 0; transform: translateX(0); }
.door-right { right: 0; transform: translateX(0); background: linear-gradient(270deg, rgba(255,255,255,.04), transparent 14%, rgba(0,0,0,.12) 88%), linear-gradient(180deg, #343c46 0%, #222933 12%, #2b333e 48%, #20262f 100%); }
.stage.open .door-left { transform: translateX(-101%); }
.stage.open .door-right { transform: translateX(101%); }

.door-line {
  position: absolute;
  top: 8%;
  bottom: 8%;
  width: 1px;
  background: rgba(255,255,255,.07);
}
.door-left .door-line { right: 18%; }
.door-right .door-line { left: 18%; }
.center-seam { position: absolute; z-index: 7; top: 0; bottom: 0; left: 50%; width: 1px; background: rgba(0,0,0,.5); pointer-events: none; transition: opacity 300ms; }
.stage.open .center-seam { opacity: 0; }

.control-strip { display: flex; align-items: center; gap: 12px; padding: 15px 16px 17px; border-top: 1px solid #222832; background: #11151b; }
.timer-track { flex: 1; height: 4px; border-radius: 99px; overflow: hidden; background: #262d36; }
.timer-bar { width: 0%; height: 100%; background: var(--accent); transform-origin: left; transition: width 80ms linear; }
.hint { width: 28px; height: 28px; border: 1px solid #2e3540; border-radius: 50%; display: grid; place-items: center; color: var(--muted); font-size: 12px; font-weight: 900; }

.overlay-card {
  position: absolute;
  z-index: 20;
  left: 28px;
  right: 28px;
  top: 50%;
  transform: translateY(-45%);
  border: 1px solid #303742;
  border-radius: 24px;
  padding: 28px 24px;
  background: rgba(16, 20, 26, .96);
  backdrop-filter: blur(18px);
  box-shadow: 0 30px 100px rgba(0,0,0,.58);
  text-align: center;
}
.overlay-card.hidden { display: none; }
.overlay-card h1,
.overlay-card h2 { margin: 8px 0 10px; font-size: clamp(34px, 10vw, 50px); letter-spacing: -.05em; }
.overlay-card p { margin: 0 auto 22px; max-width: 330px; color: #a8b1bd; line-height: 1.55; }
.warning-label { color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .2em; }
.primary-button,
.secondary-button { width: 100%; min-height: 56px; border-radius: 16px; font-weight: 950; letter-spacing: .08em; }
.primary-button { border: 0; background: var(--accent); color: #080a0d; }
.secondary-button { margin-top: 10px; border: 1px solid #343c47; background: #181d25; color: var(--text); }
.footnote { margin-top: 14px !important; margin-bottom: 0 !important; font-size: 11px; color: #717b88 !important; }
.score-row { display: flex; justify-content: space-between; align-items: center; margin: 18px 0; padding: 13px 15px; border: 1px solid #2d343f; border-radius: 14px; background: #11161d; }
.score-row span { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .14em; }
.score-row strong { font: 900 24px/1 ui-monospace, monospace; color: var(--accent); }

.flash-success::after,
.flash-fail::after {
  content: "";
  position: absolute;
  z-index: 18;
  inset: 0;
  pointer-events: none;
  animation: flash 420ms ease-out both;
}
.flash-success::after { background: rgba(215,255,63,.18); }
.flash-fail::after { background: rgba(255,93,93,.22); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

@media (max-height: 700px) {
  .app-shell { gap: 10px; }
  .topbar { min-height: 42px; }
  .brand-mark { width: 36px; height: 36px; }
  .elevator { grid-template-rows: 58px minmax(290px, 1fr) auto; }
  .floor-panel { height: 58px; }
  .challenge { padding: 18px; gap: 13px; }
  .overlay-card { padding: 22px 20px; }
}
