/* =========================================================
   NEURAL TYCOON — arayüz
   ========================================================= */
:root {
  --bg: #0e1522;
  --panel: rgba(17, 25, 40, 0.92);
  --panel-solid: #131c2c;
  --line: rgba(255, 255, 255, 0.10);
  --text: #e8eef8;
  --muted: #8fa0b8;
  --accent: #34d3ee;
  --accent2: #7c6bff;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --gold: #ffd66b;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --r: 14px;

  /* Yerleşim ölçüleri — mobil sorgular bunları değiştirir. */
  --hud-h: 62px;
  --rail-h: 0px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }

button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; }
h2, h3, h4 { font-weight: 700; letter-spacing: .2px; }
.hidden { display: none !important; }

/* ---------------- ÜST HUD ---------------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; height: 62px; z-index: 30;
  display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: linear-gradient(180deg, rgba(10, 16, 27, .95), rgba(10, 16, 27, .74));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.brand .logo { font-size: 26px; filter: drop-shadow(0 0 8px rgba(52, 211, 238, .6)); }
.brand-text { min-width: 0; }
.brand-name { font-weight: 800; font-size: 13px; letter-spacing: 2px; color: var(--accent); }
.brand-sub {
  display: block; font-size: 12px; color: var(--muted); text-align: left;
  max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 1px 5px; margin-left: -5px; border-radius: 6px; transition: .14s;
}
.brand-sub:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.brand-sub::after { content: " ✎"; opacity: .5; font-size: 10px; }

.res-bar { display: flex; gap: 6px; flex: 1; overflow: hidden; }
.res {
  display: flex; align-items: center; gap: 8px; padding: 6px 11px; border-radius: 10px;
  background: rgba(255, 255, 255, .045); border: 1px solid var(--line); white-space: nowrap;
}
.res .ico { font-size: 17px; }
.res b { display: block; font-size: 14px; font-weight: 700; }
.res i { display: block; font-size: 10.5px; color: var(--muted); font-style: normal; }
.res.alert { border-color: rgba(248, 113, 113, .6); background: rgba(248, 113, 113, .12); }
.res.good b { color: var(--good); }

.time-box { display: flex; align-items: center; gap: 12px; }
.conn {
  display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted);
  padding: 4px 9px; border-radius: 8px; background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line); white-space: nowrap;
}
.conn.ok { color: var(--good); border-color: rgba(74, 222, 128, .35); }
.conn.bad { color: var(--bad); border-color: rgba(248, 113, 113, .45); }
/* Online'da hız düğmeleri anlamsız — zaman sunucuda akıyor. */
body.online-mode .speeds { display: none; }
.date { font-size: 13px; color: var(--muted); min-width: 96px; text-align: right; }
.speeds { display: flex; gap: 3px; background: rgba(255, 255, 255, .05); padding: 3px; border-radius: 10px; }
.spd {
  padding: 5px 9px; border-radius: 7px; font-size: 11px; color: var(--muted);
  transition: .15s;
}
.spd:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.spd.active { background: var(--accent); color: #04222a; font-weight: 700; }

/* ---------------- SOL RAY ---------------- */
#rail {
  position: fixed; left: 12px; top: 74px; z-index: 28;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px; box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.rail-btn {
  width: 58px; padding: 8px 4px; border-radius: 10px; text-align: center; transition: .15s;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.rail-btn span { font-size: 20px; line-height: 1; }
.rail-btn em { font-style: normal; font-size: 10px; color: var(--muted); }
.rail-btn:hover { background: rgba(255, 255, 255, .08); }
.rail-btn.active { background: linear-gradient(160deg, var(--accent), #1b8fb0); }
.rail-btn.active em { color: #04222a; font-weight: 700; }
.rail-btn.small span { font-size: 15px; }
.rail-sep { height: 1px; background: var(--line); margin: 4px 2px; }

/* ---------------- PANEL ---------------- */
#panel {
  position: fixed; left: 96px; top: 74px; bottom: 16px; width: 396px; z-index: 27;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); backdrop-filter: blur(14px);
  display: flex; flex-direction: column; overflow: hidden;
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-14px); } }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.panel-head h2 { font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); }
#panel-close { font-size: 14px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
#panel-close:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.panel-body { flex: 1; overflow-y: auto; padding: 12px; }

.panel-body::-webkit-scrollbar, .inspector-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb, .inspector-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .14); border-radius: 4px;
}

/* ---------------- KARTLAR ---------------- */
.cat-title {
  font-size: 10.5px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted);
  margin: 14px 4px 7px;
}
.cat-title:first-child { margin-top: 2px; }

.card {
  display: flex; gap: 11px; padding: 10px; border-radius: 11px; margin-bottom: 7px;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line);
  cursor: pointer; transition: .14s; position: relative; align-items: flex-start;
}
.card:hover { background: rgba(52, 211, 238, .12); border-color: rgba(52, 211, 238, .45); transform: translateX(2px); }
.card.locked { opacity: .45; cursor: not-allowed; }
.card.locked:hover { transform: none; background: rgba(255, 255, 255, .04); border-color: var(--line); }
.card.done { border-color: rgba(74, 222, 128, .45); background: rgba(74, 222, 128, .08); }
.card.active-node { border-color: var(--accent); background: rgba(52, 211, 238, .12); }
.card .cico { font-size: 22px; width: 30px; text-align: center; flex: 0 0 auto; }
.card .cbody { flex: 1; min-width: 0; }
.card h4 { font-size: 13px; margin-bottom: 2px; }
.card p { font-size: 11.5px; color: var(--muted); line-height: 1.42; }
.card .cost { font-size: 11.5px; font-weight: 700; color: var(--gold); margin-top: 4px; }
.card .cost.no { color: var(--bad); }
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag {
  font-size: 10px; padding: 2px 6px; border-radius: 5px;
  background: rgba(255, 255, 255, .08); color: var(--muted);
}
.tag.g { background: rgba(74, 222, 128, .16); color: var(--good); }
.tag.b { background: rgba(248, 113, 113, .16); color: var(--bad); }
.tag.a { background: rgba(52, 211, 238, .16); color: var(--accent); }

/* ---------------- BUTONLAR ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 13px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  background: rgba(255, 255, 255, .08); border: 1px solid var(--line); transition: .14s;
}
.btn:hover { background: rgba(255, 255, 255, .15); }
.btn.primary { background: linear-gradient(160deg, var(--accent), #1a8aab); color: #052029; border: none; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.violet { background: linear-gradient(160deg, var(--accent2), #4c3fd0); color: #fff; border: none; }
.btn.danger { background: rgba(248, 113, 113, .18); color: var(--bad); border-color: rgba(248, 113, 113, .35); }
.btn.gold { background: linear-gradient(160deg, #ffd66b, #e0a33a); color: #3a2a05; border: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.sm { padding: 5px 9px; font-size: 11px; }
.row { display: flex; gap: 7px; }
.row.wrap { flex-wrap: wrap; }

/* ---------------- İLERLEME ---------------- */
.bar { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, .1); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
.bar.gold > i { background: linear-gradient(90deg, var(--gold), #f59e0b); }
.bar.green > i { background: linear-gradient(90deg, var(--good), #16a34a); }

/* ---------------- İSTATİSTİK SATIRI ---------------- */
.stat-list { display: flex; flex-direction: column; gap: 1px; }
.stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 9px; border-radius: 7px; font-size: 12px;
}
.stat:nth-child(odd) { background: rgba(255, 255, 255, .035); }
.stat span { color: var(--muted); }
.stat b { font-weight: 700; }
.stat b.pos { color: var(--good); } .stat b.neg { color: var(--bad); }

.hint {
  font-size: 11.5px; color: var(--muted); line-height: 1.5;
  background: rgba(52, 211, 238, .08); border-left: 2px solid var(--accent);
  padding: 8px 10px; border-radius: 0 8px 8px 0; margin-bottom: 10px;
}

/* ---------------- INSPECTOR ---------------- */
#inspector {
  position: fixed; right: 12px; bottom: 12px; width: 300px; z-index: 27;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); backdrop-filter: blur(14px); overflow: hidden;
  animation: slideUp .18s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } }
.insp-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.insp-head .cico { font-size: 24px; }
.insp-head h3 { font-size: 14px; }
.insp-head p { font-size: 11px; color: var(--muted); }
.inspector-body { padding: 11px 14px; max-height: 46vh; overflow-y: auto; }

/* ---------------- KOŞU WIDGET ---------------- */
#runs-widget {
  position: fixed; right: 12px; top: 74px; width: 300px; z-index: 26;
  display: flex; flex-direction: column; gap: 8px;
}
.run-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.run-card .rtop { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.run-card .rtop b { font-size: 12.5px; }
.run-card .rsub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.pri { display: flex; gap: 3px; }
.pri button {
  width: 22px; height: 20px; border-radius: 5px; font-size: 10px;
  background: rgba(255, 255, 255, .07); color: var(--muted);
}
.pri button.on { background: var(--accent); color: #04222a; font-weight: 700; }

/* ---------------- TOAST ---------------- */
#toasts {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; flex-direction: column; gap: 7px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--panel-solid); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 9px 15px; border-radius: 9px; font-size: 12.5px; box-shadow: var(--shadow);
  animation: toastIn .25s ease; max-width: 460px;
}
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.96); } }
.toast.out { animation: toastOut .3s ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }

/* ---------------- YERLEŞTİRME İPUCU ---------------- */
#place-hint {
  position: fixed; bottom: calc(18px + var(--rail-h) + var(--safe-b));
  left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--panel-solid); border: 1px solid var(--accent); border-radius: 12px;
  padding: 9px 16px; font-size: 12.5px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 24px);
}
#place-hint .k {
  background: rgba(255, 255, 255, .12); padding: 1px 6px; border-radius: 4px; font-size: 11px;
}
#place-hint .ph-touch { display: none; flex-direction: column; line-height: 1.3; }
#place-hint .ph-touch small { color: var(--muted); font-size: 10.5px; }
#place-hint .ph-actions { display: none; gap: 7px; }

/* Parmakla yerleştirmede ekran ortasındaki nişangâh */
#place-cross {
  position: fixed; left: 50%; top: 50%; width: 42px; height: 42px; z-index: 24;
  transform: translate(-50%, -50%); pointer-events: none;
  background:
    linear-gradient(var(--accent), var(--accent)) center/2px 100% no-repeat,
    linear-gradient(var(--accent), var(--accent)) center/100% 2px no-repeat;
  opacity: .55; border-radius: 50%;
}

/* ---------------- HEDEFLER ---------------- */
.goal {
  display: flex; gap: 9px; align-items: flex-start; padding: 8px 9px;
  border-radius: 9px; margin-bottom: 4px; background: rgba(255, 255, 255, .035);
  border: 1px solid transparent;
}
.goal.done { background: rgba(74, 222, 128, .1); border-color: rgba(74, 222, 128, .3); }
.goal .gmark { font-size: 13px; line-height: 1.3; flex: 0 0 auto; }
.goal .gtext { display: flex; flex-direction: column; min-width: 0; }
.goal .gtext b { font-size: 12.5px; }
.goal.done .gtext b { color: var(--good); }
.goal .gtext small { font-size: 11px; color: var(--muted); line-height: 1.4; }

/* ---------------- FORM ALANI ---------------- */
.field { margin: 14px 0 4px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 11px 13px; border-radius: 10px; font-size: 14px;
  font-family: inherit; color: var(--text); background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line); outline: none; user-select: text;
}
.field input:focus { border-color: var(--accent); background: rgba(52, 211, 238, .1); }

.dot.big { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }

/* ---------------- MODAL ---------------- */
#modal-wrap {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 9, 16, .72); backdrop-filter: blur(6px); animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
#modal {
  width: min(620px, 92vw); max-height: 88vh; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, .6); animation: pop .22s cubic-bezier(.2, 1.3, .5, 1);
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.modal-head { padding: 22px 26px 12px; display: flex; gap: 14px; align-items: center; }
.modal-head .mico { font-size: 38px; }
.modal-head h2 { font-size: 21px; }
.modal-head p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.modal-body { padding: 0 26px 8px; font-size: 13.5px; line-height: 1.62; color: #cfdcee; }
.modal-choices { padding: 14px 20px 22px; display: flex; flex-direction: column; gap: 9px; }
.choice {
  text-align: left; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04); transition: .15s;
}
.choice:hover { background: rgba(52, 211, 238, .12); border-color: var(--accent); transform: translateX(3px); }
.choice b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.choice small { color: var(--muted); font-size: 11.5px; }

.intro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.intro-card {
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line);
  border-radius: 11px; padding: 12px;
}
.intro-card h4 { font-size: 12.5px; margin-bottom: 4px; color: var(--accent); }
.intro-card p { font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* Seçilebilir kart (ayarlar) */
button.intro-card { display: block; width: 100%; text-align: left; transition: .14s; }
button.intro-card:hover { background: rgba(255, 255, 255, .07); }
button.intro-card.active {
  background: rgba(52, 211, 238, .14); border-color: rgba(52, 211, 238, .55);
}
button.intro-card.active h4::after { content: " ✓"; }

/* ---------------- RAKİP LİSTESİ ---------------- */
.rival { display: flex; align-items: center; gap: 9px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.rival:last-child { border: none; }
.rival .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.rival .rname { flex: 1; font-size: 12.5px; }
.rival .rscore { font-size: 12px; font-weight: 700; }
.rival.you { background: rgba(52, 211, 238, .1); border-radius: 8px; }

/* ---------------- LOG ---------------- */
.log-line { font-size: 11.5px; padding: 6px 8px; border-radius: 6px; color: #c2d0e2; line-height: 1.45; }
.log-line:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.log-line .d { color: var(--muted); font-size: 10px; margin-right: 6px; }

/* ---------------- TOOLTIP ---------------- */
#tooltip {
  position: fixed; z-index: 90; pointer-events: none; max-width: 250px;
  background: #0b1220; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; font-size: 11.5px; color: #cfdcee; box-shadow: var(--shadow); line-height: 1.45;
}

/* ---------------- SEGMENT ---------------- */
.seg { display: flex; gap: 4px; background: rgba(255, 255, 255, .05); padding: 3px; border-radius: 9px; margin-bottom: 11px; }
.seg button { flex: 1; padding: 6px; border-radius: 7px; font-size: 11.5px; color: var(--muted); }
.seg button.on { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 700; }

.score-badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-weight: 800; font-size: 12px;
  background: rgba(255, 255, 255, .1);
}
.score-badge.s1 { background: rgba(248, 113, 113, .2); color: var(--bad); }
.score-badge.s2 { background: rgba(251, 191, 36, .2); color: var(--warn); }
.score-badge.s3 { background: rgba(74, 222, 128, .2); color: var(--good); }
.score-badge.s4 { background: linear-gradient(120deg, var(--accent), var(--accent2)); color: #04222a; }

/* =========================================================
   DAR EKRAN / TABLET
   ========================================================= */
@media (max-width: 1240px) {
  .res-bar { overflow-x: auto; scrollbar-width: none; }
  .res-bar::-webkit-scrollbar { display: none; }
  #runs-widget { width: 260px; }
  #panel { width: 350px; }
}

/* Tablet: sol ray kalır ama panel daralır, koşular alta iner. */
@media (max-width: 1024px) {
  .brand { min-width: 0; }
  .brand-name { display: none; }
  .brand-sub { max-width: 120px; font-size: 12.5px; }
  #panel { width: 340px; }
  #inspector { width: 268px; }
  #runs-widget {
    top: auto; bottom: calc(12px + var(--safe-b)); right: 12px; width: 268px;
    max-height: 42vh; overflow-y: auto;
  }
  /* Denetçi açıkken koşular onun üstüne çıkmasın */
  #inspector:not(.hidden) ~ #runs-widget { display: none; }
}

/* =========================================================
   TELEFON — ray alta, paneller alt sayfa (bottom sheet)
   ========================================================= */
@media (max-width: 780px) {
  :root { --hud-h: 96px; --rail-h: 62px; }

  /* ---- HUD: iki satır ---- */
  #hud {
    height: auto; min-height: var(--hud-h);
    padding: calc(6px + var(--safe-t)) calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l));
    flex-wrap: wrap; gap: 8px 10px; align-items: center;
  }
  .brand { order: 1; flex: 1 1 auto; min-width: 0; }
  .brand .logo { font-size: 21px; }
  .brand-sub { max-width: 46vw; font-size: 12px; }
  .time-box { order: 2; flex: 0 0 auto; gap: 8px; }
  .date { min-width: 0; font-size: 11.5px; }
  .res-bar {
    order: 3; flex: 1 0 100%; gap: 5px; padding-bottom: 2px;
    scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  }
  .res { padding: 5px 9px; gap: 6px; scroll-snap-align: start; }
  .res .ico { font-size: 14px; }
  .res b { font-size: 12.5px; }
  .res i { font-size: 9.5px; }
  .speeds { padding: 2px; }
  .spd { padding: 7px 10px; font-size: 11px; }

  /* ---- Ray: alt gezinme çubuğu ---- */
  #rail {
    left: 0; right: 0; top: auto; bottom: 0; height: calc(var(--rail-h) + var(--safe-b));
    flex-direction: row; justify-content: flex-start; gap: 2px;
    border-radius: 0; border-left: none; border-right: none; border-bottom: none;
    padding: 5px calc(6px + var(--safe-r)) calc(5px + var(--safe-b)) calc(6px + var(--safe-l));
    overflow-x: auto; scrollbar-width: none; z-index: 32;
  }
  #rail::-webkit-scrollbar { display: none; }
  .rail-sep { height: auto; width: 1px; margin: 6px 3px; flex: 0 0 auto; }
  .rail-btn { width: auto; min-width: 56px; flex: 0 0 auto; padding: 5px 8px; gap: 2px; }
  .rail-btn span { font-size: 18px; }
  .rail-btn em { font-size: 9.5px; }

  /* ---- Panel: alt sayfa ---- */
  #panel {
    left: 0; right: 0; width: auto;
    top: auto; bottom: calc(var(--rail-h) + var(--safe-b));
    height: min(62dvh, 520px);
    border-radius: 18px 18px 0 0; border-left: none; border-right: none; border-bottom: none;
    animation: sheetIn .2s ease;
  }
  .panel-head { padding: 12px 16px; }
  .panel-body {
    padding: 12px calc(12px + var(--safe-r)) 16px calc(12px + var(--safe-l));
    -webkit-overflow-scrolling: touch;
  }
  /* Alt sayfayı sürüklemek için tutamak */
  .panel-head::before {
    content: ""; position: absolute; left: 50%; top: 5px; width: 38px; height: 4px;
    transform: translateX(-50%); border-radius: 3px; background: rgba(255, 255, 255, .22);
  }
  .panel-head { position: relative; }

  /* ---- Denetçi: rayın üstünde tam genişlik ---- */
  #inspector {
    left: 8px; right: 8px; width: auto;
    bottom: calc(var(--rail-h) + var(--safe-b) + 8px);
  }
  .inspector-body { max-height: 34dvh; }

  /* ---- Koşular: HUD altında yatay şerit ---- */
  #runs-widget {
    left: 0; right: 0; width: auto; top: calc(var(--hud-h) + 6px); bottom: auto;
    flex-direction: row; gap: 7px; max-height: none;
    padding: 0 calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  }
  #runs-widget::-webkit-scrollbar { display: none; }
  .run-card { flex: 0 0 232px; padding: 8px 10px; }
  #inspector:not(.hidden) ~ #runs-widget { display: flex; }
  /* Panel açıkken şerit gizlensin — ekran zaten dolu */
  #panel:not(.hidden) ~ #runs-widget { display: none; }

  /* ---- Yerleştirme: dokunmatik akış ---- */
  #place-hint {
    left: 8px; right: 8px; transform: none; max-width: none;
    bottom: calc(var(--rail-h) + var(--safe-b) + 10px);
    justify-content: space-between; padding: 8px 10px;
  }
  #place-hint .ph-text { display: none; }
  #place-hint .ph-touch { display: flex; }
  #place-hint .ph-actions { display: flex; }
  #inspector:not(.hidden) { bottom: calc(var(--rail-h) + var(--safe-b) + 8px); }

  /* ---- Modal ---- */
  #modal {
    width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0;
    margin-top: auto; animation: sheetIn .22s ease;
  }
  #modal-wrap { align-items: flex-end; }
  .modal-head { padding: 18px 18px 10px; }
  .modal-head .mico { font-size: 30px; }
  .modal-head h2 { font-size: 18px; }
  .modal-body { padding: 0 18px 8px; font-size: 13px; }
  .modal-choices { padding: 12px 14px calc(18px + var(--safe-b)); }
  .intro-grid { grid-template-columns: 1fr; }

  /* ---- Toast ---- */
  #toasts { top: calc(var(--hud-h) + 8px); width: calc(100vw - 24px); }
  .toast { width: 100%; font-size: 12px; }

  /* Panel açıkken toast'lar üstte kalsın */
  #tooltip { display: none !important; }
}

@media (max-width: 400px) {
  .brand-name, .rail-btn em { display: none; }
  .rail-btn { min-width: 46px; padding: 8px 6px; }
  .rail-btn span { font-size: 20px; }
  :root { --rail-h: 52px; }
}

/* Yatay tutulan telefon: yükseklik az, HUD ve panel kısılır. */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --hud-h: 52px; --rail-h: 0px; }
  #hud { min-height: 52px; height: 52px; flex-wrap: nowrap; }
  .res-bar { order: 0; flex: 1 1 auto; }
  #rail {
    left: calc(6px + var(--safe-l)); right: auto; top: 58px; bottom: 8px; height: auto;
    flex-direction: column; border-radius: var(--r); padding: 5px;
    /* Yatayda yükseklik az — ray kendi içinde kaysın, ekrandan taşmasın. */
    max-height: calc(100dvh - 66px); overflow-y: auto; overflow-x: visible;
    scrollbar-width: none;
  }
  #rail::-webkit-scrollbar { display: none; }
  .rail-btn { min-width: 0; width: 44px; }
  .rail-btn em { display: none; }
  #panel {
    left: calc(74px + var(--safe-l)); right: auto; width: 320px;
    top: 58px; bottom: 8px; height: auto; border-radius: var(--r);
  }
  #inspector { left: auto; right: 8px; width: 250px; bottom: 8px; }
  #runs-widget { top: 58px; left: auto; right: 8px; width: 250px; flex-direction: column; }
}

/* Parmakla kullanımda tıklama alanları büyür, hover efektleri kapanır. */
@media (pointer: coarse) {
  .btn { padding: 11px 14px; font-size: 13px; }
  .btn.sm { padding: 9px 12px; font-size: 12px; }
  .card { padding: 12px; }
  .card:hover { transform: none; background: rgba(255, 255, 255, .04); border-color: var(--line); }
  .card:active { background: rgba(52, 211, 238, .16); border-color: rgba(52, 211, 238, .5); }
  .choice:hover { transform: none; }
  .pri button { width: 30px; height: 28px; font-size: 12px; }
  #panel-close { padding: 8px 12px; font-size: 16px; }
  .seg button { padding: 10px 6px; font-size: 12px; }
  .brand-sub::after { content: " ✎"; opacity: .8; }
}

@keyframes sheetIn { from { opacity: 0; transform: translateY(24px); } }
