:root {
  --bg: #090D18;
  --surface: #121726;
  --surface-2: #1A2136;
  --border: rgba(255, 255, 255, 0.11);
  --accent: #F97316;
  --gold: #FFB51F;
  --cyan: #38BDF8;
  --emerald: #10B981;
  --text: #F4F6FA;
  --muted: #9AA5BC;
  --ui-scale: 1;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: calc(15px * var(--ui-scale));
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 12px) + 10px) 14px calc(env(safe-area-inset-bottom, 16px) + 24px);
}

.install-banner {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.18), rgba(255, 181, 31, 0.14));
  border: 1px solid rgba(255, 181, 31, 0.42);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85em;
}

.install-banner.hidden { display: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-row img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 181, 31, 0.55);
}

.brand-title {
  font-weight: 700;
  font-size: 1.12em;
  letter-spacing: 0.01em;
}

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 0.88em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn:active { opacity: 0.8; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.next-block .label {
  color: var(--muted);
  font-size: 0.84em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.next-time {
  font-size: 2.15em;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.12;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.next-countdown {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.96em;
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

.sun-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  text-align: left;
  font-size: 0.82em;
}

.sun-stat .st-label { color: var(--muted); font-size: 0.88em; }
.sun-stat .st-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.sun-stat .st-val.rise { color: var(--gold); }
.sun-stat .st-val.set { color: #FB7185; }

.arc-wrap {
  position: relative;
  margin: 10px 0 8px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #0B0F1A;
}

#sunArcCanvas {
  width: 100%;
  height: 142px;
  display: block;
}

.hero-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.moon-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86em;
  color: var(--muted);
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86em;
  cursor: pointer;
}

.switch-row input {
  width: 38px;
  height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

.loc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.loc-name {
  font-weight: 700;
  font-size: 1.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.loc-meta {
  color: var(--muted);
  font-size: 0.8em;
  margin-top: 2px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.action-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 6px;
  font-size: 0.86em;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.action-btn.accent-text { color: var(--accent); }
.action-btn:active { background: rgba(255, 255, 255, 0.1); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.seg-group {
  display: inline-flex;
  gap: 6px;
}

.seg-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 13px;
  font-weight: 600;
  font-size: 0.88em;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
}

.sched-list {
  display: flex;
  flex-direction: column;
}

.sched-row {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.92em;
}

.sched-row:last-child { border-bottom: none; }
.sched-day { color: var(--text); }
.sched-kind { color: var(--muted); }
.sched-time { font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.sched-row.sunset .sched-time { color: #FB923C; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(4, 7, 15, 0.86);
  backdrop-filter: blur(6px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 16px; }
}

.modal-backdrop.open { display: flex; }

.modal-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 16px) + 16px);
}

@media (min-width: 600px) {
  .modal-sheet { border-radius: 20px; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.15em;
}

.field-group {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

.group-title {
  color: var(--accent);
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.form-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.84em;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  background: #0B0F1A;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 0.96em;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
  font-size: 0.9em;
  cursor: pointer;
}

.check-item input {
  width: 19px;
  height: 19px;
  accent-color: var(--accent);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.preset-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 11px;
  padding: 10px 6px;
  font-size: 0.86em;
  font-weight: 600;
  cursor: pointer;
}

.preset-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #111;
  font-weight: 700;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.94em;
  width: 100%;
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.94em;
  width: 100%;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.lang-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lang-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
}

.lang-item.active { border-color: var(--accent); }
.lang-badge {
  background: #0B0F1A;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 8px;
  font-size: 0.78em;
  font-weight: 700;
  color: var(--gold);
  margin-right: 10px;
}

/* Map info card, search results & zoom canvas */
.map-results {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
  max-height: 195px;
  overflow-y: auto;
}

.map-result-item {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.86em;
  line-height: 1.35;
  cursor: pointer;
}

.map-result-item:hover,
.map-result-item:active {
  border-color: var(--gold);
  background: #222B45;
}

.map-info-card {
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.map-card-coords {
  font-size: 1.24em;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.map-card-addr {
  font-size: 1.0em;
  font-weight: 600;
  color: var(--gold);
  margin-top: 3px;
  line-height: 1.3;
  word-break: break-word;
}

.map-card-addr.muted {
  color: var(--muted);
  font-weight: 500;
}

.map-card-sub {
  font-size: 0.82em;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.3;
}

.map-wrap {
  position: relative;
}

#mapCanvas {
  width: 100%;
  height: 250px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0B1220;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.map-zoom-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 5;
}

.map-zoom-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(11, 15, 26, 0.88);
  color: var(--text);
  font-size: 1.15em;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.map-zoom-badge {
  font-size: 0.72em;
  font-weight: 600;
  color: var(--gold);
  background: rgba(11, 15, 26, 0.84);
  border-radius: 6px;
  padding: 2px 6px;
}

/* OLED Standby Night Clock */
.standby-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #000000;
  color: #E5E7EB;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
}

.standby-overlay.open { display: flex; }

.standby-inner {
  width: 100%;
  max-width: 440px;
  text-align: center;
  transition: transform 1.2s ease;
}

.standby-top {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.standby-emblem {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 1px solid rgba(255, 181, 31, 0.45);
  margin-bottom: 14px;
}

.stby-track {
  width: 100%;
  height: 8px;
  background: #141926;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.stby-fill {
  height: 100%;
  background: linear-gradient(90deg, #3B82F6, #FFB51F);
  width: 50%;
}

.stby-target {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.95em;
}

.stby-countdown {
  font-size: 3.1em;
  font-weight: 700;
  color: #FCD34D;
  font-variant-numeric: tabular-nums;
  margin: 6px 0;
}

.stby-clock {
  font-size: 1.75em;
  font-weight: 600;
  color: #60A5FA;
  font-variant-numeric: tabular-nums;
  margin-bottom: 20px;
}

.hidden { display: none !important; }
