/* ============ Базовое ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --neon: #2eea62;
  --neon-soft: #b6ffce;
  --neon-dim: #6f9b7c;
  --cyan: #4dd2ff;
  --red: #ff5252;
  --amber: #ffd166;
  --pink: #d6336c;
  --pink-soft: #ff5e98;
  --violet: #a86bff;
}

html, body { height: 100%; }

body {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  background: radial-gradient(ellipse at 50% 30%, #07120b 0%, #04080a 70%);
  color: var(--neon-soft);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ============ Слои ============ */
#matrix-canvas {
  position: fixed; inset: 0;
  z-index: 0;
  opacity: 0.4;
  pointer-events: none;
}
body.celebration #matrix-canvas { display: none; }

.crt {
  position: fixed; inset: 0;
  z-index: 60;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
  opacity: 0.5;
}
.crt::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.45));
}
body.celebration .crt { display: none; }

#alert-flash {
  position: fixed; inset: 0;
  z-index: 70;
  background: rgba(255, 40, 60, 0.3);
  opacity: 0;
  pointer-events: none;
}
#alert-flash.on { animation: alertflash 0.35s ease-out; }
@keyframes alertflash { 0% { opacity: 1; } 100% { opacity: 0; } }

#flashout {
  position: fixed; inset: 0;
  z-index: 80;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
#flashout.on { animation: flashout 1.1s ease-in-out; }
@keyframes flashout { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }

#confetti-canvas {
  position: fixed; inset: 0;
  z-index: 40;
  pointer-events: none;
}

#bg-hearts { display: none; }
body.celebration #bg-hearts { display: block; }
#bg-hearts span {
  position: fixed;
  bottom: -50px;
  z-index: 0;
  opacity: 0.35;
  animation: floatBg linear infinite;
  pointer-events: none;
}
@keyframes floatBg { to { transform: translateY(-115vh) rotate(25deg); } }

body.shake-it { animation: screenshake 0.5s; }
@keyframes screenshake {
  0%, 100% { transform: none; }
  20% { transform: translate(-8px, 4px); }
  40% { transform: translate(7px, -6px); }
  60% { transform: translate(-5px, 6px); }
  80% { transform: translate(6px, 2px); }
}

/* ============ HUD ============ */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 56px 9px 14px;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--neon-dim);
  background: rgba(4, 10, 6, 0.75);
  border-bottom: 1px solid rgba(46, 234, 98, 0.18);
  backdrop-filter: blur(6px);
}
#hud-stage {
  color: var(--neon);
  text-shadow: 0 0 8px rgba(46, 234, 98, 0.6);
  white-space: nowrap;
}
.led {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--neon);
  margin-right: 6px;
  box-shadow: 0 0 8px var(--neon);
  animation: blink 1.6s infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }
body.celebration #hud { display: none; }

#mute-btn {
  position: fixed;
  top: 5px; right: 10px;
  z-index: 90;
  width: 38px; height: 38px;
  border: 1px solid rgba(46, 234, 98, 0.4);
  border-radius: 8px;
  background: rgba(4, 14, 8, 0.8);
  font-size: 17px;
  cursor: pointer;
  transition: transform 0.15s;
}
#mute-btn:active { transform: scale(0.9); }
body.celebration #mute-btn {
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  box-shadow: 0 6px 18px rgba(180, 80, 140, 0.25);
}

/* ============ Каркас ============ */
#app {
  position: relative;
  z-index: 10;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 56px 14px 36px;
}

.screen { display: none; width: 100%; }
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: popIn 0.4s ease;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* ============ Терминальные панели ============ */
.panel {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  background: rgba(4, 14, 8, 0.92);
  border: 1px solid #1d4d2c;
  border-radius: 12px;
  box-shadow: 0 0 50px rgba(46, 234, 98, 0.14), 0 24px 60px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  text-align: left;
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid #16381f;
}
.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.r { background: #ff5f56; }
.dot.y { background: #ffbd2e; }
.dot.g { background: #27c93f; }
.term-title { margin-left: 8px; color: #7fa98c; font-size: 0.75rem; }

.term-body {
  padding: 18px;
  min-height: 220px;
  max-height: 60vh;
  overflow-y: auto;
}
.term-actions { padding: 0 18px 18px; }

.term-line {
  line-height: 1.7;
  font-size: 0.9rem;
  min-height: 1.2em;
  color: var(--neon-soft);
  word-break: break-word;
}
.term-line.dim { color: var(--neon-dim); }
.term-line.ok { color: var(--neon); }
.term-line.err { color: var(--red); }
.term-line.warn { color: var(--amber); }

.stage-title {
  font-size: clamp(1rem, 3.6vw, 1.45rem);
  font-weight: 700;
  color: var(--neon);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(46, 234, 98, 0.55);
  margin-bottom: 12px;
}

/* глитч на заголовках */
.glitch { position: relative; display: inline-block; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  text-shadow: none;
  opacity: 0.75;
}
.glitch::before { color: var(--cyan); animation: glitchShift 2.9s infinite steps(1); }
.glitch::after { color: #ff4d8d; animation: glitchShift 2.3s infinite steps(1) reverse; }
@keyframes glitchShift {
  0%, 91% { clip-path: inset(0 0 100% 0); transform: none; }
  92% { clip-path: inset(15% 0 45% 0); transform: translateX(-3px); }
  94% { clip-path: inset(60% 0 10% 0); transform: translateX(3px); }
  96% { clip-path: inset(40% 0 40% 0); transform: translateX(-2px); }
  98% { clip-path: inset(80% 0 2% 0); transform: translateX(2px); }
}

/* ============ Кибер-кнопки ============ */
.cbtn {
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--neon);
  background: rgba(46, 234, 98, 0.07);
  border: 1px solid var(--neon);
  border-radius: 6px;
  padding: 13px 26px;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(46, 234, 98, 0.25), inset 0 0 14px rgba(46, 234, 98, 0.07);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  touch-action: manipulation;
}
.cbtn:hover {
  background: rgba(46, 234, 98, 0.16);
  box-shadow: 0 0 30px rgba(46, 234, 98, 0.5), inset 0 0 18px rgba(46, 234, 98, 0.14);
}
.cbtn:active { transform: scale(0.97); }
.cbtn-small { padding: 10px 18px; font-size: 0.8rem; }

/* ============ Стадия 1: сенсорная панель ============ */
#playfield {
  position: relative;
  width: 100%;
  height: min(48vh, 340px);
  margin-top: 12px;
  border: 1px solid rgba(46, 234, 98, 0.35);
  border-radius: 8px;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(46, 234, 98, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(46, 234, 98, 0.07) 1px, transparent 1px);
  background-size: 28px 28px;
}
#runaway-btn { position: absolute; white-space: nowrap; }
#runaway-btn.jolt { animation: jolt 0.18s steps(2); }
@keyframes jolt {
  25% { transform: skewX(14deg); opacity: 0.35; }
  75% { transform: skewX(-12deg); opacity: 0.7; }
}
#runaway-btn.surrendered {
  background: rgba(46, 234, 98, 0.25);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

/* ============ Стадия 2: верификация ============ */
.quiz-question {
  font-size: clamp(0.95rem, 3vw, 1.15rem);
  color: #d9ffe6;
  line-height: 1.6;
  min-height: 3.2em;
  margin: 6px 0 12px;
}
.copt {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--neon-soft);
  background: transparent;
  border: 1px solid rgba(46, 234, 98, 0.25);
  border-left: 3px solid rgba(46, 234, 98, 0.45);
  border-radius: 4px;
  padding: 11px 14px;
  margin: 7px 0;
  cursor: pointer;
  transition: all 0.12s;
  touch-action: manipulation;
}
.copt:hover { background: rgba(46, 234, 98, 0.1); border-color: var(--neon); }
.copt .key { color: var(--neon-dim); margin-right: 10px; }
.copt.wrong {
  color: var(--red);
  border-color: rgba(255, 82, 82, 0.5);
  text-decoration: line-through;
  opacity: 0.55;
  cursor: default;
}
.copt.correct {
  background: rgba(46, 234, 98, 0.18);
  border-color: var(--neon);
  color: #d9ffe6;
}
#quiz-log { margin-top: 10px; font-weight: 700; }

/* ============ Стадия 3: аудит кода ============ */
#audit-code {
  margin: 10px 0;
  border: 1px solid rgba(46, 234, 98, 0.2);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  overflow-x: auto;
}
.code-line {
  display: flex;
  gap: 14px;
  padding: 4px 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre;
  cursor: pointer;
  transition: background 0.12s;
}
.code-line:hover { background: rgba(46, 234, 98, 0.08); }
.code-line .ln {
  color: #3f6e4d;
  min-width: 2ch;
  text-align: right;
  user-select: none;
  flex-shrink: 0;
}
.code-line .code { color: #c9e8d2; }
.code-line.nope { animation: nopeflash 0.4s; }
@keyframes nopeflash {
  0% { background: rgba(255, 82, 82, 0.3); }
  100% { background: transparent; }
}
.code-line.patched { background: rgba(46, 234, 98, 0.16); }
.code-line.patched .code { color: var(--neon); }
#audit-msg { margin-top: 8px; font-weight: 700; }

/* ============ Стадия 4: финальный замок ============ */
#term-out { min-height: 240px; }
#term-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 18px 14px;
}
.term-prompt { color: var(--neon); font-weight: bold; }
#term-input {
  flex: 1;
  min-width: 0;
  background: rgba(52, 255, 109, 0.07);
  border: 1px solid #1d4d2c;
  color: #c8ffd8;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 1rem;
  letter-spacing: 0.2em;
  outline: none;
}
#term-input:focus {
  border-color: var(--neon);
  box-shadow: 0 0 0 3px rgba(46, 234, 98, 0.15);
}
.term-hint { padding: 0 18px 16px; color: #5d8b6b; font-size: 0.78rem; }

/* ============ Вскрытие хранилища ============ */
.vault-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 30px 10px;
}
#vault-lock {
  font-size: 110px;
  filter: drop-shadow(0 0 30px rgba(46, 234, 98, 0.5));
  animation: vaultpulse 1.2s ease-in-out infinite;
}
@keyframes vaultpulse { 50% { transform: scale(1.07); } }
.vault-bar {
  width: min(420px, 82vw);
  height: 14px;
  border: 1px solid var(--neon);
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 0 18px rgba(46, 234, 98, 0.3);
}
#vault-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1fb65b, var(--neon));
  box-shadow: 0 0 14px var(--neon);
  transition: width 0.2s;
}
#vault-status {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.82rem;
  color: var(--neon);
  text-shadow: 0 0 10px rgba(46, 234, 98, 0.5);
  min-height: 1.6em;
  text-align: center;
}

/* ============ ПРАЗДНИК (розовый мир) ============ */
body.celebration {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #ffd3e8, #e8d5ff, #ffe3ec, #d8e9ff);
  background-size: 300% 300%;
  animation: bgshift 18s ease infinite;
  color: #5a4257;
}
@keyframes bgshift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.card {
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  padding: 36px 30px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  box-shadow: 0 20px 60px rgba(180, 80, 140, 0.25);
  text-align: center;
}
.card-wide { max-width: 700px; }

.title {
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: clamp(1.4rem, 5vw, 2.1rem);
  line-height: 1.15;
  background: linear-gradient(110deg, var(--pink), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 8px 0 10px;
}
.subtitle { font-size: 1.02rem; line-height: 1.6; }

.btn {
  background: linear-gradient(135deg, var(--pink-soft), var(--violet));
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 30px;
  font-size: 1rem;
  font-weight: 800;
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(214, 51, 108, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  margin-top: 10px;
}
.btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 30px rgba(214, 51, 108, 0.45); }
.btn:active { transform: scale(0.96); }
.btn-small { padding: 10px 22px; font-size: 0.92rem; }

/* таймлайн */
#timeline-list {
  text-align: left;
  margin: 14px 0 8px;
  width: 100%;
}
.tl-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 8px 0;
  opacity: 0;
  transform: translateX(-18px);
  transition: all 0.5s cubic-bezier(0.2, 1, 0.4, 1);
}
.tl-item.show { opacity: 1; transform: none; }
.tl-icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow: 0 6px 16px rgba(214, 51, 108, 0.18);
}
.tl-date {
  font-family: 'Unbounded', sans-serif;
  font-weight: 700;
  color: var(--pink);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tl-text { line-height: 1.45; font-size: 0.95rem; }

/* финал */
.drum-emoji { font-size: 64px; animation: drumshake 0.25s linear infinite; }
@keyframes drumshake {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

#cert-wrap { display: none; }
#cert-wrap.revealed {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: certIn 0.8s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes certIn {
  from { opacity: 0; transform: scale(0.6) translateY(40px); }
  to { opacity: 1; transform: none; }
}

.cert-card {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(135deg, #ffffff, #f3f6ff);
  border: 1px solid #dbe7ff;
  border-radius: 20px;
  padding: 26px 24px;
  margin-top: 16px;
  box-shadow: 0 16px 44px rgba(0, 91, 255, 0.18);
}
.cert-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cert-logo {
  background: #005bff;
  color: #fff;
  font-weight: 900;
  padding: 4px 12px;
  border-radius: 8px;
  letter-spacing: 0.03em;
}
#cert-title { font-weight: 800; color: #1c3358; }
.cert-sub { color: #5b6f93; margin: 6px 0 14px; }
.cert-code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: clamp(1.2rem, 4.5vw, 1.7rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #0a2d6e;
  background: #eef4ff;
  border: 2px dashed #7da6ff;
  border-radius: 12px;
  padding: 14px 10px;
  margin-bottom: 14px;
  user-select: all;
}
.cert-note { color: #8294b5; font-size: 0.85rem; margin-top: 12px; }
.cert-teaser {
  margin-top: 18px;
  font-family: 'Unbounded', sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--violet);
}

/* ============ Мобильные ============ */
@media (max-width: 560px) {
  #app { padding: 50px 8px 28px; }
  .term-body { padding: 14px; }
  .term-line { font-size: 0.82rem; }
  .code-line { font-size: 0.74rem; gap: 8px; }
  .card { padding: 26px 16px; border-radius: 22px; }
  #playfield { height: min(52vh, 320px); }
  #hud { font-size: 0.6rem; padding-right: 52px; }
}
