/* ═══════════════════════════════════════
   RESET + BASE
═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0e1a;
  --bg2:       #0f1629;
  --bg3:       #141d35;
  --panel:     #111827;
  --border:    #1e2d50;
  --accent:    #3b82f6;
  --accent2:   #6366f1;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #f59e0b;
  --text:      #e2e8f0;
  --text2:     #94a3b8;
  --text3:     #64748b;
  --editor-bg: #0d1117;
  --font-mono: 'Courier New', Courier, monospace;
  --font-ui:   system-ui, -apple-system, sans-serif;
  --radius:    8px;
  --radius-lg: 14px;
}

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

/* ═══════════════════════════════════════
   SCREENS
═══════════════════════════════════════ */
.screen {
  position: fixed; inset: 0;
  display: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.screen.active {
  display: flex;
  opacity: 1;
}
.screen.fade-out { opacity: 0; }

/* ═══════════════════════════════════════
   INTRO SCREEN
═══════════════════════════════════════ */
.intro-bg {
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, #0d1d40 0%, #050810 100%);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}

.glitch-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(59,130,246,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.07) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: gridMove 20s linear infinite;
}
@keyframes gridMove {
  from { background-position: 0 0; }
  to   { background-position: 40px 40px; }
}

.intro-center {
  position: relative; z-index: 2;
  display: flex; flex-direction: column;
  align-items: center; gap: 28px;
  text-align: center; max-width: 600px; padding: 24px;
}

.logo-title {
  font-size: 64px; font-weight: 900; letter-spacing: 6px;
  color: #fff;
  text-shadow: 0 0 40px rgba(99,102,241,0.8), 0 0 80px rgba(59,130,246,0.4);
}
.logo-title span { color: var(--accent2); }
.logo-sub {
  font-size: 16px; color: var(--text2); letter-spacing: 2px;
  margin-top: -16px;
}

.intro-story {
  font-size: 15px; line-height: 1.8; color: var(--text2);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 28px; min-height: 80px;
  max-width: 520px;
}

/* ═══════════════════════════════════════
   BUTTONS
═══════════════════════════════════════ */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; border: none; border-radius: var(--radius);
  padding: 14px 36px; font-size: 16px; font-weight: 700;
  cursor: pointer; letter-spacing: 1px;
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(99,102,241,0.6);
}
.btn-primary:active { transform: translateY(0); }

.btn-icon {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); border-radius: var(--radius);
  padding: 6px 12px; font-size: 16px; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-icon:hover { background: var(--accent); color: #fff; }

.btn-icon-sm {
  background: none; border: none;
  color: var(--text3); font-size: 16px; cursor: pointer;
  transition: color 0.2s;
}
.btn-icon-sm:hover { color: var(--accent); }

/* ═══════════════════════════════════════
   DIALOG SCREEN
═══════════════════════════════════════ */
.dialog-scene {
  width: 100%; height: 100%;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 60px;
  background: radial-gradient(ellipse at 50% 30%, #0d2040 0%, #050810 100%);
  position: relative;
}

.dialog-bg-world {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(59,130,246,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.05) 1px, transparent 1px);
  background-size: 30px 30px;
}

.dialog-box {
  position: relative; z-index: 2;
  background: rgba(15, 22, 41, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  max-width: 680px; width: 90%;
  box-shadow: 0 0 60px rgba(59,130,246,0.15);
}

.dialog-speaker {
  font-size: 12px; font-weight: 700; letter-spacing: 3px;
  color: var(--accent); margin-bottom: 12px;
}

.dialog-text {
  font-size: 16px; line-height: 1.8; color: var(--text);
  min-height: 60px;
}

.btn-dialog-next {
  margin-top: 20px;
  background: none; border: 1px solid var(--border);
  color: var(--text2); border-radius: var(--radius);
  padding: 8px 20px; font-size: 14px; cursor: pointer;
  float: right;
  transition: border-color 0.2s, color 0.2s;
}
.btn-dialog-next:hover { border-color: var(--accent); color: var(--accent); }

/* ═══════════════════════════════════════
   CHAPTERS SCREEN
═══════════════════════════════════════ */
.chapters-wrap {
  width: 100%; height: 100%;
  overflow-y: auto;
  padding: 48px 40px;
  background: radial-gradient(ellipse at top, #0d1d3a 0%, #060a14 100%);
}
.chapters-title {
  font-size: 28px; font-weight: 800; color: var(--text);
  margin-bottom: 36px; text-align: center; letter-spacing: 2px;
}
.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px; max-width: 1100px; margin: 0 auto;
}

.chapter-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative; overflow: hidden;
}
.chapter-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  opacity: 0; transition: opacity 0.2s;
}
.chapter-card:hover { transform: translateY(-4px); border-color: var(--accent); box-shadow: 0 8px 30px rgba(59,130,246,0.15); }
.chapter-card:hover::before { opacity: 1; }
.chapter-card.locked { opacity: 0.45; cursor: not-allowed; }
.chapter-card.locked:hover { transform: none; border-color: var(--border); box-shadow: none; }

.chapter-icon   { font-size: 36px; margin-bottom: 12px; }
.chapter-num    { font-size: 11px; color: var(--text3); letter-spacing: 2px; font-weight: 600; margin-bottom: 4px; }
.chapter-name   { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.chapter-desc   { font-size: 13px; color: var(--text2); line-height: 1.6; }
.chapter-status { margin-top: 16px; font-size: 12px; font-weight: 600; }
.chapter-status.done    { color: var(--green); }
.chapter-status.active  { color: var(--accent); }
.chapter-status.locked  { color: var(--text3); }

/* ═══════════════════════════════════════
   MISSION SCREEN
═══════════════════════════════════════ */
.mission-topbar {
  height: 48px; background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; flex-shrink: 0;
}
.mission-chapter-label {
  font-size: 11px; letter-spacing: 2px; color: var(--text3);
  font-weight: 600; white-space: nowrap;
}
.mission-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mission-progress-wrap {
  width: 120px; height: 4px;
  background: var(--bg3); border-radius: 2px; overflow: hidden;
}
.mission-progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.5s ease; border-radius: 2px;
}
.mission-step-label {
  font-size: 12px; color: var(--text3); white-space: nowrap;
}

#screen-mission {
  flex-direction: column;
}
.mission-layout {
  display: grid;
  grid-template-columns: 300px 1fr 360px;
  flex: 1; overflow: hidden;
}

/* ── Панель истории ── */
.panel-story {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0;
}

.mentor-block {
  padding: 20px 16px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: flex-start;
}
.mentor-avatar { font-size: 32px; flex-shrink: 0; }
.mentor-bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0 12px 12px 12px;
  padding: 10px 14px;
  font-size: 13px; line-height: 1.6; color: var(--text2);
  position: relative;
}

.mission-task-block {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.task-header {
  font-size: 12px; font-weight: 700; letter-spacing: 2px;
  color: var(--accent); margin-bottom: 10px;
}
.task-desc {
  font-size: 14px; line-height: 1.7; color: var(--text);
}
.task-hints {
  margin-top: 12px; display: flex; flex-direction: column; gap: 6px;
}
.task-hint-item {
  font-size: 13px; color: var(--text2);
  padding-left: 12px; border-left: 2px solid var(--accent2);
}

.tag-reference {
  padding: 16px; flex: 1; overflow-y: auto;
}
.tag-ref-title {
  font-size: 11px; letter-spacing: 2px; color: var(--text3);
  font-weight: 700; margin-bottom: 12px;
}
.tag-ref-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  margin-bottom: 8px; font-size: 13px;
}
.tag-ref-item code {
  font-family: var(--font-mono); color: var(--accent);
  background: rgba(59,130,246,0.1); padding: 1px 6px;
  border-radius: 4px;
}
.tag-ref-item .tag-desc { color: var(--text2); margin-top: 4px; font-size: 12px; }

/* ── Панель редактора ── */
.panel-editor {
  display: flex; flex-direction: column;
  background: var(--editor-bg);
  border-right: 1px solid var(--border);
}

.editor-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--panel); flex-shrink: 0;
}
.editor-tab {
  padding: 10px 20px; font-size: 13px; font-weight: 600;
  color: var(--text3); cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.editor-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.editor-tab.hidden { display: none; }

.editor-body {
  flex: 1; display: flex; overflow: hidden; position: relative;
}

.editor-line-numbers {
  padding: 14px 0; min-width: 40px; text-align: right;
  padding-right: 12px; padding-left: 8px;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.6;
  color: var(--text3); background: var(--editor-bg);
  border-right: 1px solid var(--border);
  user-select: none; overflow: hidden; flex-shrink: 0;
}

.code-editor {
  flex: 1; background: var(--editor-bg); color: #abb2bf;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.6;
  border: none; outline: none; resize: none;
  padding: 14px 16px;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  caret-color: var(--accent);
}

.editor-footer {
  display: flex; gap: 8px; padding: 10px 12px;
  background: var(--panel); border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-run {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); border-radius: var(--radius);
  padding: 7px 16px; font-size: 13px; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-run:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.btn-check {
  background: var(--green); border: none;
  color: #fff; border-radius: var(--radius);
  padding: 7px 18px; font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 10px rgba(34,197,94,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-check:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(34,197,94,0.4); }

.btn-hint {
  margin-left: auto;
  background: none; border: 1px solid var(--border);
  color: var(--yellow); border-radius: var(--radius);
  padding: 7px 14px; font-size: 13px; cursor: pointer;
  transition: border-color 0.2s;
}
.btn-hint:hover { border-color: var(--yellow); }

/* ── Панель превью ── */
.panel-preview {
  display: flex; flex-direction: column;
  background: var(--bg2);
}

.preview-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text2); flex-shrink: 0;
}

.preview-frame {
  flex: 1; border: none;
  background: #fff;
}

.validation-result {
  padding: 10px 14px; font-size: 13px; font-weight: 600;
  min-height: 40px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
}
.validation-result.ok   { color: var(--green); background: rgba(34,197,94,0.08); border-top: 1px solid rgba(34,197,94,0.2); }
.validation-result.fail { color: var(--red);   background: rgba(239,68,68,0.08); border-top: 1px solid rgba(239,68,68,0.2); }

/* ═══════════════════════════════════════
   WIN SCREEN
═══════════════════════════════════════ */
.win-scene {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #0a2040 0%, #050810 100%);
  position: relative; overflow: hidden;
}
.win-particles {
  position: absolute; inset: 0; pointer-events: none;
}
.win-box {
  position: relative; z-index: 2;
  background: rgba(15,22,41,0.97);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 48px 56px;
  text-align: center; max-width: 500px;
  box-shadow: 0 0 80px rgba(59,130,246,0.2);
  animation: winPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes winPop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.win-icon  { font-size: 72px; margin-bottom: 16px; animation: bounce 1s infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-10px); } }
.win-title { font-size: 28px; font-weight: 900; color: var(--text); margin-bottom: 12px; }
.win-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 14px; font-weight: 700;
  padding: 8px 24px; border-radius: 999px;
  margin-bottom: 20px; letter-spacing: 1px;
}
.win-desc  { font-size: 15px; color: var(--text2); line-height: 1.7; margin-bottom: 28px; }

/* ═══════════════════════════════════════
   MODAL
═══════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); z-index: 100;
}
.modal {
  position: fixed; z-index: 101;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px; max-width: 440px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal.hidden { display: none; }
.modal-title  { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 14px; }
.modal-body   { font-size: 14px; line-height: 1.7; color: var(--text2); margin-bottom: 20px; }
.modal-body code {
  font-family: var(--font-mono);
  background: var(--bg3); padding: 2px 6px;
  border-radius: 4px; color: var(--accent);
}
.modal-overlay.hidden { display: none; }

/* ═══════════════════════════════════════
   SYNTAX COLORS (simple)
═══════════════════════════════════════ */
.code-editor::selection { background: rgba(59,130,246,0.25); }

/* ═══════════════════════════════════════
   SCROLLBARS
═══════════════════════════════════════ */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ═══════════════════════════════════════
   PARTICLES (win screen)
═══════════════════════════════════════ */
.particle {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  animation: particleFly linear forwards;
}
@keyframes particleFly {
  from { transform: translateY(0) scale(1); opacity: 1; }
  to   { transform: translateY(-300px) scale(0); opacity: 0; }
}

/* ═══════════════════════════════════════
   TYPE ANIMATION
═══════════════════════════════════════ */
.typing::after {
  content: '▌';
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
