:root {
  --panel-bg: rgba(10, 14, 26, 0.86);
  --panel-border: rgba(120, 150, 220, 0.25);
  --text: #dfe6f5;
  --text-dim: #9aa6c4;
  --accent: #6fb3ff;
  --accent-warm: #ffcf87;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #05070d;
  color: var(--text);
  font: 13px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
}

#sky {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#sky.dragging { cursor: grabbing; }

/* ---- Ust bilgi seridi (HUD) ---- */
#hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  gap: 18px;
  padding: 6px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  backdrop-filter: blur(4px);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- Panel ac/kapa dugmesi + mobil arka perde ---- */
#panel-toggle {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 40;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 19px;
  line-height: 1;
  border-radius: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
}
body.panel-open #panel-toggle { display: none; }

#panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.4);
  display: none;
}

#panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 12px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  display: none;
}
#hud b { color: var(--accent); font-weight: 600; }
#hud .warm { color: var(--accent-warm); }

/* ---- Sol kontrol paneli ---- */
#panel {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 30;
  width: 268px;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  transform: translateX(calc(-100% - 24px));
}
body.panel-ready #panel { transition: transform 0.22s ease; }
body.panel-open #panel { transform: none; }
body.panel-open #panel-close { display: block; }
#panel h1 {
  font-size: 14px;
  margin: 0 0 2px;
  letter-spacing: .3px;
}
#panel .sub {
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 12px;
}
#panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-dim);
  margin: 14px 0 6px;
  border-top: 1px solid var(--panel-border);
  padding-top: 10px;
}
#panel h2:first-of-type { border-top: none; padding-top: 0; }

.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row label { flex: 0 0 74px; color: var(--text-dim); }
.row input[type="number"],
.row input[type="datetime-local"],
.row input[type="search"],
.row input[type="text"],
.row select {
  flex: 1 1 auto;
  min-width: 0;
  background: #0c1220;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
}
.row input[type="range"] { flex: 1 1 auto; }
.check { display: flex; align-items: center; gap: 7px; margin: 5px 0; cursor: pointer; }
.check input { accent-color: var(--accent); }

button {
  background: #16233c;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
  cursor: pointer;
}
button:hover { background: #1e2f4f; }
button.primary { background: #24487e; border-color: #3a6bb8; }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.hint { color: var(--text-dim); font-size: 10.5px; margin-top: 4px; }

#obj-list {
  max-height: 42vh;
  overflow-y: auto;
  margin-top: 4px;
}
#obj-list button { font-size: 12px; line-height: 1.3; }

/* ---- Ince, tema uyumlu kaydirma cubuklari ---- */
#panel, #obj-list, #info, #map-modal .box {
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 150, 220, 0.32) transparent;
}
#panel::-webkit-scrollbar,
#obj-list::-webkit-scrollbar,
#info::-webkit-scrollbar,
#map-modal .box::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
#panel::-webkit-scrollbar-track,
#obj-list::-webkit-scrollbar-track,
#info::-webkit-scrollbar-track,
#map-modal .box::-webkit-scrollbar-track { background: transparent; }
#panel::-webkit-scrollbar-thumb,
#obj-list::-webkit-scrollbar-thumb,
#info::-webkit-scrollbar-thumb,
#map-modal .box::-webkit-scrollbar-thumb {
  background: rgba(120, 150, 220, 0.25);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 9px;
}
#panel:hover::-webkit-scrollbar-thumb,
#obj-list:hover::-webkit-scrollbar-thumb,
#info:hover::-webkit-scrollbar-thumb {
  background: rgba(140, 170, 235, 0.45);
  background-clip: padding-box;
}
#panel::-webkit-scrollbar-thumb:hover,
#obj-list::-webkit-scrollbar-thumb:hover,
#info::-webkit-scrollbar-thumb:hover {
  background: rgba(160, 190, 245, 0.7);
  background-clip: padding-box;
}
#panel::-webkit-scrollbar-corner,
#obj-list::-webkit-scrollbar-corner { background: transparent; }

#worldmap {
  width: 100%;
  height: auto;
  display: block;
  margin: 8px 0 2px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  cursor: pointer;
  touch-action: pan-y;
}

/* ---- Konum secici penceresi ---- */
#map-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 11, 0.62);
  backdrop-filter: blur(3px);
}
#map-modal.open { display: flex; }
#map-modal .box {
  width: min(92vw, 900px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
#map-modal header,
#map-modal footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
#map-modal header { border-bottom: 1px solid var(--panel-border); }
#map-modal footer { border-top: 1px solid var(--panel-border); }
#map-modal header h3 {
  flex: 1;
  margin: 0;
  font-size: 13px;
  letter-spacing: .3px;
}
#map-modal header .x {
  width: 26px; height: 26px; padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
}
#map-modal .canvas-wrap { position: relative; }
#mapmodal-canvas {
  display: block;
  width: 100%;
  height: min(62vh, 480px);
  background: #aad3df;
  cursor: grab;
  touch-action: none;
}
#mapmodal-canvas.dragging { cursor: grabbing; }
#map-modal .zoombtns {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#map-modal .zoombtns button {
  width: 32px; height: 32px; padding: 0;
  font-size: 18px; line-height: 1;
  background: var(--panel-bg);
}
#map-modal footer { flex-wrap: wrap; }
#map-modal footer .coords {
  flex: 1 1 auto;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
#map-modal footer .attr {
  color: var(--text-dim);
  font-size: 10.5px;
  opacity: .8;
}
[dir="rtl"] #map-modal .zoombtns { right: auto; left: 10px; }

/* ---- Obje bilgi karti ---- */
#info {
  position: fixed;
  right: 10px;
  bottom: 10px;
  z-index: 35;
  width: 320px;
  max-height: calc(100dvh - 20px);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  overflow: hidden auto;
  overscroll-behavior: contain;
  display: none;
}
#info.open { display: block; }
#info .sheet-grip { display: none; }   /* yalnizca mobilde gorunur */
#info-img-wrap { position: relative; }
#info img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: #05070d;
  display: block;
}
#info-img-note {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(5, 7, 13, 0.72);
  color: var(--text-dim);
  font-size: 12px;
}
#info-img-wrap.loading #info-img-note { display: flex; }
#info-img-wrap.error #info-img-note { display: flex; }
#info-img-wrap.error #info-img-note .spinner { display: none; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(180, 205, 245, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#info .body { padding: 12px 14px 14px; }
#info h3 { margin: 0 0 2px; font-size: 15px; }
#info .type { color: var(--accent-warm); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
#info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 10px 0; }
#info dt { color: var(--text-dim); }
#info dd { margin: 0; font-variant-numeric: tabular-nums; }
#info p { margin: 8px 0 0; color: #cdd6ea; }
#info .close {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px; padding: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 70;
  background: rgba(120, 40, 40, 0.92);
  border: 1px solid #d88;
  color: #ffe;
  padding: 8px 16px;
  border-radius: 8px;
  max-width: 80vw;
  display: none;
}

/* ---- Tablet ---- */
@media (max-width: 900px) {
  #hud { gap: 12px; font-size: 12px; }
}

/* ---- Mobil ---- */
@media (max-width: 720px) {
  #hud {
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 11px;
    padding: 5px 10px;
    max-width: calc(100vw - 108px);
  }

  /* Panel: soldan kayan cekmece + arka perde */
  #panel {
    width: min(86vw, 320px);
    max-height: 100dvh;
    top: 0;
    left: 0;
    border-radius: 0 14px 14px 0;
    padding-top: max(14px, env(safe-area-inset-top));
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
  }
  body.panel-open #panel-backdrop { display: block; }

  /* Uzun etiketler tasmasin */
  .row { flex-wrap: wrap; }
  .row label { flex: 1 0 100%; margin-bottom: 1px; }
  .row input[type="range"] { flex-basis: 60%; }

  #obj-list { max-height: 38vh; }

  /* Bilgi karti: alttan cekilen sayfa — varsayilan "peek", yukari cek = ac */
  #info {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 82dvh;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #info .sheet-grip {
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 30px;
    padding: 13px 46px 9px 16px;
    background: rgba(12, 16, 28, 0.96);
    cursor: grab;
    touch-action: none;
    user-select: none;
  }
  #info .sheet-grip::before {
    content: "";
    position: absolute;
    top: 6px; left: 50%;
    width: 36px; height: 4px;
    transform: translateX(-50%);
    border-radius: 2px;
    background: var(--text-dim);
    opacity: .55;
  }
  #info .sheet-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* peek: yalnizca tutamac serisi */
  #info:not(.expanded) { max-height: none; }
  #info:not(.expanded) #info-img-wrap,
  #info:not(.expanded) .body { display: none; }
  #info.expanded .sheet-title { font-weight: 500; opacity: .5; }

  #info img { height: 128px; }
  #info .body { padding: 10px 14px 12px; }
  #info h3 { font-size: 15px; }
  #info dl { gap: 2px 10px; margin: 9px 0; font-size: 12.5px; }
  #info p { margin-top: 7px; font-size: 12.5px; line-height: 1.4; }
  #info .close { width: 30px; height: 30px; top: 8px; right: 8px; }

  /* Konum penceresi: tam ekran */
  #map-modal { align-items: stretch; justify-content: stretch; }
  #map-modal .box {
    width: 100%;
    max-width: none;
    max-height: none;
    height: 100%;
    border: none;
    border-radius: 0;
  }
  #map-modal .canvas-wrap { flex: 1 1 auto; min-height: 0; }
  #mapmodal-canvas { height: 100%; }
  #map-modal .zoombtns button { width: 40px; height: 40px; font-size: 20px; }
}

@media (max-width: 720px) and (orientation: landscape) {
  #panel { width: min(70vw, 340px); }
  /* yatayda dikey yer dar: alttan cekmece yerine sag kenarda kompakt kart */
  #info {
    left: auto;
    right: 8px;
    bottom: 8px;
    width: min(52vw, 320px);
    max-height: calc(100dvh - 16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
  }
  #info .sheet-grip { display: none; }
  #info:not(.expanded) #info-img-wrap,
  #info:not(.expanded) .body { display: block; }   /* yatayda daima acik */
  #info img { height: 96px; }
  [dir="rtl"] #info { right: auto; left: 8px; }
}

/* ---- Sağdan sola (Arapça) ---- */
[dir="rtl"] #panel {
  left: auto;
  right: max(10px, env(safe-area-inset-right));
  transform: translateX(calc(100% + 24px));
}
[dir="rtl"] body.panel-open #panel { transform: none; }
[dir="rtl"] #panel-close { right: auto; left: 8px; }
[dir="rtl"] #panel-toggle {
  left: auto;
  right: max(10px, env(safe-area-inset-right));
}
[dir="rtl"] #info { right: auto; left: 10px; }
[dir="rtl"] #info .close { right: auto; left: 8px; }
[dir="rtl"] #hud { direction: rtl; }
[dir="rtl"] .row label { text-align: right; }
[dir="rtl"] #obj-list button { text-align: right !important; }
[dir="rtl"] #info dl { direction: rtl; }
[dir="rtl"] .hint, [dir="rtl"] #panel .sub { text-align: right; }

@media (max-width: 720px) {
  [dir="rtl"] #panel {
    right: 0;
    left: auto;
    border-radius: 14px 0 0 14px;
  }
  [dir="rtl"] #info { left: 0; right: 0; }
  [dir="rtl"] #info .sheet-grip { padding: 13px 16px 9px 46px; }
  [dir="rtl"] #info .close { right: auto; left: 8px; }
}
