:root {
  --paper: #FBF4E6;
  --grid: #EADFCB;
  --panel: #FFFFFF;
  --ink: #22262F;
  --ink-2: #4A4F5C;
  --muted: #7A7F8C;
  --accent: #D9532B;
  --c-dry: #DCE3EC;
  --c-comfortable: #CDE8B8;
  --c-humid: #F5EFA8;
  --c-muggy: #F6C6A8;
  --c-oppressive: #F79AC0;
  --c-miserable: #F0755B;
  --lc: var(--c-comfortable);
  --border: 3px solid var(--ink);
  --shadow: 6px 6px 0 var(--ink);
  --display: 'Space Grotesk', 'Avenir Next', 'Segoe UI', sans-serif;
  --body: 'Nunito', 'Avenir Next', 'Segoe UI', sans-serif;
}
[data-level="dry"] { --lc: var(--c-dry); }
[data-level="comfortable"] { --lc: var(--c-comfortable); }
[data-level="humid"] { --lc: var(--c-humid); }
[data-level="muggy"] { --lc: var(--c-muggy); }
[data-level="oppressive"] { --lc: var(--c-oppressive); }
[data-level="miserable"] { --lc: var(--c-miserable); }

* { box-sizing: border-box; }
html { background: var(--paper); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100dvh;
}
.display { font-family: var(--display); font-weight: 700; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: #B8401E; text-decoration: underline; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
h1, h2, p { margin: 0; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 28px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.place { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 2px; }
.place svg:first-child { color: var(--accent); flex: none; }
.place .chev { color: var(--muted); }
.place-name { font-size: 24px; letter-spacing: .5px; text-transform: uppercase; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.share {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: var(--border); background: var(--panel); color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}
.share:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

.seg { display: flex; border: var(--border); background: var(--panel); }
.seg button {
  font-family: var(--display); font-weight: 700; font-size: 15px; padding: 7px 14px; min-height: 38px; color: var(--ink);
  border-right: var(--border); transition: background .15s, color .15s;
}
.seg button:last-child { border-right: 0; }
.seg button.is-on { background: var(--ink); color: var(--paper); }

/* hero */
.hero {
  position: relative; border: 4px solid var(--ink); background: var(--panel);
  box-shadow: 8px 8px 0 var(--ink); transition: background .3s;
}
/* The hero card's own proportion; the character sits inside it. */
.scene { width: 100%; aspect-ratio: 300 / 262; display: grid; place-items: center; }
.buddy {
  width: 66%; height: auto; aspect-ratio: 240 / 248;
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 600% 100%;
  image-rendering: pixelated;
  animation: walk6 2.7s steps(6) infinite;
}
[data-level="dry"] .buddy { background-image: url(/sprites/cloud-dry.webp); }
[data-level="comfortable"] .buddy { background-image: url(/sprites/cloud-comfortable.webp); }
[data-level="humid"] .buddy { background-image: url(/sprites/cloud-humid.webp); }
[data-level="muggy"] .buddy { background-image: url(/sprites/cloud-muggy.webp); }
[data-level="oppressive"] .buddy { background-image: url(/sprites/cloud-oppressive.webp); }
[data-level="miserable"] .buddy { background-image: url(/sprites/cloud-miserable.webp); }


/* n frames advance to n/(n-1)*100% so the last step lands on the last frame */
@keyframes walk6 { to { background-position: 120% 0; } }
@media (prefers-reduced-motion: reduce) { .buddy { animation: none !important; } }

.chip {
  position: absolute; bottom: -4px; display: flex; align-items: center; gap: 8px;
  border: var(--border); background: var(--panel); padding: 6px 12px; font-size: 13px; font-weight: 700;
}
.level-chip { left: -4px; padding: 6px 14px 6px 10px; }
.level-chip .display { font-size: 20px; letter-spacing: 1px; text-transform: uppercase; }
.time-chip { right: -4px; font-family: var(--display); font-size: 15px; }

/* headline + stats */
.headline { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; }
.headline h1 { font-size: 34px; line-height: 1.05; letter-spacing: .5px; text-transform: uppercase; }
.headline p { font-size: 15px; line-height: 1.45; color: var(--ink-2); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; border: var(--border); background: var(--panel); padding: 10px 6px; box-shadow: 4px 4px 0 var(--ink); }
.stat .k { font-family: var(--display); font-size: 13px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.stat .v { font-size: 24px; text-transform: uppercase; }
.stat.comfort { background: var(--lc); transition: background .3s; }
.stat.comfort .k { color: var(--ink-2); }
.stat.comfort .v { font-size: 18px; letter-spacing: .5px; }

/* blocks */
.block { display: flex; flex-direction: column; gap: 10px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.block-head h2 { font-size: 20px; letter-spacing: 1px; text-transform: uppercase; }
.block-head .sub { font-size: 13px; font-weight: 700; color: var(--muted); text-align: right; }
.block-head .sub a { color: var(--accent); }

.hours { display: flex; overflow-x: auto; scroll-snap-type: x proximity; border: var(--border); background: var(--panel); scrollbar-width: none; box-shadow: var(--shadow); }
.hours::-webkit-scrollbar { display: none; }
.hour {
  flex: none; scroll-snap-align: start; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 58px; padding: 10px 4px; background: var(--lc); border-right: 2px solid var(--ink);
}
.hour:last-child { border-right: 0; }
.hour.is-now { box-shadow: inset 0 -5px 0 var(--ink); }
.hour .t { font-family: var(--display); font-size: 13px; color: var(--ink-2); }
.hour .dot { display: none; }
.hour .d { font-family: var(--display); font-size: 17px; font-weight: 700; }

/* "Is this normal?" and "When to go out" panels */
.panel { border: var(--border); background: var(--panel); padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.panel .verdict { font-size: 22px; line-height: 1.1; letter-spacing: .5px; text-transform: uppercase; }
.panel .note { font-size: 13px; line-height: 1.45; font-weight: 600; color: var(--ink-2); }
.panel.window { background: var(--lc); transition: background .3s; }  /* overridden per-window in app.js */
.panel.window .note { color: var(--ink); }

.mixbar { display: flex; height: 22px; border: 2px solid var(--ink); position: relative; overflow: hidden; margin-top: 2px; }
.mixbar i { min-width: 3px; }
/* Marker sits at the current percentile; because segments are sized by their
   share of past hours, that position lands inside today's band by construction. */
.mixbar .marker {
  position: absolute; top: 0; bottom: 0; width: 4px; background: var(--ink);
  transform: translateX(-2px); box-shadow: 0 0 0 2px var(--paper);
}
.mixends { display: flex; justify-content: space-between; font-family: var(--display); font-size: 12px; color: var(--muted); }

.week { display: flex; flex-direction: column; gap: 8px; }
.day {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) 46px; align-items: center; gap: 10px;
  border: var(--border); background: var(--panel); padding: 10px 12px; min-height: 48px;
}
.day .n { font-size: 17px; text-transform: uppercase; }
.day .bar { display: flex; height: 16px; border: 2px solid var(--ink); overflow: hidden; }
.day .bar i { flex: 1; background: var(--lc); }
.day .d { font-family: var(--display); font-size: 17px; font-weight: 700; text-align: right; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; padding-top: 4px; }
.legend span { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 13px; color: var(--ink-2); }
.legend i { width: 12px; height: 12px; border: 2px solid var(--ink); background: var(--lc); }

.foot p { font-size: 11px; line-height: 1.5; color: var(--muted); text-align: center; font-weight: 600; }

/* loading / error */
[data-state="loading"] .hours, [data-state="loading"] .week { opacity: .35; }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); font-family: var(--display); font-size: 15px; padding: 10px 16px; border: var(--border);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* location sheet */
.sheet { border: 0; padding: 0; margin: 0; background: transparent; color: var(--ink); width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; inset: 0; }
.sheet::backdrop { background: rgba(34, 38, 47, .55); }
.sheet-inner {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 480px;
  background: var(--paper); border: 4px solid var(--ink); border-bottom: 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 20px);
  display: flex; flex-direction: column; gap: 12px; max-height: 88dvh;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 24px; text-transform: uppercase; letter-spacing: 1px; }
.close { width: 44px; height: 44px; display: grid; place-items: center; border: var(--border); background: var(--panel); }
.search { display: flex; align-items: center; gap: 10px; background: var(--panel); border: var(--border); padding: 0 14px; min-height: 50px; color: var(--muted); }
.search input { flex: 1; background: none; border: 0; outline: 0; color: var(--ink); font: inherit; font-size: 17px; font-weight: 600; min-width: 0; }
.search input::placeholder { color: var(--muted); }
.geo { display: flex; align-items: center; gap: 8px; color: var(--accent); font-family: var(--display); font-size: 16px; min-height: 44px; padding: 0 4px; }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.results li button { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: var(--border); padding: 10px 14px; min-height: 52px; }
.results .nm { font-family: var(--display); font-size: 18px; }
.results .ad { font-size: 12px; color: var(--muted); font-weight: 600; }
.results .empty { font-size: 13px; color: var(--muted); padding: 8px 4px; font-weight: 600; }

@media (min-width: 640px) { .app { padding-top: 40px; } }
