:root {
  --bg: #070b14;
  --panel: #0d1424;
  --panel-2: #121b30;
  --line: #1f2a44;
  --text: #e7ecf6;
  --muted: #8d9ab5;
  --accent: #ffc94d;
  --day: #ffd76a;
  --civil: #f39b52;
  --nautical: #7d6fd6;
  --astro: #3d4a8f;
  --night: #1a2140;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; }

button, select, input { font: inherit; color: inherit; }

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0b1222, var(--bg));
}
.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .2px;
  color: var(--text);
  text-decoration: none;
  padding-right: 16px;
  border-right: 1px solid var(--line);
}
.brand span { color: var(--accent); }
.title { flex: 1; min-width: 0; }
.title h1 { margin: 0; font-size: 18px; font-weight: 650; }
.title p { margin: 0; color: var(--muted); font-size: 12.5px; }

.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
}
.seg button[aria-selected="true"] { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px #2c3a5c; }

/* ---------- Раскладка ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 28vw, 380px);
}
.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.stage {
  position: relative;
  flex: 1;
  min-height: 300px;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background: #04060c;
}
.stage.dragging { cursor: grabbing; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.layers {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: calc(100% - 24px);
}
.layers label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  font-size: 12.5px;
  background: rgba(7, 11, 20, .72);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
}
.layers input { accent-color: var(--accent); margin: 0; }

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 6px 10px;
  font-size: 12px;
  color: #c5cee0;
  background: rgba(7, 11, 20, .72);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 10px;
  pointer-events: none;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.day { background: #7f9c58; }
.sw.civil { background: #5a7148; }
.sw.nautical { background: #3f523c; }
.sw.astro { background: #263432; }
.sw.night { background: #0b1526; box-shadow: inset 0 0 0 1px #24314d; }

.tooltip {
  position: absolute;
  pointer-events: none;
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.35;
  background: rgba(10, 15, 28, .92);
  border: 1px solid #2a3756;
  border-radius: 8px;
  white-space: nowrap;
  transform: translate(14px, 14px);
  z-index: 3;
}
.tooltip b { font-weight: 600; }

.loading, .fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}
.fallback { background: var(--bg); color: var(--text); }
.loading[hidden], .fallback[hidden] { display: none; }

/* ---------- Панель времени ---------- */
.timebar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.clock-main { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock-sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.live {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #0b1526;
  background: #4ade80;
  border-radius: 999px;
}
.live[hidden] { display: none; }

.clock { flex: 0 0 auto; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; flex: 1 1 440px; }
.controls input[type="range"] { flex: 1 1 140px; min-width: 120px; accent-color: var(--accent); }
.controls select, .controls input[type="date"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  height: 34px;
}
.btn {
  background: var(--panel-2);
  border: 1px solid #2a3756;
  border-radius: 8px;
  padding: 6px 12px;
  height: 34px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #18233d; }
.btn.icon { width: 38px; padding: 0; font-size: 14px; }
.btn.small { height: 28px; padding: 3px 10px; font-size: 12.5px; }
.btn.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 600; }

.presets { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  color: #c5cee0;
  cursor: pointer;
}
.chip:hover { border-color: #3a4a70; color: var(--text); }
.chip small { color: var(--muted); margin-left: 4px; }

/* ---------- Боковая панель ---------- */
.side {
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #080d18;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coords { color: var(--muted); font-size: 12.5px; margin: 2px 0 10px; font-variant-numeric: tabular-nums; }

.sunnow { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.alt { display: flex; flex-direction: column; }
.alt span { font-size: 30px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.alt small { color: var(--muted); font-size: 11.5px; }
.phase {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid transparent;
}
.phase.day { background: rgba(255, 215, 106, .14); color: var(--day); border-color: rgba(255, 215, 106, .3); }
.phase.civil { background: rgba(243, 155, 82, .14); color: var(--civil); border-color: rgba(243, 155, 82, .3); }
.phase.nautical { background: rgba(125, 111, 214, .16); color: #a99cf5; border-color: rgba(125, 111, 214, .35); }
.phase.astro { background: rgba(61, 74, 143, .25); color: #9aa8f0; border-color: rgba(90, 104, 180, .4); }
.phase.night { background: rgba(26, 33, 64, .6); color: #aab4d4; border-color: #2a3560; }

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.facts dd small { color: var(--muted); }
.facts .sep { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 4px 0; }

.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

.cities { list-style: none; margin: 0; padding: 0; }
.cities li {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  margin: 0 -6px;
  border-radius: 8px;
  cursor: pointer;
}
.cities li:hover, .cities li.sel { background: var(--panel-2); }
.cities .ic { text-align: center; }
.cities .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cities .tm { font-variant-numeric: tabular-nums; color: #c5cee0; }
.cities .tm small { color: var(--muted); margin-left: 6px; }

.about summary { cursor: pointer; font-weight: 650; font-size: 15px; }
.about details p { color: #c5cee0; margin: 8px 0; }
.keys { color: var(--muted); font-size: 12px; }
kbd {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 2px 5px;
  border: 1px solid #2a3756;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
}

/* ---------- Мобильная раскладка ---------- */
@media (max-width: 960px) {
  html, body { height: auto; }
  .layout { display: block; }
  /* Слои — полосой под картой, а не поверх неё */
  .stage { height: calc(50vw + 44px); min-height: 220px; flex: none; }
  body.mode-globe .stage { height: calc(min(100vw, 72vh) + 44px); }
  .stage canvas { bottom: auto; height: calc(100% - 44px); }
  .layers {
    top: auto; bottom: 0; left: 0; right: 0;
    max-width: none; height: 44px;
    padding: 7px 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
    touch-action: pan-x;
    scrollbar-width: none;
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .layers label { flex: none; }
  .legend { bottom: 54px; }
  .side { border-left: 0; overflow: visible; }
  .controls input[type="range"] { flex-basis: 100%; order: 5; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: 6px 12px; padding: 10px 12px; }
  .brand { border-right: 0; padding-right: 0; }
  .seg { margin-left: auto; }
  .title { order: 3; flex-basis: 100%; }
  .title h1 { font-size: 16px; }
  .title p { display: none; }
  .layers label { font-size: 11.5px; padding: 4px 8px 4px 6px; }
  .legend { display: none; }
  .clock-main { font-size: 17px; }
}
