:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1b263d;
  --text: #eef2f8;
  --muted: #9aa8bf;
  --accent: #e30a17;
  --accent-2: #ff4d57;
  --good: #22c55e;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --topbar-h: 52px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; min-height: 100dvh; }
main { flex: 1; position: relative; }
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.2; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.25rem; }
p { line-height: 1.5; }
.hidden { display: none !important; }
/* Dokunmatik: çift dokunma yakınlaştırması ve gri vurgu olmasın, dokunuş anında tıklama sayılsın. */
button, a, input, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Üst bar */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; font-size: 1.1rem; letter-spacing: 0.2px; }
.brand-pin { margin-right: 2px; }
.day-label { color: var(--muted); font-weight: 600; margin-left: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-weight: 700; cursor: pointer;
}

/* Butonlar ve kartlar */
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 0.95rem;
  background: var(--panel-2); color: var(--text); cursor: pointer; transition: transform 0.05s, background 0.15s;
}
.btn:active:not(:disabled) { background: #26334f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--accent-2); }
/* Hover efektleri sadece gerçek fareli cihazlarda: iOS'ta dokunma "yapışkan hover" bırakır,
   hover ile görünüm değişirse Safari/Firefox ilk dokunuşu yutar (butona iki kez basmak gerekir). */
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { background: #26334f; }
  .btn-primary:hover:not(:disabled) { background: var(--accent-2); }
}
.btn-lg { padding: 14px 22px; font-size: 1.05rem; width: 100%; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }

/* Ekranlar */
.screen { position: absolute; inset: 0; overflow: auto; }
#screen-intro { display: grid; place-items: center; padding: 20px; }
.intro-card { max-width: 460px; width: 100%; }
.lead { font-size: 1.05rem; }
.rules { list-style: none; padding: 0; margin: 18px 0 22px; display: grid; gap: 10px; }
.rules li { display: flex; gap: 10px; align-items: center; background: var(--panel-2); padding: 10px 12px; border-radius: 10px; }

/* Oyun */
#screen-game { overflow: hidden; }
.pano { position: absolute; inset: 0; background: #000; }
.hud {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
}
.hud-item {
  background: rgba(11, 18, 32, 0.85); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; font-weight: 700; font-size: 0.9rem; color: var(--text); backdrop-filter: blur(4px);
}
.hud-btn { cursor: pointer; }
.hud-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.guess-panel {
  position: absolute; right: 14px; bottom: 34px; z-index: 6;
  width: 300px; display: flex; flex-direction: column; gap: 8px;
  transition: width 0.2s ease;
}
.guess-panel .map {
  height: 210px; border-radius: 12px; overflow: hidden; border: 2px solid rgba(255, 255, 255, 0.25);
  transition: height 0.2s ease; background: #1d2a44;
}
.guess-panel.expanded { width: min(560px, 60vw); }
.guess-panel.expanded .map { height: min(400px, 55vh); }
@media (hover: hover) and (pointer: fine) {
  .guess-panel:hover { width: min(560px, 60vw); }
  .guess-panel:hover .map { height: min(400px, 55vh); }
}
.map-toggle {
  display: none; align-self: flex-end; border: 1px solid var(--border); border-radius: 999px;
  background: rgba(11, 18, 32, 0.9); color: var(--text); padding: 8px 14px; font-weight: 700; font-size: 0.95rem;
}
/* Dokunmatik ekranlarda (tablet dahil) hover yok: harita butonla büyütülür. */
@media (pointer: coarse) { .map-toggle { display: block; } }
.guess-btn { width: 100%; }

/* Tur sonucu kartı: sol üstte; altta Google logosu ve yazıları görünür kalsın. */
.round-result {
  position: absolute; z-index: 8; left: 16px; top: 16px; width: min(420px, calc(100% - 32px));
  max-height: calc(100% - 56px); overflow: auto; overscroll-behavior: contain;
}
.result-card h2 { margin-bottom: 2px; }
/* Kart kaydırılsa da devam butonu hep görünür kalsın. */
.result-card #next-btn { position: sticky; bottom: 8px; box-shadow: 0 -10px 18px var(--panel), 0 8px 0 var(--panel); }
.rr-km { display: flex; align-items: center; gap: 12px; margin: 12px 0 2px; font-size: 2.6rem; font-weight: 900; }
.rr-emoji { font-size: 2rem; }
.rr-dir { margin: 0 0 12px; }
.learn p { background: var(--panel-2); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 8px; font-size: 0.92rem; margin: 8px 0; }
.learn p.clue { border-left-color: #ffd479; }

/* Kalabalık: herkes nasıl tahmin etti */
.crowd { background: var(--panel-2); border-radius: 12px; padding: 12px 14px; margin: 10px 0; }
.crowd-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.crowd-head strong { font-size: 1.05rem; }
.crowd-ext { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.88rem; margin-top: 6px; }
.crowd-empty { margin: 10px 0; }
.hist { margin: 26px 0 6px; }
.hist-plot { position: relative; height: 70px; display: flex; align-items: flex-end; gap: 3px; border-bottom: 2px solid rgba(255, 255, 255, 0.5); }
.hist-bar { flex: 1; background: rgba(255, 255, 255, 0.28); border-radius: 3px 3px 0 0; }
.hist-marker { position: absolute; top: -4px; bottom: 0; width: 3px; margin-left: -1.5px; background: var(--accent); }
.hist-flag {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff;
  font-size: 0.72rem; font-weight: 800; padding: 1px 7px; border-radius: 6px; white-space: nowrap; letter-spacing: 0.5px;
}
.hist-axis { position: relative; height: 18px; font-size: 0.72rem; color: var(--muted); }
.hist-axis span { position: absolute; top: 3px; transform: translateX(-50%); white-space: nowrap; }
.hist-axis span:first-child { transform: none; }
.hist-axis span:last-child { transform: translateX(-100%); }

/* Harita pinleri (OverlayView) */
.pin {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); pointer-events: none;
}
.pin-guess { background: var(--accent); }
.pin-actual { background: var(--good); width: 22px; height: 22px; margin: -11px 0 0 -11px; }
.dots { position: absolute; left: 0; top: 0; }
.dot {
  position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%;
  background: rgba(255, 212, 121, 0.75); border: 1px solid rgba(0, 0, 0, 0.45); pointer-events: none;
}

/* Sonuç ekranı */
#screen-final {
  padding: 20px max(20px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.final-wrap { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.karne { border-top: 4px solid var(--accent); }
.karne-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; border-bottom: 2px solid var(--border); padding-bottom: 10px; }
.karne-title { font-weight: 900; letter-spacing: 6px; font-size: 1.3rem; }
.karne-label { display: block; font-size: 0.75rem; font-weight: 800; letter-spacing: 2px; color: var(--muted); }
.karne-score { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 14px 0 4px; }
.karne-avg { display: block; font-size: 3rem; font-weight: 900; line-height: 1.1; }
.badge { background: var(--accent); color: #fff; font-weight: 800; padding: 8px 14px; border-radius: 999px; white-space: nowrap; }
.karne-hist { margin: 12px 0; }
.final-rounds { display: grid; gap: 8px; margin: 14px 0; }
.final-round {
  display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center; background: var(--panel-2);
  border-radius: 10px; padding: 10px 12px;
}
.final-round .fr-sq { grid-row: span 2; font-size: 1.5rem; }
.final-round .fr-place { font-weight: 700; }
.final-round .fr-km { font-weight: 800; text-align: right; white-space: nowrap; }
.final-round .fr-meta { grid-column: 2 / -1; color: var(--muted); font-size: 0.85rem; }
.report h3 { font-size: 1.15rem; }
.report h4 { margin: 14px 0 4px; font-size: 1rem; }
.report p { margin: 4px 0; }
.report .tip { color: #ffd479; }
.report-round { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.nick-form { display: flex; gap: 8px; margin-bottom: 12px; }
.nick-form input {
  flex: 1; width: 0; min-width: 0; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); padding: 10px 12px; font-size: 1rem;
}
.crown { font-weight: 800; color: #ffd479; margin: 0 0 6px; }
.leaderboard table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.leaderboard th, .leaderboard td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.leaderboard td.num, .leaderboard th.num { text-align: right; }
.leaderboard tr.me td { color: #ffd479; font-weight: 700; }

.footer { text-align: center; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
body[data-screen='game'] .footer { display: none; }

.dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 480px; width: calc(100% - 32px); padding: 22px;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog li { margin: 6px 0; line-height: 1.4; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: #fff; color: #111; padding: 10px 16px; border-radius: 10px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); max-width: 90vw;
}

/* Telefon (dikey) */
@media (max-width: 700px) {
  h1 { font-size: 1.6rem; }
  /* Küçük telefonda "Başla" kaydırmadan görünsün: buton kuralların üstüne gelir. */
  #screen-intro { padding: 12px; align-items: start; }
  .intro-card { display: flex; flex-direction: column; }
  .intro-card #start-btn { order: 1; margin-top: 4px; }
  .intro-card #intro-status { order: 2; }
  .intro-card .rules { order: 3; margin: 10px 0 0; gap: 8px; }
  .rules li { padding: 8px 10px; font-size: 0.95rem; }
  .lead { font-size: 1rem; }
  /* Panel, sokak görüntüsünün altındaki Google logosu ve yazılarının üstünde durur. */
  .guess-panel { left: 10px; right: 10px; bottom: calc(30px + env(safe-area-inset-bottom)); width: auto; }
  .guess-panel .map { height: 0; border-width: 0; }
  .guess-panel.expanded { width: auto; }
  .guess-panel.expanded .map { height: 52vh; height: 52dvh; border-width: 2px; }
  .hud { top: 8px; width: calc(100% - 16px); }
  .hud-item { font-size: 0.82rem; padding: 5px 10px; }
  /* Tur sonucu: üstte harita, altta kart (harita ve Google yazıları kartın altında kalmaz). */
  .round-result {
    left: 0; right: 0; top: 42%; bottom: 0; width: auto; max-height: none;
    background: var(--bg); padding: 8px 8px env(safe-area-inset-bottom);
  }
  .result-card { padding: 16px; margin-bottom: 8px; }
  .rr-km { font-size: 2.1rem; margin-top: 8px; }
  #screen-final { padding: 12px max(12px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .card { padding: 16px; }
  .karne-avg { font-size: 2.4rem; }
}

/* Telefon (yatay): harita butonla açılır, açıkken ekranın sağ yarısını kaplar. */
@media (pointer: coarse) and (max-height: 500px) and (min-width: 701px) {
  .guess-panel { right: max(10px, env(safe-area-inset-right)); bottom: 30px; width: 280px; }
  .guess-panel .map { height: 0; border-width: 0; }
  .guess-panel.expanded { top: 8px; width: min(520px, 58vw); }
  .guess-panel.expanded .map { flex: 1; height: auto; border-width: 2px; }
  .hud { left: max(10px, env(safe-area-inset-left)); transform: none; justify-content: flex-start; }
  .round-result { left: max(10px, env(safe-area-inset-left)); top: 8px; width: min(380px, 46vw); max-height: calc(100% - 46px); }
  .result-card { padding: 14px; }
  .rr-km { font-size: 1.9rem; margin-top: 6px; }
}

/* Tur sonucu modunda harita tüm alanı kaplar (yukarıdaki tüm kurallardan güçlü olsun diye id ile). */
#guess-panel.result-mode { inset: 0; width: auto; }
#guess-panel.result-mode .map { flex: 1; height: auto; border: 0; border-radius: 0; }
#guess-panel.result-mode .guess-btn, #guess-panel.result-mode .map-toggle { display: none; }
@media (max-width: 700px) {
  #guess-panel.result-mode { bottom: 58%; }
}
