:root {
  --bg: #0b0f1a; --surface: #121826; --surface-2: #1a2236;
  --border: rgba(255,255,255,0.08); --accent: #00e5a8;
  --accent-dim: rgba(0,229,168,0.15); --warn: #ff6b4a;
  --text: #e8eef8; --muted: #8b9bb4; --green: #4ade80; --blue: #38bdf8;
  --panel-w: 520px;
  --font-display: 'Orbitron', 'Space Grotesk', system-ui, sans-serif;
  --star-fill: #ffcc4d; --star-empty: rgba(255,255,255,0.18);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Space Grotesk', system-ui, sans-serif; }

#app {
  display: grid;
  grid-template-columns: 48px 1fr;
  height: 100vh;
  height: 100dvh;
  transition: grid-template-columns 0.28s ease;
}
#app.blocks-open {
  grid-template-columns: var(--panel-w) 1fr;
}

.block-toggle {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 0.75rem 0; gap: 0.75rem; z-index: 20;
  cursor: pointer; user-select: none;
}
.block-toggle:hover { background: var(--surface-2); }
.block-toggle .toggle-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 700; transition: transform 0.25s;
}
#app.blocks-open .block-toggle .toggle-icon { transform: rotate(180deg); }
.block-toggle .toggle-label {
  writing-mode: vertical-rl; text-orientation: mixed;
  font-family: var(--font-display);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}

.sidebar {
  display: none;
  background: #0e1420;
  border-right: 1px solid var(--border);
  flex-direction: column; overflow: hidden;
  min-width: 0;
}
#app.blocks-open .sidebar { display: flex; }
#app.blocks-open .block-toggle { display: none; }

.sidebar-header {
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
  background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}
.sidebar-header a.logo {
  font-family: var(--font-display);
  font-size: 1.4rem; font-weight: 700; color: var(--text); text-decoration: none;
  letter-spacing: -0.01em; line-height: 1.1;
}
.sidebar-header a.logo:hover { color: var(--accent); }
.sidebar-header a.logo span { color: var(--accent); }
.btn-collapse {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; font-size: 0.95rem; cursor: pointer;
}
.btn-collapse:hover { color: var(--text); border-color: var(--accent); }

.editor-tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--surface);
}
.editor-tab {
  flex: 1; padding: 0.55rem 0.5rem; text-align: center; font-size: 0.72rem; font-weight: 600;
  color: var(--muted); background: transparent; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.05em;
}
.editor-tab:hover { color: var(--text); }
.editor-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: rgba(0,229,168,0.06); }

.toolbar {
  display: flex; gap: 0.4rem; padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0; background: var(--surface);
}
button {
  font-family: var(--font-display); cursor: pointer; border: none; border-radius: 8px;
  font-weight: 700; font-size: 0.76rem; transition: all 0.15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.btn-primary { background: var(--accent); color: #04120e; padding: 0.5rem 0.85rem; flex: 1; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-danger { background: rgba(255,107,74,0.2); color: var(--warn); border: 1px solid rgba(255,107,74,0.35); padding: 0.45rem 0.65rem; }

.editor-pane { flex: 1; min-height: 0; display: none; flex-direction: column; }
.editor-pane.active { display: flex; }

#blocklyDiv { flex: 1; min-height: 0; width: 100%; height: 100%; background: #0e1420; position: relative; }
#blocklyDiv .injectionDiv {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
}
#blocklyDiv .blocklySvg {
  width: 100% !important;
  height: 100% !important;
}
#app.blocks-open .sidebar {
  min-width: 0;
  width: auto;
}

.python-wrap {
  flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative;
  background: #0a0e16;
}
#python-editor-host {
  flex: 1; min-height: 0; width: 100%; position: relative; overflow: hidden;
}
#python-editor-host .CodeMirror {
  height: 100%; width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem; line-height: 1.55;
  background: #0a0e16;
}
#python-editor-host .CodeMirror-scroll { min-height: 100%; }
#python-editor-host .CodeMirror-gutters {
  background: #0c121c; border-right: 1px solid rgba(255,255,255,0.06);
}
#python-editor-host .CodeMirror-linenumber { color: #4a5568; }
#python-editor-host .CodeMirror-cursor { border-left: 2px solid #00e5a8; }
#python-editor { display: none; }
.py-hint {
  flex-shrink: 0; padding: 0.35rem 0.75rem; font-size: 0.65rem; color: var(--muted);
  border-top: 1px solid var(--border); background: #0c121c;
}
.autocomplete {
  position: absolute; z-index: 30; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; max-height: 180px; overflow-y: auto; display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45); min-width: 220px;
}
.autocomplete.show { display: block; }
.ac-item {
  padding: 0.4rem 0.7rem; font-family: 'JetBrains Mono', monospace; font-size: 0.72rem;
  color: var(--text); cursor: pointer;
}
.ac-item:hover, .ac-item.active { background: var(--accent-dim); color: var(--accent); }
.ac-item .sig { color: var(--muted); font-size: 0.65rem; }

.blocklyMainBackground { fill: #070b14 !important; }
.blocklyToolboxDiv {
  background: #0a1020 !important;
  border-right: 1px solid rgba(0,230,255,0.18) !important;
  box-shadow: inset -1px 0 12px rgba(0,230,255,0.06);
}
.blocklyTreeRow { height: 30px !important; }
.blocklyTreeLabel { color: #7dd3fc; font-family: 'Space Grotesk', sans-serif !important; font-size: 13px !important; font-weight: 600 !important; }
.blocklyTreeSelected .blocklyTreeLabel { text-shadow: 0 0 8px currentColor; }
.blocklyTreeSelected { background: rgba(0,230,255,0.1) !important; }
.blocklyFlyoutBackground { fill: #0c1424 !important; fill-opacity: 1 !important; }
.blocklyScrollbarHandle { fill: #1e3a5f !important; }
.blocklyText { fill: #f0f9ff !important; }
.blocklyEditableText > rect {
  fill: rgba(0,20,40,0.65) !important;
  stroke: rgba(0,230,255,0.45) !important;
  stroke-width: 1.5 !important;
}
.blocklyHtmlInput { background: transparent !important; color: #00e6ff !important; }
.blocklyDropDownDiv {
  background-color: #0c1424 !important;
  border: 1px solid rgba(0,230,255,0.35) !important;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55), 0 0 16px rgba(0,230,255,0.15) !important;
}
.blocklyMenuItem { color: #e0f2fe !important; }
.blocklyMenuItemHighlight { background-color: rgba(0,230,255,0.18) !important; }
.blocklySelected > .blocklyPath {
  filter: drop-shadow(0 0 6px rgba(0,230,255,0.45));
}
.blocklyPath { stroke-width: 1.5 !important; }
.blocklyHighlightedConnectionPath { stroke: #00e5a8 !important; }
/* Çalışan blok yeşil parlar */
.blocklyRunning .blocklyPath,
g.blocklyRunning > .blocklyPath {
  filter: drop-shadow(0 0 8px rgba(0,229,168,0.75));
  transition: filter 0.15s;
}
#blocklyDiv { background: radial-gradient(ellipse at 30% 20%, #0c1a30 0%, #070b14 55%) !important; }

.level-caption-bar {
  flex-shrink: 0; padding: 0.45rem 0.75rem; background: rgba(0,229,168,0.08);
  color: var(--accent); font-size: 0.75rem; font-weight: 600; border-top: 1px solid var(--border);
}

.viewport { position: relative; background: #05080f; display: flex; flex-direction: column; min-width: 0; }
#canvas-wrap { flex: 1; position: relative; }
#c { display: block; width: 100%; height: 100%; }

/* ÜST HUD */
.overlay-hud {
  position: absolute; top: 0.75rem; left: 0.75rem; right: 0.75rem;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; z-index: 10; gap: 0.5rem; flex-wrap: wrap;
}
.hud-card {
  background: rgba(18,24,38,0.9);
  border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.75rem;
  font-size: 0.75rem; pointer-events: auto;
}
.hud-card strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.hud-card.hud-right {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.hud-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 0.4rem; }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem; }
.hud-card.hud-stars {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.3rem 0.6rem;
  border-color: rgba(255,204,77,0.45); font-family: var(--font-display);
}
.hud-stars-icon { color: var(--star-fill); font-size: 1.05rem; line-height: 1; text-shadow: 0 0 8px rgba(255,204,77,0.65); }
.hud-card.hud-stars strong { color: var(--star-fill); font-size: 0.95rem; }
.hud-card.hud-stars em { color: var(--muted, rgba(255,255,255,0.55)); font-style: normal; font-size: 0.68rem; }
.hud-card.hud-stars.pop { animation: starsPop 0.7s ease; }
@keyframes starsPop { 0% { transform: scale(1); } 35% { transform: scale(1.25); box-shadow: 0 0 18px rgba(255,204,77,0.7); } 100% { transform: scale(1); } }

/* TELEMETRİ: masaüstünde tam liste, mobilde yalnızca hız + yükseklik */
.telemetry-hud {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.75rem;
  min-width: 140px;
  font-size: 0.72rem;
  opacity: 0.72;
  transition: opacity 0.2s;
}
.telemetry-hud:hover { opacity: 1; }
.telemetry-hud .telem-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.05rem 0;
  border-bottom: 1px dashed rgba(255,255,255,0.05);
}
.telemetry-hud .telem-row:last-child { border-bottom: none; }
body.is-mobile .telemetry-hud {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  padding: 0.28rem 0.45rem;
  min-width: 0;
  font-size: 0.62rem;
  opacity: 0.9;
}
body.is-mobile .telemetry-hud .telem-row {
  justify-content: flex-start;
  gap: 0.25rem;
  padding: 0;
  border-bottom: none;
}
body.is-mobile .telemetry-hud .telem-extra { display: none; }
.telemetry-hud .telem-row span {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.telemetry-hud .telem-row strong {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: var(--accent);
}
.telemetry-hud .telem-row em {
  font-style: normal;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  color: var(--muted);
  margin-left: 0.15rem;
}

/* Aşamalar butonu */
.btn-stages {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.72rem;
  cursor: pointer;
}
.btn-stages:hover {
  background: var(--accent);
  color: #04120e;
}

/* Durum pill */
.hud-card.hud-status {
  padding: 0.2rem 0.28rem;
  align-self: flex-start;
  height: fit-content;
  line-height: 1;
}
.status-pill {
  display: inline-flex; align-items: center; gap: 0.28rem;
  padding: 0.18rem 0.48rem; border-radius: 999px; font-size: 0.62rem; font-weight: 600;
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.04em;
  line-height: 1.1;
}
.status-pill.idle { background: rgba(139,155,180,0.2); color: var(--muted); }
.status-pill.flying { background: var(--accent-dim); color: var(--accent); }
.status-pill.landed { background: rgba(74,222,128,0.15); color: var(--green); }
.status-pill.crash { background: rgba(255,107,74,0.2); color: var(--warn); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* FAB */
.fab-blocks {
  position: absolute; top: 50%; left: 0.75rem; transform: translateY(-50%);
  z-index: 15; background: var(--surface); border: 1px solid var(--border);
  color: var(--accent); border-radius: 12px; padding: 0.75rem 0.65rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  cursor: pointer; box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.fab-blocks:hover { border-color: var(--accent); background: var(--surface-2); }
.fab-blocks .fab-icon { font-family: var(--font-display); font-size: 0.85rem; font-weight: 700; letter-spacing: 0.04em; }
.fab-blocks .fab-text { font-family: var(--font-display); writing-mode: vertical-rl; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); }
#app.blocks-open .fab-blocks { display: none; }

/* Kontrol ipucu */
.controls-hint {
  position: absolute; bottom: 4rem; left: 50%; transform: translateX(-50%);
  background: rgba(18,24,38,0.8); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.35rem 0.8rem; font-size: 0.65rem; color: var(--muted); z-index: 10; white-space: nowrap;
  transition: opacity 0.6s;
}
.controls-hint.hidden { opacity: 0; pointer-events: none; }

/* ALT: ayarlar düğmesi + açılır panel */
.settings-wrap {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.4rem;
}
.btn-settings {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(18,24,38,0.92);
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.btn-settings:hover,
.settings-wrap.open .btn-settings {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.settings-bar {
  display: none;
  align-items: center;
  gap: 0.45rem;
  background: rgba(18,24,38,0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.4rem 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(92vw, 420px);
}
.settings-wrap.open .settings-bar,
.settings-bar:not([hidden]) {
  display: flex;
}
.settings-bar[hidden] { display: none !important; }

body:not(.is-mobile) .btn-settings { display: none; }
body:not(.is-mobile) .settings-wrap { flex-direction: column; }
body:not(.is-mobile) .settings-bar,
body:not(.is-mobile) .settings-bar[hidden] {
  display: flex !important;
}


.btn-theme, .btn-cam {
  font-family: var(--font-display); cursor: pointer; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 0.7rem; padding: 0.28rem 0.5rem;
  transition: all 0.15s; white-space: nowrap;
}
.btn-theme:hover, .btn-cam:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.btn-cam.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.btn-mute {
  font-family: var(--font-display); cursor: pointer; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2); color: var(--text);
  font-size: 0.85rem; padding: 0.24rem 0.4rem; line-height: 1;
  transition: all 0.15s;
}
.btn-mute:hover { border-color: var(--accent); background: var(--accent-dim); }
.btn-mute.is-muted { color: var(--muted); opacity: 0.7; }
.btn-lang {
  font-family: var(--font-display); cursor: pointer; border: none;
  border-radius: 8px; font-weight: 700; font-size: 0.72rem; padding: 0.32rem 0.65rem;
  transition: all 0.15s; white-space: nowrap; letter-spacing: 0.04em;
  background: linear-gradient(135deg, #00e5a8 0%, #38bdf8 100%);
  color: #04120e; box-shadow: 0 0 0 1px rgba(0,229,168,0.35), 0 2px 8px rgba(0,229,168,0.25);
}
.btn-lang:hover {
  filter: brightness(1.12);
  box-shadow: 0 0 0 1px rgba(0,229,168,0.55), 0 4px 14px rgba(0,229,168,0.4);
}
.cam-group { display: flex; gap: 0.25rem; }

/* SAĞ ALT: aşama bilgisi — vurgulu, nefes alan */
.stage-info {
  position: absolute;
  bottom: 0.75rem;
  right: 0.75rem;
  background: rgba(18,24,38,0.95);
  border: 1.5px solid rgba(0,229,168,0.55);
  border-radius: 14px;
  padding: 0.85rem 1rem 0.9rem;
  font-size: 0.78rem;
  z-index: 11;
  max-width: 360px;
  min-width: 260px;
  pointer-events: auto;
  cursor: default;
  transition: transform 0.18s, box-shadow 0.18s;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,229,168,0.15);
}
.stage-info::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 26px rgba(0,229,168,0.35), 0 0 0 1px rgba(0,229,168,0.35);
  opacity: 0; animation: stagePulse 3.5s ease-in-out infinite;
}
@keyframes stagePulse {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

.stage-info-label {
  font-family: var(--font-display);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 700;
}
.stage-info-hint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.55rem;
  color: var(--blue);
  opacity: 0.75;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.stage-info strong {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.25;
  display: block;
  margin-bottom: 0.35rem;
}
.stage-info-caption {
  color: var(--text);
  font-size: 0.76rem;
  line-height: 1.4;
  opacity: 0.9;
  margin: 0 0 0.35rem 0;
}
.stage-info-tip {
  color: var(--blue);
  font-size: 0.7rem;
  line-height: 1.35;
  margin: 0;
  padding-top: 0.35rem;
  border-top: 1px dashed rgba(56,189,248,0.25);
}
.stage-info-tip:empty { display: none; }

.stage-info-progress {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed rgba(0,229,168,0.25);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  color: var(--accent);
}
.stage-info-progress:empty { display: none; }
.stage-info-next {
  margin-top: 0.2rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.62rem;
  color: var(--muted);
}
.stage-info-next:empty { display: none; }

/* YARDIMCI ROBOT */
.helper {
  position: absolute;
  bottom: 6.5rem;
  right: 0.9rem;
  z-index: 13;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: auto;
}
.helper-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(18,24,38,0.92);
  border: 1.5px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5), 0 0 12px rgba(0,229,168,0.25);
  transition: transform 0.2s, box-shadow 0.2s;
}
.helper-avatar:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 20px rgba(0,0,0,0.55), 0 0 20px rgba(0,229,168,0.5);
}
.helper-bubble {
  position: absolute;
  right: 0;
  bottom: 0;
  background: rgba(18,24,38,0.96);
  border: 1px solid rgba(0,229,168,0.4);
  border-radius: 12px;
  padding: 0.55rem 1.6rem 0.55rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text);
  max-width: 240px;
  line-height: 1.35;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
}
.helper-bubble.show {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
.helper-bubble::after {
  display: none;
  content: '';
  position: absolute;
  right: -6px;
  bottom: 14px;
  width: 10px;
  height: 10px;
  background: rgba(18,24,38,0.96);
  border-right: 1px solid rgba(0,229,168,0.4);
  border-top: 1px solid rgba(0,229,168,0.4);
  transform: rotate(45deg);
}
.helper-close {
  position: absolute;
  top: 2px;
  right: 4px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 5px;
}
.helper-close:hover { color: var(--text); }

/* HATA İPUCU BALONU (çarpışma noktasında) */
.hint-toast {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -10px);
  background: rgba(255,107,74,0.95);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 14;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 300px;
  text-align: center;
  box-shadow: 0 6px 22px rgba(0,0,0,0.5);
}
.hint-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* AŞAMALAR POPUP */
.stages-modal { max-width: 520px; width: 92%; }
.stages-modal h2 { color: var(--accent); }
.stages-progress {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.6rem 0 0.3rem;
}
.stages-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #00e5a8, #38bdf8);
  width: 0%;
  transition: width 0.5s ease;
  border-radius: 999px;
}
.stages-progress-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: right;
  margin-bottom: 0.4rem;
}
.stages-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin: 1rem 0;
}
.stage-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.35rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.stage-card:hover:not(.locked) {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.stage-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(0,229,168,0.4);
}
.stage-card.done { border-color: rgba(74,222,128,0.5); }
.stage-card.locked { opacity: 0.45; cursor: not-allowed; }
.stage-card .stage-num {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stage-card .stage-stars {
  font-size: 0.65rem;
  letter-spacing: 1px;
  margin-top: 0.3rem;
  line-height: 1;
}
.stage-card .stage-stars .star-on { color: var(--star-fill); }
.stage-card .stage-stars .star-off { color: var(--star-empty); }
.stage-card .stage-lock {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.7rem;
}

/* AŞAMA BİLGİ POPUP */
.stage-info-modal { max-width: 420px; width: 90%; }
.stage-info-modal h2 { color: var(--accent); margin-bottom: 0.6rem; }
.stage-info-modal p { color: var(--muted); font-size: 0.85rem; line-height: 1.5; margin-bottom: 0.4rem; text-align: left; }
.stage-info-modal .stage-info-tip { color: var(--blue); font-size: 0.78rem; }

/* YENİ BLOK MODAL */
.newblock-modal { max-width: 380px; width: 90%; }
.newblock-badge {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
  animation: badgePop 0.6s ease;
}
@keyframes badgePop {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.newblock-modal h2 { color: var(--blue); margin-bottom: 0.5rem; }

/* Log (küçük, hata odaklı) */
.log {
  position: absolute;
  bottom: 4.5rem;
  left: 0.75rem;
  max-width: 220px;
  max-height: 60px;
  overflow-y: auto;
  padding: 0.35rem 0.55rem;
  font-family: 'JetBrains Mono', monospace; font-size: 0.58rem;
  background: rgba(10,14,22,0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  z-index: 10;
  pointer-events: auto;
  opacity: 0.55;
  transition: opacity 0.2s;
}
.log:hover { opacity: 1; }
.log:empty { display: none; }
.log .ok { color: var(--green); } .log .err { color: var(--warn); } .log .info { color: var(--blue); }

/* Modal genel */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.72);
  z-index: 100; display: none; align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.75rem 2rem; max-width: 380px; width: 90%; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5); animation: modalIn 0.35s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal .success-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%; margin-bottom: 0.75rem;
  background: var(--accent-dim); border: 2px solid var(--accent); color: var(--accent);
  font-size: 1.1rem; font-weight: 700; letter-spacing: 0.04em;
}
.modal h2 { font-family: var(--font-display); font-size: 1.45rem; margin-bottom: 0.35rem; color: var(--accent); }
.modal p { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.6rem; line-height: 1.45; }
.win-stars { font-size: 1.6rem; letter-spacing: 4px; margin-bottom: 0.4rem; }
.win-stars .star-on { color: var(--star-fill); text-shadow: 0 0 10px rgba(255,204,77,0.7); }
.win-stars .star-off { color: var(--star-empty); }
.win-badges {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 0.8rem;
  min-height: 1.6rem;
  font-size: 1.4rem;
  flex-wrap: wrap;
}
.win-badges .badge {
  animation: badgePop 0.5s ease;
  filter: drop-shadow(0 0 8px rgba(255,204,77,0.5));
}
.win-badges .badge[title] { cursor: help; }
.modal .btn-row { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }
.modal .btn-next {
  background: var(--accent); color: #04120e; padding: 0.7rem 1.4rem; border-radius: 12px; font-size: 0.95rem;
}
.modal .btn-next:hover { filter: brightness(1.1); }
.modal .btn-stay {
  background: var(--surface-2); color: var(--text); padding: 0.7rem 1.2rem;
  border-radius: 12px; border: 1px solid var(--border); font-size: 0.9rem;
}

/* Intro modal */
.intro-modal {
  max-width: 460px; text-align: left; position: relative; overflow: hidden;
  background:
    linear-gradient(rgba(0,229,168,0.05), rgba(0,229,168,0.05)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0px, rgba(255,255,255,0.025) 1px, transparent 1px, transparent 3px),
    linear-gradient(180deg, #0e1626, #0a0f1a);
  border: 1px solid rgba(0,229,168,0.35);
  box-shadow: 0 0 0 1px rgba(0,229,168,0.12), 0 0 40px rgba(0,229,168,0.15), 0 20px 60px rgba(0,0,0,0.6);
}
.intro-modal { --corner: 22px; }
.intro-modal > * { position: relative; z-index: 1; }
.intro-modal::before {
  content: ''; position: absolute; inset: 10px; pointer-events: none; z-index: 2;
  border-top: 2px solid rgba(0,229,168,0.65); border-left: 2px solid rgba(0,229,168,0.65);
  width: var(--corner); height: var(--corner);
}
.intro-modal::after {
  content: ''; position: absolute; right: 10px; bottom: 10px; pointer-events: none; z-index: 2;
  border-bottom: 2px solid rgba(0,229,168,0.65); border-right: 2px solid rgba(0,229,168,0.65);
  width: var(--corner); height: var(--corner);
}
.intro-modal .scanline {
  position: absolute; left: 0; right: 0; top: 0; height: 40%;
  background: linear-gradient(180deg, transparent, rgba(0,229,168,0.06), transparent);
  animation: scanSweep 4s linear infinite; pointer-events: none; z-index: 0;
}
@keyframes scanSweep { 0% { transform: translateY(-100%); } 100% { transform: translateY(250%); } }
.intro-modal h2 {
  font-family: var(--font-display); text-align: center; margin-bottom: 0.6rem;
  text-transform: uppercase; letter-spacing: 0.1em; font-size: 1.2rem;
  color: var(--accent); text-shadow: 0 0 12px rgba(0,229,168,0.5);
}
.intro-typewriter {
  min-height: 7.5em; font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem; line-height: 1.65; color: #b8f5df;
  white-space: pre-wrap; margin-bottom: 1.2rem;
  padding-left: 0.7rem; border-left: 2px solid rgba(0,229,168,0.3);
}
.intro-typewriter::after {
  content: '▋';
  color: var(--accent);
  animation: caretBlink 0.85s step-end infinite;
  margin-left: 1px;
}
.intro-typewriter.done::after { content: ''; }
@keyframes caretBlink { 50% { opacity: 0; } }
#btn-intro-start:disabled { opacity: 0.4; cursor: not-allowed; }
.intro-modal .btn-row { justify-content: center; }
.intro-modal #btn-intro-start {
  letter-spacing: 0.08em;
  box-shadow: 0 0 0 1px rgba(0,229,168,0.4), 0 0 20px rgba(0,229,168,0.25);
}

/* Responsive */
@media (max-width: 1600px) {
  :root { --panel-w: 460px; }
  .sidebar-header a.logo { font-size: 1.2rem; }
  .hud-card { font-size: 0.7rem; padding: 0.4rem 0.6rem; }
}

@media (max-width: 1440px) {
  :root { --panel-w: 400px; }
  .overlay-hud { top: 0.5rem; left: 0.5rem; right: 0.5rem; gap: 0.35rem; }
  .toolbar { padding: 0.4rem 0.55rem; gap: 0.3rem; }
  button { font-size: 0.68rem; }
  .btn-primary { padding: 0.42rem 0.65rem; }
  .telemetry-hud { font-size: 0.68rem; min-width: 130px; }
  .stage-info { max-width: 320px; min-width: 240px; }
}

@media (max-width: 1280px) {
  :root { --panel-w: 360px; }
  .sidebar-header { padding: 0.6rem 0.7rem; }
  .editor-tab { font-size: 0.64rem; padding: 0.45rem 0.3rem; }
  .level-caption-bar { font-size: 0.68rem; padding: 0.35rem 0.55rem; }
  .controls-hint { font-size: 0.58rem; padding: 0.28rem 0.6rem; }
  .fab-blocks { padding: 0.55rem 0.5rem; }
}

@media (max-height: 850px) {
  .sidebar-header { padding: 0.5rem 0.75rem; }
  .toolbar { padding: 0.35rem 0.55rem; }
  .modal { padding: 1.2rem 1.4rem; }
  .intro-typewriter { min-height: 5.5em; font-size: 0.76rem; }
  .helper { bottom: 5.5rem; }
}

@media (max-height: 720px) {
  .hud-stack { gap: 0.25rem; }
  .controls-hint { bottom: 3.5rem; }
  .telemetry-hud { font-size: 0.62rem; min-width: 120px; }
}

@media (max-width: 1100px) {
  :root { --panel-w: 320px; }
  #app { grid-template-columns: 40px 1fr; }
  .block-toggle { padding: 0.5rem 0; }
  .block-toggle .toggle-icon { width: 28px; height: 28px; }
}

/* ─── Mobile portrait: stage on top, blocks below (OctoStudio-style) ─── */
@media (max-width: 900px), (max-width: 1100px) and (orientation: portrait) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
  }

  #app,
  #app.blocks-open {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 42dvh) minmax(240px, 1fr);
    grid-template-areas:
      "viewport"
      "editor";
    height: 100dvh;
    height: 100svh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .block-toggle { display: none !important; }

  .viewport {
    grid-area: viewport;
    min-height: 0;
    min-width: 0;
  }

  .sidebar {
    grid-area: editor;
    display: flex !important;
    flex-direction: column;
    min-height: 0;
    max-height: none;
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .fab-blocks { display: none !important; }

  .sidebar-header {
    padding: 0.4rem 0.65rem;
  }
  .sidebar-header a.logo { font-size: 1rem; }
  .btn-collapse { display: none; }

  .editor-tabs { flex-shrink: 0; }
  .editor-tab { font-size: 0.62rem; padding: 0.42rem 0.25rem; }

  .toolbar {
    padding: 0.4rem 0.55rem;
    gap: 0.35rem;
    position: sticky;
    top: 0;
    z-index: 5;
  }
  .btn-primary {
    padding: 0.62rem 0.85rem;
    font-size: 0.82rem;
    border-radius: 12px;
  }
  .btn-danger { padding: 0.55rem 0.7rem; }

  #blocklyDiv { min-height: 0; touch-action: none; }

  .level-caption-bar {
    font-size: 0.64rem;
    padding: 0.28rem 0.55rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .overlay-hud {
    top: 0.4rem;
    left: 0.4rem;
    right: 0.4rem;
    gap: 0.3rem;
    align-items: flex-start;
  }
  .hud-stack {
    align-items: flex-end;
    width: auto;
    max-width: 46%;
  }
  .hud-card { font-size: 0.62rem; padding: 0.28rem 0.42rem; }
  .hud-card.hud-right { flex-wrap: wrap; justify-content: flex-end; }

  .telemetry-hud {
    min-width: 0;
    padding: 0.22rem 0.4rem;
    font-size: 0.56rem;
    gap: 0.45rem;
  }

  .settings-wrap {
    left: 0.45rem;
    right: auto;
    bottom: 0.4rem;
    transform: none;
    align-items: flex-start;
  }
  .btn-settings { width: 38px; height: 38px; font-size: 1.05rem; }
  .settings-bar {
    gap: 0.28rem;
    padding: 0.28rem 0.4rem;
    max-width: calc(100vw - 1.2rem);
    border-radius: 10px;
  }
  .btn-theme, .btn-cam, .btn-lang, .btn-mute {
    font-size: 0.58rem;
    padding: 0.22rem 0.36rem;
  }

  .controls-hint { display: none; }

  .stage-info {
    max-width: min(210px, 52vw);
    min-width: 0;
    bottom: 2.55rem;
    right: 0.4rem;
    padding: 0.45rem 0.55rem 0.5rem;
    border-radius: 10px;
  }
  .stage-info strong { font-size: 0.72rem; margin-bottom: 0.15rem; }
  .stage-info-caption { font-size: 0.62rem; margin-bottom: 0.1rem; }
  .stage-info-tip,
  .stage-info-next,
  .stage-info-hint { display: none; }
  .stage-info-progress { font-size: 0.58rem; margin-top: 0.25rem; padding-top: 0.25rem; }

  .helper {
    bottom: 2.55rem;
    left: 0.4rem;
    right: auto;
  }
  .helper-bubble {
    right: auto;
    left: 0;
    max-width: 170px;
    font-size: 0.62rem;
  }
  .helper-bubble::after {
    right: auto;
    left: -6px;
    border-right: none;
    border-left: 1px solid rgba(0,229,168,0.4);
  }

  .hint-toast {
    top: 22%;
    max-width: 86vw;
    font-size: 0.72rem;
    padding: 0.45rem 0.7rem;
  }

  .modal-overlay { align-items: flex-end; }
  .modal {
    max-width: 100vw;
    width: 100%;
    padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
  }
  .intro-modal {
    max-width: 100vw;
    border-radius: 16px 16px 0 0;
  }
  .intro-typewriter { min-height: 5em; font-size: 0.74rem; }
  .stages-grid { grid-template-columns: repeat(3, 1fr); gap: 0.45rem; }
}

@media (max-width: 600px) {
  #app,
  #app.blocks-open {
    grid-template-rows: minmax(180px, 38dvh) minmax(220px, 1fr);
  }
  .btn-theme, .btn-cam, .btn-lang { font-size: 0.56rem; padding: 0.2rem 0.32rem; }
  .stages-grid { grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
  .stage-info { max-width: 46vw; padding: 0.38rem 0.48rem; }
  .stage-info-caption { display: none; }
  .telemetry-hud { font-size: 0.54rem; padding: 0.18rem 0.35rem; }
  .telemetry-hud .telem-row span { font-size: 0.5rem; }
  .telemetry-hud .telem-row strong { font-size: 0.56rem; }
  .helper-bubble { max-width: 150px; font-size: 0.6rem; }
  .cam-group .btn-cam[data-cam="orbit"] { display: none; }
}

@media (max-width: 900px) and (max-height: 700px) {
  #app,
  #app.blocks-open {
    grid-template-rows: minmax(160px, 34dvh) minmax(200px, 1fr);
  }
  .telemetry-hud { padding: 0.16rem 0.3rem; }
}

@media (max-width: 900px) and (orientation: landscape) {
  #app,
  #app.blocks-open {
    grid-template-columns: minmax(220px, 42vw) 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "editor viewport";
  }
  .sidebar { border-top: none; border-right: 1px solid var(--border); }
  .modal-overlay { align-items: center; }
  .modal { border-radius: 16px; width: 90%; max-width: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  .stage-info::before, .status-dot, .intro-modal .scanline { animation: none; }
}