:root {
    color-scheme: light;
    --ink: #253b42;
    --muted: #657579;
    --line: #dbe2df;
    --paper: #fafbf8;
    --accent: #bf582d;
    --accent-soft: #f4e7da;
    --panel-shadow: 0 12px 40px #2138301c, 0 2px 6px #2138300a;
    font-family: Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: #e7ece5;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; }
#app { height: 100dvh; }
button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button, select, input { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}
button:active { transform: translateY(1px); }
svg { display: block; width: 22px; height: 22px; flex-shrink: 0; }
.hidden { display: none !important; }
#map-wrap { position: relative; width: 100%; height: 100%; }
#map { position: absolute; inset: 0; }
.map-toolbar {
    position: absolute;
    inset: max(18px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) auto max(20px, env(safe-area-inset-left));
    z-index: 40;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}
.map-brand, .options-button, .map-info-card {
    background: #fafbf8f2;
    border: 1px solid #ffffffbd;
    box-shadow: 0 2px 12px #263f3512;
    backdrop-filter: blur(12px);
}
.map-brand { display: flex; gap: 9px; align-items: center; padding: 9px 14px 9px 10px; border-radius: 15px; }
.brand-mark { width: 32px; height: 32px; color: var(--accent); }
.map-brand h1 { font-size: 17px; letter-spacing: -.5px; margin: 0; line-height: 1.2; }
.map-brand p { margin: 2px 0 0; color: var(--muted); font-size: 10px; letter-spacing: 1.3px; text-transform: uppercase; }
.options-button { pointer-events: auto; min-height: 48px; padding: 0 16px; display: flex; gap: 9px; align-items: center; border-radius: 15px; color: var(--ink); font-size: 14px; font-weight: 700; }
#map .maplibregl-ctrl-top-right { top: 82px; right: 12px; }
#map .maplibregl-ctrl-geolocate { width: 44px; height: 44px; }
#location-feedback { position: absolute; top: 90px; right: max(78px, env(safe-area-inset-right)); z-index: 45; max-width: min(280px, calc(100% - 96px)); padding: 12px 14px; border: 1px solid #d9b89d; border-radius: 12px; background: var(--paper); box-shadow: var(--panel-shadow); color: var(--ink); font-size: 12px; line-height: 1.5; pointer-events: none; }
.map-info { position: absolute; top: 90px; left: max(20px, env(safe-area-inset-left)); z-index: 30; display: grid; gap: 10px; pointer-events: none; }
.map-info-card { border-radius: 13px; padding: 12px 14px; font-size: 11px; }
.map-info-card h2 { margin: 0 0 7px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
#sun-info-time { color: var(--muted); font-size: 10px; }
.sun-coordinates { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 7px; font-variant-numeric: tabular-nums; }
.twilight-bands { padding: 0; margin: 0; list-style: none; display: grid; gap: 5px; }
.twilight-bands li { display: flex; align-items: center; gap: 7px; }
.twilight-bands li > span { width: 11px; height: 11px; border: 1px solid #00000014; border-radius: 4px; background: var(--band-color); }
.twilight-bands small { margin-left: auto; color: var(--muted); font-size: 10px; }

#timeline-wrap {
    position: absolute;
    z-index: 40;
    left: max(20px, env(safe-area-inset-left));
    right: max(20px, env(safe-area-inset-right));
    bottom: calc(28px + env(safe-area-inset-bottom));
    max-width: 840px;
    margin: 0 auto;
    padding: 16px 18px 10px;
    border: 1px solid #ffffff;
    border-radius: 24px;
    background: linear-gradient(135deg, #fffffffa, #f5f7f0f5);
    backdrop-filter: blur(18px);
    box-shadow: var(--panel-shadow);
    animation: panel-arrive 400ms ease-out both;
}
.timeline-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.timeline-readout { min-width: 0; flex: 1; }
.timeline-time { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 9px; }
#timeline-selected-label { font-size: 30px; font-weight: 500; line-height: 1.1; letter-spacing: -.9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.time-zone-badge { max-width: 100%; overflow-wrap: anywhere; font-size: 9px; font-weight: 700; letter-spacing: .4px; padding: 4px 5px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: transparent; }
#timeline-date-label { margin-top: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.timeline-actions { display: flex; flex-shrink: 0; gap: 8px; }
.icon-button { width: 46px; height: 46px; min-width: 46px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: #ffffffb3; color: var(--ink); }
.play-button { background: var(--ink); color: white; border-color: var(--ink); }
.play-button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.timeline-ruler { display: flex; gap: 10px; }
#mode-toggle-btn { width: 68px; flex: 0 0 68px; min-height: 76px; border-radius: 14px; border: 1px solid #d7ded5; background: #edf1e8; color: var(--ink); font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: -.7px; }
#mode-toggle-btn::after { content: attr(data-caption); display: block; margin-top: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
#timeline-viewport { position: relative; flex: 1; min-width: 0; height: 76px; overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(#f1f4ee, #fafbf8); cursor: grab; }
#timeline-viewport.is-dragging { cursor: grabbing; }
#timeline-viewport::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, #f4f6f0 0%, transparent 10%, transparent 90%, #f4f6f0 100%); }
#timeline-scale { position: absolute; top: 0; bottom: 0; will-change: transform; pointer-events: none; }
.timeline-track { position: absolute; left: 0; top: 35px; height: 1px; background: #adbcb1; opacity: .65; }
.timeline-daylight { position: absolute; top: 32px; height: 6px; border-radius: 3px; background: #e8bd28; }
.timeline-dot { position: absolute; top: 35px; width: 2px; height: 8px; border-radius: 1px; background: #a6b4aa; transform: translate(-50%, -50%); }
.timeline-dot.major { height: 18px; background: #637970; }
.timeline-label { position: absolute; top: 4px; white-space: nowrap; transform: translateX(-50%); font-size: 11px; font-variant-numeric: tabular-nums; color: #546a61; }
.timeline-label.bottom { top: 52px; }
#timeline-center-marker { position: absolute; z-index: 1; top: 8px; bottom: 8px; width: 2px; left: 50%; transform: translateX(-50%); border-radius: 2px; background: var(--accent); box-shadow: 0 0 0 4px #bf582d0a; pointer-events: none; }
.timeline-footer { display: flex; justify-content: space-between; gap: 8px; padding: 9px 2px 0; font-size: 10px; color: var(--muted); }
.daylight-key { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.daylight-key > span { width: 15px; height: 5px; border-radius: 2px; background: #e8bd28; }

dialog { width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); margin: auto; padding: 0; overflow: auto; overscroll-behavior: contain; color: var(--ink); background: var(--paper); border: 1px solid #ffffff; border-radius: 24px; box-shadow: 0 24px 100px #182c3a40; }
dialog::backdrop { background: #1734386b; backdrop-filter: blur(4px); }
dialog[open] { animation: panel-arrive 180ms ease-out; }
dialog form { padding: 26px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; }
dialog h2 { margin: 0; font-weight: 500; font-size: 26px; letter-spacing: -.6px; }
.close-button { background: transparent; border-color: transparent; }
.dialog-description { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 15px 0 23px; }
.option-field { padding: 17px 0; border-top: 1px solid var(--line); }
.option-field label, .calendar-field label { font-weight: 700; font-size: 14px; }
.option-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.option-label output { color: var(--accent); font-size: 13px; font-variant-numeric: tabular-nums; }
.option-field p { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 7px 0 10px; }
input[type="range"] { display: block; width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent); cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 2px solid white; }
.range-endpoints { display: flex; justify-content: space-between; margin-top: -2px; font-size: 10px; color: var(--muted); }
select, input[type="time"], input[type="date"] { width: 100%; min-width: 0; min-height: 48px; border: 1px solid #cbd6ce; border-radius: 10px; background: white; color: var(--ink); padding: 10px 12px; font-size: 16px; }
.field-label { display: block; margin: 14px 0 8px; font-size: 14px; font-weight: 700; }
.field-note { margin: 8px 0 16px; color: var(--muted); font-size: 12px; }
input[type="search"] { width: 100%; min-width: 0; min-height: 48px; padding: 10px 12px; font-size: 16px; color: var(--ink); background: white; border: 1px solid #cbd6ce; border-radius: 10px; }
#time-zone-select { padding: 4px; min-height: 96px; max-height: 204px; }
#time-zone-select option { padding: 9px 8px; font-size: 14px; }
.time-zone-dialog { scroll-padding-bottom: 140px; }
.time-zone-actions { position: sticky; bottom: 0; z-index: 1; padding: 12px 0; background: var(--paper); box-shadow: 0 -10px 0 var(--paper); }
#time-zone-device-btn { width: 100%; }
.time-zone-dialog .dialog-footer { justify-content: flex-end; margin-top: 12px; }
button:disabled { opacity: .5; cursor: default; }
.dialog-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }
.dialog-footer > span { font-size: 11px; color: var(--muted); }
.primary-button, .secondary-button { min-height: 46px; padding: 10px 22px; border: 1px solid var(--ink); border-radius: 12px; background: var(--ink); color: white; font-weight: 700; font-size: 14px; }
.secondary-button { background: transparent; color: var(--ink); border-color: var(--line); }
.calendar-field { margin-top: 22px; }
.calendar-field label { display: block; margin-bottom: 8px; }
.calendar-dialog .dialog-footer { justify-content: flex-end; }
.render-canvas { position: absolute; left: -10000px; top: -10000px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#wgpu-required { position: absolute; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: 28px; text-align: center; color: white; background: #6d2929ed; font-weight: 700; font-size: 17px; }

@keyframes panel-arrive { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (hover: hover) {
    .icon-button:hover, .options-button:hover, .time-zone-badge:hover, #mode-toggle-btn:hover { background: var(--accent-soft); border-color: #d9b89d; }
    .play-button:hover, .primary-button:hover { background: #34534e; color: white; }
}
@media (max-width: 520px) {
    .map-toolbar { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }
    .map-brand { padding: 8px 10px; }
    .map-brand h1 { font-size: 16px; }
    .map-brand p { font-size: 9px; }
    .options-button { padding: 0 12px; }
    #map .maplibregl-ctrl-top-right { top: 74px; right: 3px; }
    .map-info { top: max(78px, calc(env(safe-area-inset-top) + 64px)); left: max(12px, env(safe-area-inset-left)); max-width: 220px; }
    .map-info-card { padding: 10px 12px; }
    .sun-coordinates { display: grid; gap: 3px; }
    #timeline-wrap { left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); padding: 13px 12px 10px; border-radius: 20px; }
    .timeline-heading { gap: 8px; margin-bottom: 11px; }
    #timeline-selected-label { font-size: 27px; }
    #timeline-date-label { font-size: 11px; }
    .timeline-time { column-gap: 6px; }
    .timeline-actions { gap: 5px; }
    .icon-button { width: 44px; height: 44px; min-width: 44px; border-radius: 13px; }
    #mode-toggle-btn { width: 57px; flex-basis: 57px; font-size: 19px; }
    .timeline-ruler { gap: 8px; }
    .keyboard-hint { display: none; }
    .settings-dialog { width: 100%; max-width: 100%; max-height: calc(100dvh - max(16px, env(safe-area-inset-top))); margin: auto 0 0; border-radius: 24px 24px 0 0; }
    .settings-dialog form { padding: 22px 22px max(20px, env(safe-area-inset-bottom)); }
}
@media (max-width: 359px) {
    .time-zone-badge { padding: 3px; font-size: 8px; letter-spacing: .3px; }
    #timeline-selected-label { font-size: 23px; }
    .timeline-actions { gap: 3px; }
}
@media (max-height: 520px) and (orientation: landscape) {
    #map .maplibregl-ctrl-top-right { display: flex; align-items: flex-start; }
    .map-info { top: 12px; left: 50%; transform: translateX(-50%); }
    #sun-info-time, #twilight-legend { display: none !important; }
    #timeline-wrap { padding-top: 10px; padding-bottom: 8px; }
    .timeline-heading { margin-bottom: 7px; }
    .timeline-footer { display: none; }
    .timeline-time time { font-size: 24px !important; }
    #timeline-date-label { margin-top: 2px; }
}
@media (prefers-reduced-motion: reduce) {
    #timeline-wrap, dialog[open] { animation: none; }
}
