/* Structure, layout and theme-agnostic plot styling.
   Colours, fonts and per-theme flourishes live in themes.css. */

*,*::before,*::after{box-sizing:border-box}
:root{
  padding-top:env(safe-area-inset-top,0px);
  padding-bottom:env(safe-area-inset-bottom,0px);
  padding-left:env(safe-area-inset-left,0px);
  padding-right:env(safe-area-inset-right,0px);
  color-scheme:light;
  background:var(--bg);
}
:root[data-dark]{color-scheme:dark}
html{height:100%}
body{
  margin:0;height:100%;overflow:hidden;
  color:var(--ink);font-family:var(--font-body);line-height:1.35;
  background:var(--bg-image),var(--bg);
  background-blend-mode:var(--bg-blend);
  background-size:var(--bg-size);
  -webkit-font-smoothing:antialiased;
  -webkit-tap-highlight-color:transparent;
}
[hidden]{display:none!important}

/* ============ Layout ============ */
#app{height:100%;display:flex;flex-direction:column;overflow:auto}
#plotWrap{position:relative;flex:1 1 auto;min-height:56vh;min-height:56svh;margin:0}
#plot{position:absolute;top:var(--plot-inset);left:var(--plot-inset);width:calc(100% - 2 * var(--plot-inset));height:calc(100% - 2 * var(--plot-inset));display:block;overflow:hidden}
#panel{flex:none;display:grid;grid-template-columns:1fr 1fr;gap:1.15rem 1.5rem;align-content:start;padding:1.1rem 1.25rem 1.4rem;background:var(--panel)}
#panel>header,#panel>.legend{grid-column:1/-1}
@media (max-width:400px){#panel{grid-template-columns:1fr}}
@media (min-aspect-ratio:5/4) and (min-width:760px){
  #app{flex-direction:row;overflow:hidden}
  #plotWrap{min-height:0;height:100%}
  #panel{width:clamp(290px,25vw,380px);height:100%;overflow:auto;grid-template-columns:1fr}
}

/* ============ Panel ============ */
.toprow{display:flex;align-items:flex-start;justify-content:space-between;gap:.75rem}
.tools{display:flex;gap:.4rem;flex:none}
.kicker{font-family:var(--font-sc);color:var(--accent);font-size:.95rem;padding-top:.35rem}
.time{font-family:var(--font-display);font-size:clamp(2.6rem,9vw,4.2rem);line-height:1;margin-top:.35rem;font-variant-numeric:var(--nums);white-space:nowrap}
.time .ss{font-size:.4em;margin-left:.14em;opacity:.65}
.time .ap{font-size:.3em;margin-left:.35em;opacity:.8}
.date{margin-top:.45rem}
.place{all:unset;cursor:pointer;display:block;margin-top:.4rem;color:var(--ink-soft);font-size:.86rem}
.place:hover span{text-decoration:underline dotted}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.place:focus-visible{outline:2px solid var(--accent)}
.sub{color:var(--ink-soft);font-size:.85rem}
.sec h2{margin:0 0 .6rem;font-weight:400;font-size:1rem}
dl{margin:0;display:grid;gap:.32rem}
dl>div{display:flex;justify-content:space-between;align-items:baseline;gap:.8rem;flex-wrap:wrap}
dt{color:var(--ink-soft)}
dd{margin:0;text-align:right;font-variant-numeric:var(--nums)}
.phase{display:flex;align-items:center;gap:.75rem;margin-bottom:.55rem}
#phaseIcon{width:2.9rem;height:2.9rem;flex:none;overflow:visible}
.phase-name{font-size:1.02rem}
.legend ul{list-style:none;margin:0;padding:0;display:flex;flex-wrap:wrap;gap:.45rem 1.15rem;font-size:.84rem;color:var(--ink-soft)}
.legend li{display:flex;align-items:center;gap:.5em}
.sw{width:30px;height:10px;overflow:visible;flex:none}

/* ============ Buttons & controls ============ */
.seg{display:inline-flex;border:1px solid var(--rule);border-radius:var(--radius);overflow:hidden;max-width:100%}
.seg button,.ibtn{font:inherit;font-size:.85rem;color:var(--ink);background:transparent;border:0;padding:.4em .75em;min-height:38px;cursor:pointer;touch-action:manipulation}
.seg button{display:inline-flex;align-items:center;gap:.5em}
.seg button+button{border-left:1px solid var(--rule)}
.seg button[aria-pressed="true"]{background:var(--btn-on-bg);color:var(--btn-on-ink)}
.seg svg{width:20px;height:14px;fill:none;stroke:currentColor;stroke-width:1.3}
.ibtn{border:1px solid var(--rule);border-radius:var(--radius);min-width:38px;display:inline-flex;align-items:center;justify-content:center;gap:.4em}
.ibtn svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round}
.ibtn:active{transform:translateY(1px)}

/* ============ Settings sheet ============ */
dialog#settings{
  padding:0;border:1px solid var(--rule);border-radius:var(--sheet-radius,var(--radius));
  color:var(--ink);font-family:var(--font-body);
  background:var(--bg-image),var(--bg);background-blend-mode:var(--bg-blend);background-size:var(--bg-size);
  width:min(560px,calc(100vw - 24px));max-height:min(88vh,820px);max-height:min(88dvh,820px);
  box-shadow:0 20px 60px rgba(0,0,0,.35);
}
dialog#settings::backdrop{background:rgba(10,8,6,.45);backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px)}
@media (max-width:600px){
  dialog#settings{width:100vw;max-width:100vw;max-height:92dvh;margin:auto 0 0;border-radius:var(--sheet-radius,var(--radius)) var(--sheet-radius,var(--radius)) 0 0;border-bottom:0}
}
.sheet{display:flex;flex-direction:column;gap:1.2rem;padding:1rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom,0px))}
.sheet-head{display:flex;justify-content:space-between;align-items:center;position:sticky;top:-1rem;margin:-1rem -1.25rem 0;padding:1rem 1.25rem .6rem;background:inherit;z-index:1}
.sheet-head h2{margin:0;font-family:var(--font-display);font-weight:400;font-size:1.35rem}
.set-sec{display:grid;gap:.7rem}
.set-sec h3{margin:0;font-family:var(--font-sc);font-weight:400;font-size:1rem;color:var(--accent)}
.set-sec p{margin:0}
.set-sec .seg{justify-self:start}
.set-sec .row{display:flex;gap:.6rem;flex-wrap:wrap;align-items:flex-end}
.set-sec label{display:flex;flex-direction:column;gap:.25rem;font-size:.8rem;color:var(--ink-soft)}
.set-sec input:not([type]),.set-sec input[type="text"]{font:inherit;font-size:1rem;color:var(--ink);background:var(--field,transparent);border:1px solid var(--rule);border-radius:var(--radius);padding:.4em .55em;width:9.5em;font-variant-numeric:var(--nums)}
#locMsg:empty,#compassMsg:empty{display:none}
.sheet-foot{border-top:1px solid var(--rule);padding-top:.8rem;font-size:.78rem}

/* Theme cards: each preview carries its own data-style, so it picks up that theme's variables. */
.themes{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:.6rem}
.tcard{position:relative;display:grid!important;grid-template-rows:auto auto auto;gap:.15rem!important;cursor:pointer;color:var(--ink)!important;font-size:.9rem!important}
.tcard input{position:absolute;opacity:0;pointer-events:none}
.tprev{
  position:relative;display:flex;align-items:flex-end;justify-content:space-between;height:74px;padding:.45rem .55rem;overflow:hidden;
  border:1px solid var(--rule);border-radius:var(--radius);
  background:var(--bg-image),var(--bg);background-blend-mode:var(--bg-blend);background-size:var(--bg-size);
  color:var(--ink);font-family:var(--font-display);font-size:1.6rem;line-height:1;
}
.tprev .dots{display:flex;gap:4px;align-self:flex-start}
.tprev .dots i{width:11px;height:11px;border-radius:50%;background:var(--c)}
.tprev .arc{position:absolute;left:10%;right:10%;bottom:-38px;height:76px;border:2px solid var(--today);border-radius:50%;border-bottom-color:transparent;border-left-color:transparent;transform:rotate(-45deg);opacity:.85}
.tname{font-weight:500;margin-top:.25rem}
.tblurb{font-size:.76rem;color:var(--ink-soft)}
.tcard input:checked+.tprev{outline:2.5px solid var(--accent-outer,var(--accent));outline-offset:2px}
.tcard input:focus-visible+.tprev{outline:2.5px dashed var(--accent-outer,var(--accent));outline-offset:2px}

/* Toggle switch */
.switch{flex-direction:row!important;align-items:center;gap:.7rem!important;font-size:.92rem!important;color:var(--ink)!important;cursor:pointer}
.switch input{position:absolute;opacity:0;width:1px;height:1px}
.switch .track{position:relative;flex:none;width:42px;height:24px;border-radius:999px;border:1px solid var(--rule);background:var(--field,transparent);transition:background .15s}
.switch .track::after{content:"";position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:50%;background:var(--ink-soft);transition:transform .15s,background .15s}
.switch input:checked+.track{background:var(--btn-on-bg)}
.switch input:checked+.track::after{transform:translateX(18px);background:var(--btn-on-ink)}
.switch input:focus-visible+.track{outline:2px solid var(--accent);outline-offset:2px}
.switch input:disabled~*{opacity:.5}

/* ============ Plot ============ */
#plot text{font-family:var(--font-plot);fill:var(--ink-soft)}
.up{transform:rotate(var(--rot,0deg))}
.b-sky{fill:var(--sky)} .b-tw1{fill:var(--tw1)} .b-tw2{fill:var(--tw2)} .b-tw3{fill:var(--tw3)} .b-night{fill:var(--night)}
.gl{stroke:var(--grid);stroke-width:.75;stroke-dasharray:var(--grid-dash)}
.gl.mid{stroke:var(--grid-mid)}
.gl.major{stroke:var(--grid-strong);stroke-width:1}
.horizon{stroke:var(--horizon);stroke-width:var(--horizon-w)}
.horizon.speed{stroke-width:calc(var(--horizon-w) * .6);opacity:.5}
.ana{fill:none;stroke:var(--analemma);stroke-width:var(--ana-w)}
.ana.night{opacity:.55}
#plot .ana-label{fill:var(--analemma-label)}
#plot .ana-label.night{opacity:.6}
.trk{fill:none;stroke-linecap:round;stroke-linejoin:round}
.trk-sum{stroke:var(--summer);stroke-width:var(--trk-w);stroke-dasharray:var(--sum-dash)}
.trk-eq{stroke:var(--equinox);stroke-width:var(--trk-w);stroke-dasharray:var(--eq-dash)}
.trk-win{stroke:var(--winter);stroke-width:var(--trk-w);stroke-dasharray:var(--win-dash)}
.trk-today{stroke:var(--today);stroke-width:var(--today-w)}
.trk-moon{stroke:var(--moon-line);stroke-width:var(--moon-w);stroke-dasharray:var(--moon-dash)}
.hdot{fill:var(--today)} .hdot.night{opacity:.45}
.frame{fill:none;stroke:var(--ink);stroke-width:1.2} .frame.thin{stroke-width:.6}
.ticks{fill:none;stroke:var(--ink-soft);stroke-width:.8}
.corner{fill:none;stroke:var(--ink-soft);stroke-width:1}
.speed-deco{fill:none;stroke:var(--accent);stroke-width:1.6;stroke-linecap:round}
#plot .cap{fill:var(--ink)}
#plot .card{fill:var(--ink)}
#plot .trk-label.sum{fill:var(--summer)} #plot .trk-label.eq{fill:var(--equinox)} #plot .trk-label.win{fill:var(--winter)}
#plot .hz{fill:var(--ink)}
.halo{paint-order:stroke;stroke:var(--bg);stroke-width:3px;stroke-linejoin:round}
.mk.below{opacity:.5}
.xhair line,.xhair circle{stroke:var(--sun);stroke-width:.75;opacity:.45;stroke-dasharray:2 3}
#plot .tag-sun{fill:var(--sun)} #plot .tag-moon{fill:var(--moon-line)}
.moon-dark{fill:var(--moon-dark)} .moon-lit{fill:var(--moon)}
.moon-rim{fill:none;stroke:var(--moon-line);stroke-width:.8}
.moon-ring{fill:none;stroke:var(--moon-line);stroke-width:.75}
.sun-disc{fill:var(--sun)}
.sun-ring{fill:none;stroke:var(--sun);stroke-width:1}
.sun-ticks{stroke:var(--sun);stroke-width:1}
