/* =====================================================================
   Te Marama — Moon Atlas styles
   Dark "night sky" theme, mobile-first, iPad/iPhone PWA friendly.
   ===================================================================== */

:root {
  --bg: #0a0c14;
  --bg-raised: #12172a;
  --bg-card: #181f38;
  --ink: #e8ecf6;
  --ink-dim: #9aa3bd;
  --ink-faint: #5d6680;
  --accent: #ffd27d;        /* moonlight gold */
  --accent-2: #7db8ff;      /* sky blue */
  --teal: #4fd1b5;
  --danger: #ff7d7d;
  --line: #262e4a;
  --radius: 14px;
  --header-h: 56px;
  --tabbar-h: 58px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; min-height: 100dvh; }

a { color: var(--accent-2); }
button { font: inherit; }
h1, h2, h3 { font-weight: 650; letter-spacing: 0.01em; }

/* ---------- header ---------- */
header.app-header {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: linear-gradient(180deg, #11162b, #0c1020);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}
header.app-header .logo {
  width: 30px; height: 30px; border-radius: 50%;
}
header.app-header h1 {
  font-size: 17px; margin: 0; font-weight: 700;
}
header.app-header h1 span { color: var(--accent); }
header.app-header .subtitle {
  margin-left: auto; font-size: 12px; color: var(--ink-faint);
  text-align: right;
}

/* ---------- tab bar ---------- */
nav.tabbar {
  display: flex;
  background: #0c1020;
  border-top: 1px solid var(--line);
  position: sticky; bottom: 0; z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabbar button {
  flex: 1; background: none; border: 0; color: var(--ink-faint);
  padding: 9px 4px 7px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; border-top: 2px solid transparent;
}
nav.tabbar button .ico { font-size: 19px; line-height: 1; }
nav.tabbar button.active { color: var(--accent); border-top-color: var(--accent); }

main { flex: 1; display: flex; flex-direction: column; }
.view { display: none; flex: 1; flex-direction: column; }
.view.active { display: flex; }

/* ---------- shared cards/controls ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: 1px solid var(--line); background: var(--bg-raised);
  color: var(--ink-dim); border-radius: 999px; padding: 6px 13px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.pill.active { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 600; }
.pill.active.blue { background: var(--accent-2); color: #06121f; border-color: var(--accent-2); }

label.field { display: block; font-size: 12px; color: var(--ink-dim); }
label.field input, label.field select {
  display: block; width: 100%; margin-top: 4px;
  background: var(--bg-raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 14px;
}

/* =====================================================================
   ATLAS VIEW
   ===================================================================== */
#view-atlas { position: relative; overflow: hidden; }

.atlas-toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px;
  background: rgba(10, 12, 20, 0.92);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.atlas-toolbar .side-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.atlas-toolbar .side-toggle button {
  background: var(--bg-raised); color: var(--ink-dim); border: 0;
  padding: 7px 14px; cursor: pointer; font-size: 13px;
}
.atlas-toolbar .side-toggle button.active { background: var(--accent); color: #1a1405; font-weight: 700; }

#atlas-stage {
  position: relative; flex: 1; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #101527 0%, #06080f 70%);
  touch-action: none;       /* we handle pan/zoom ourselves */
  cursor: grab;
}
#atlas-stage.dragging { cursor: grabbing; }
#atlas-inner { position: absolute; transform-origin: 0 0; will-change: transform; }
#atlas-inner img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
#atlas-svg { position: absolute; inset: 0; overflow: visible; }

/* feature labels */
.f-label {
  fill: #cdd6ec; paint-order: stroke;
  stroke: rgba(5, 7, 12, 0.85); stroke-width: 2.6px;
  font-family: inherit; pointer-events: none;
}
.f-label.mare { fill: #aebbe0; font-style: italic; letter-spacing: 0.05em; }
.f-label.mons { fill: #c9b896; }
.f-label.sat { fill: #8d97b5; }
.f-ring { fill: none; stroke: rgba(205, 214, 236, 0.35); stroke-width: 1; pointer-events: all; cursor: pointer; }
.f-ring:hover { stroke: var(--accent); }

/* drawn-chart mode: dark ink labels on the paper-white hillshade */
#atlas-stage.draw .f-label { fill: #232a40; stroke: rgba(255, 255, 255, 0.75); }
#atlas-stage.draw .f-label.mare { fill: #3a4668; }
#atlas-stage.draw .f-label.mons { fill: #5a4a26; }
#atlas-stage.draw .f-label.sat { fill: #4a5470; }
#atlas-stage.draw .f-ring { stroke: rgba(40, 50, 80, 0.4); }
#atlas-stage.draw .m-marker text { fill: #6b4a00; stroke: rgba(255, 255, 255, 0.8); }
#atlas-stage.draw .disc-pin text { fill: #0e5947; stroke: rgba(255, 255, 255, 0.8); }

/* mission markers */
.m-marker { cursor: pointer; }
.m-marker .sym { stroke: #0a0c14; stroke-width: 1; }
.m-marker text {
  fill: #ffe1a8; paint-order: stroke; stroke: rgba(5,7,12,0.9);
  stroke-width: 2.4px; pointer-events: none;
}
.disc-pin { cursor: pointer; }
.disc-pin circle { fill: var(--teal); stroke: #06281f; stroke-width: 1.4; }
.disc-pin text { fill: #b8efe2; paint-order: stroke; stroke: rgba(5,7,12,0.9); stroke-width: 2.4px; pointer-events: none; }

/* popup card */
#popup {
  position: absolute; z-index: 35; max-width: 320px; min-width: 220px;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  font-size: 13.5px; line-height: 1.45;
}
#popup h3 { margin: 0 0 4px; font-size: 15px; color: var(--accent); }
#popup .meta { color: var(--ink-faint); font-size: 12px; margin-bottom: 6px; }
#popup .src { color: var(--ink-faint); font-size: 11px; margin-top: 8px; font-style: italic; }
#popup .close {
  position: absolute; top: 6px; right: 8px; background: none; border: 0;
  color: var(--ink-faint); font-size: 18px; cursor: pointer;
}

/* legend */
#legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 30;
  background: rgba(12, 16, 32, 0.92); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--ink-dim);
  display: flex; flex-direction: column; gap: 4px;
}
#legend .row { display: flex; align-items: center; gap: 8px; }
#legend svg { flex: 0 0 auto; }

.zoom-controls {
  position: absolute; right: 10px; bottom: 10px; z-index: 30;
  display: flex; flex-direction: column; gap: 6px;
}
.zoom-controls button {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(12, 16, 32, 0.92); color: var(--ink); font-size: 19px; cursor: pointer;
}

/* =====================================================================
   TONIGHT / PHASE VIEW
   ===================================================================== */
#view-tonight { padding: 14px; gap: 14px; overflow-y: auto; }

.tonight-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) {
  .tonight-grid { grid-template-columns: minmax(340px, 480px) 1fr; align-items: start; }
}

#moon-canvas-wrap {
  position: relative;
  background: radial-gradient(ellipse at 50% 42%, #131a30 0%, #05070d 72%);
  border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
#moon-canvas { width: 100%; max-width: 440px; height: auto; display: block; }
#orientation-note {
  position: absolute; bottom: 8px; left: 0; right: 0; text-align: center;
  font-size: 11.5px; color: var(--ink-faint);
}
.compass { position: absolute; top: 10px; left: 14px; font-size: 11px; color: var(--ink-faint); }

.readouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.readout { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.readout .k { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.readout .v { font-size: 16px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.readout .v small { color: var(--ink-dim); font-size: 12px; }

.time-controls { display: flex; flex-direction: column; gap: 8px; }
.time-controls .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.time-controls input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 160px; }
.time-controls input[type="datetime-local"] {
  background: var(--bg-raised); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font-size: 13px;
}
.btn {
  background: var(--bg-raised); border: 1px solid var(--line); color: var(--ink);
  border-radius: 9px; padding: 8px 14px; cursor: pointer; font-size: 13.5px;
}
.btn.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 650; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

.location-box { display: flex; flex-direction: column; gap: 10px; }
.location-box .latlon { display: flex; gap: 8px; }
.location-box .latlon label.field { flex: 1; }

/* =====================================================================
   MARAMATAKA VIEW
   ===================================================================== */
#view-maramataka { padding: 14px; gap: 14px; overflow-y: auto; }
.mara-header { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
#mara-tonight h2 { margin: 2px 0 2px; font-size: 26px; color: var(--accent); }
#mara-tonight .gloss { color: var(--ink-dim); font-size: 14.5px; }
#mara-tonight .guidance { margin-top: 10px; font-size: 14.5px; line-height: 1.5; }
.mara-meta { font-size: 12px; color: var(--ink-faint); margin-top: 10px; }

.mara-nights { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.mara-night {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px;
}
.mara-night.today { border-color: var(--accent); background: #251f10; }
.mara-night .n { color: var(--ink-faint); font-size: 11px; }
.mara-night .nm { font-weight: 650; font-size: 14px; }
.mara-night .dt { color: var(--ink-faint); font-size: 11px; }
.mara-night .cat { display: inline-block; margin-top: 3px; font-size: 10.5px; border-radius: 6px; padding: 1px 6px; background: #20294a; color: var(--accent-2); }
.honesty-note {
  border-left: 3px solid var(--teal); background: rgba(79, 209, 181, 0.07);
  padding: 10px 14px; border-radius: 0 10px 10px 0; font-size: 13px; color: var(--ink-dim); line-height: 1.5;
}

/* =====================================================================
   ABOUT VIEW
   ===================================================================== */
#view-about { padding: 16px; gap: 14px; overflow-y: auto; max-width: 860px; }
#view-about .card { font-size: 14px; line-height: 1.55; }
#view-about h2 { font-size: 17px; margin: 0 0 8px; color: var(--accent); }
#view-about ul { margin: 6px 0; padding-left: 20px; }
#view-about li { margin: 3px 0; }

/* misc */
.loading-overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 100; flex-direction: column; gap: 14px; color: var(--ink-dim);
}
.loading-overlay .orb {
  width: 54px; height: 54px; border-radius: 50%;
  background: conic-gradient(var(--accent) 0 50%, #2a3052 50% 100%);
  animation: spin 1.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
