/* Liam's Habits — chunky, friendly, city-builder UI */

:root {
  --bg: #f7f2e8;
  --bg-2: #efe6d4;
  --surface: #ffffff;
  --surface-2: #fbf7ef;
  --ink: #1e2a47;
  --ink-2: #5d6884;
  --ink-3: #8d96ad;
  --line: #e9e0cd;
  --line-2: #ddd2bb;
  --brand: #3d6bff;
  --brand-deep: #2848c7;
  --accent: #ff6b5b;
  --sun: #ffc93c;
  --sun-deep: #e0a100;
  --ok: #22c48a;
  --ok-deep: #13936a;
  --danger: #ef4b4b;
  --danger-deep: #b92f2f;
  --shadow: 0 1px 0 rgba(30, 42, 71, 0.04), 0 10px 28px -14px rgba(30, 42, 71, 0.28);
  --glass: rgba(255, 255, 255, 0.78);
  --radius: 22px;
  --tabbar-h: 72px;
  --head-h: 60px;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f1628;
    --bg-2: #141d36;
    --surface: #18223e;
    --surface-2: #1d2849;
    --ink: #eef2ff;
    --ink-2: #a8b3d1;
    --ink-3: #7681a4;
    --line: #28355a;
    --line-2: #34436d;
    --brand: #5b84ff;
    --brand-deep: #3554c4;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 12px 30px -14px rgba(0, 0, 0, 0.6);
    --glass: rgba(20, 29, 54, 0.78);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0f1628;
  --bg-2: #141d36;
  --surface: #18223e;
  --surface-2: #1d2849;
  --ink: #eef2ff;
  --ink-2: #a8b3d1;
  --ink-3: #7681a4;
  --line: #28355a;
  --line-2: #34436d;
  --brand: #5b84ff;
  --brand-deep: #3554c4;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 12px 30px -14px rgba(0, 0, 0, 0.6);
  --glass: rgba(20, 29, 54, 0.78);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 600 16px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-user-select: none; user-select: none; }
input { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
p { margin: 0; }
svg { display: block; }
.muted { color: var(--ink-2); }
.tiny { font-size: 13px; }
.center { text-align: center; }
[hidden] { display: none !important; }

#app { min-height: 100dvh; }

/* ---------- buttons ---------- */

.btn {
  --b: var(--surface);
  --bs: var(--line-2);
  --fg: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 16px;
  padding: 14px 20px;
  background: var(--b); color: var(--fg);
  font: 600 17px/1 var(--font-display); letter-spacing: 0.01em;
  box-shadow: 0 4px 0 var(--bs);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--bs); }
.btn:disabled { opacity: 0.6; pointer-events: none; }
.btn-primary { --b: var(--brand); --bs: var(--brand-deep); --fg: #fff; }
.btn-secondary { --b: var(--surface); --bs: var(--line-2); border: 2px solid var(--line-2); }
.btn-danger { --b: var(--danger); --bs: var(--danger-deep); --fg: #fff; }
.btn-ghost-danger { --b: transparent; --bs: transparent; --fg: var(--danger); box-shadow: none; border: 2px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--surface); border: 2px solid var(--line);
  box-shadow: 0 3px 0 var(--line);
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linecap: round; }

.seg {
  display: inline-flex; padding: 4px; gap: 4px;
  background: var(--bg-2); border-radius: 14px;
}
.seg button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 10px;
  font: 600 15px var(--font-display); color: var(--ink-2);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 2px 0 var(--line-2); }
.seg.small button { padding: 6px 10px; font-size: 14px; }

/* ---------- layout ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--head-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  max-width: 600px; margin: 0 auto;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
body[data-tab='city'] .topbar { max-width: none; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 38px; height: 38px; margin-top: -4px; }
.brand-title { font: 700 21px var(--font-display); letter-spacing: -0.01em; }
.top-right { display: flex; align-items: center; gap: 8px; }
.pop-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 2px solid var(--line);
  font: 600 15px var(--font-display);
}
.pop-chip b { font-weight: 600; font-variant-numeric: tabular-nums; }

.view {
  max-width: 600px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
}
.view-city { max-width: none; padding: 0; }

.card {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.pad { padding: 16px; }

.section-title {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 18px; margin: 24px 4px 10px;
}
.section-title span { font: 700 12px var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.section-title.flush { margin: 0 0 12px; }
.page-title { font-size: 26px; margin: 8px 4px 16px; }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 2px solid var(--line);
}
.tab {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; border: 0; border-radius: 16px; background: transparent;
  color: var(--ink-3);
  font: 600 13px var(--font-display); letter-spacing: 0.02em;
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.2s; }
.tab.on { color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.tab.on svg { transform: translateY(-1px) scale(1.08); }

/* ---------- guest ribbon ---------- */

.guest-ribbon {
  position: sticky; top: 0; z-index: 25;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 12px 12px;
  background:
    repeating-linear-gradient(-45deg, #ffc93c 0 12px, #1e2a47 12px 24px) bottom / 100% 5px no-repeat,
    #ffc93c;
  color: #1e2a47; font-size: 14px;
}
.guest-ribbon button {
  border: 0; border-radius: 999px; padding: 4px 12px;
  background: #1e2a47; color: #fff; font: 600 13px var(--font-display);
}
body.is-guest .topbar { top: 45px; }

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid; place-items: center; align-content: center;
  padding: 96px 16px 0;
  background: linear-gradient(180deg, #8fd3ff 0%, #d4efff 55%, var(--bg) 100%);
  position: relative; overflow: hidden;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .login { background: linear-gradient(180deg, #070d22 0%, #18275a 60%, var(--bg) 100%); }
}
.login-card {
  position: relative; z-index: 2;
  width: 100%; max-width: 380px;
  padding: 24px 22px 22px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-bolt { width: 112px; margin: -78px auto 4px; }
.login-card h1 { font-size: 30px; }
.login-form { margin-top: 18px; text-align: left; display: grid; gap: 12px; }
.login-skyline { width: min(520px, 110%); margin-top: -10px; opacity: 0.95; }
.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--ink-3); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: var(--line); }
.login-card > .tiny { margin-top: 10px; }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.boot { min-height: 100dvh; display: grid; place-items: center; }
.boot .bolt { width: 96px; animation: bob 1.4s ease-in-out infinite; }

/* ---------- forms ---------- */

.field { display: grid; gap: 6px; }
.field > span { font: 700 13px var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.field input {
  width: 100%; padding: 13px 14px;
  border: 2px solid var(--line-2); border-radius: 14px;
  background: var(--surface-2); outline: none;
  font-weight: 700; font-size: 17px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
.form-error { color: var(--danger); font-size: 14px; font-weight: 700; }

/* ---------- today ---------- */

.hero {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 14px 10px; margin-top: 8px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 10%, var(--surface)), var(--surface) 60%);
}
.hero-bolt { flex: none; width: 92px; }
.hero-talk { flex: 1; min-width: 0; display: grid; gap: 10px; }
.speech {
  position: relative;
  padding: 11px 14px; border-radius: 16px;
  background: var(--surface-2); border: 2px solid var(--line);
  font-weight: 700; font-size: 15px; line-height: 1.35;
}
.speech::before {
  content: ''; position: absolute; left: -9px; top: 18px;
  width: 14px; height: 14px; background: var(--surface-2);
  border-left: 2px solid var(--line); border-bottom: 2px solid var(--line);
  transform: rotate(45deg);
}
.hero-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.stat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--bg-2); font-size: 13px; color: var(--ink-2);
}
.stat-pill b { font: 600 15px var(--font-display); color: var(--ink); }
.stat-pill.flame { background: color-mix(in srgb, #ff8a3d 16%, var(--surface)); }
.flame-icon { display: inline-block; animation: flicker 1.6s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes flicker { 50% { transform: scale(1.12) rotate(-4deg); } }

.day-row { display: flex; align-items: center; justify-content: space-between; margin: 20px 2px 10px; }
.date-label { font: 600 15px var(--font-display); color: var(--ink-2); }

.build { padding: 14px 16px 12px; }
.build-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.build .label { font: 600 17px var(--font-display); }
.build-count { font: 600 15px var(--font-display); color: var(--ink-2); }
.build-count b { font-size: 22px; color: var(--ink); }
.build-track {
  position: relative; height: 18px; border-radius: 999px;
  background: var(--bg-2); overflow: visible;
}
.build-fill {
  height: 100%; border-radius: 999px;
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.28) 0 8px, transparent 8px 16px),
    linear-gradient(90deg, var(--sun), #ff9f3d);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  transition: width 0.6s cubic-bezier(0.3, 1.4, 0.5, 1);
  animation: stripes 1.2s linear infinite;
  background-size: 22.6px 22.6px, 100% 100%;
}
.build.complete .build-fill { background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.25) 0 8px, transparent 8px 16px), linear-gradient(90deg, #22c48a, #14b8b8); background-size: 22.6px 22.6px, 100% 100%; }
@keyframes stripes { to { background-position: 22.6px 0, 0 0; } }
.build-tick { position: absolute; top: 4px; bottom: 4px; width: 2px; margin-left: -1px; background: color-mix(in srgb, var(--ink) 12%, transparent); border-radius: 2px; }
.build-hook {
  position: absolute; top: 50%; font-size: 22px;
  transform: translate(-50%, -58%);
  transition: left 0.6s cubic-bezier(0.3, 1.4, 0.5, 1);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.15));
}
.build-note { margin-top: 10px; font-size: 14px; color: var(--ink-2); }
.build.complete { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.build.complete .build-note b { color: var(--ok-deep); }

.habit-list { display: grid; gap: 10px; margin-top: 12px; }
.habit-card {
  --hc-tint: color-mix(in srgb, var(--hc) 15%, var(--surface));
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 10px;
  background: var(--surface);
  border: 2px solid var(--line); border-radius: 20px;
  box-shadow: 0 3px 0 var(--line);
  transition: background 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.habit-card.done { background: var(--hc-tint); border-color: color-mix(in srgb, var(--hc) 55%, var(--line)); box-shadow: 0 3px 0 color-mix(in srgb, var(--hc) 45%, var(--line)); }
.habit-card.broken { border-style: dashed; border-color: color-mix(in srgb, #e2892f 55%, var(--line)); }
.habit-card.just-done { animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes pop { 40% { transform: scale(1.03); } }
.habit-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  border: 0; background: none; padding: 0; text-align: left;
}
.habit-icon {
  flex: none; width: 50px; height: 50px; border-radius: 15px;
  display: grid; place-items: center; font-size: 26px;
  background: color-mix(in srgb, var(--hc) 18%, var(--surface));
  box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--hc) 22%, transparent);
}
.habit-icon.big { width: 60px; height: 60px; font-size: 32px; border-radius: 18px; }
.habit-text { min-width: 0; display: grid; gap: 1px; }
.habit-name { font: 600 17px var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-meta { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-card.done .habit-name { color: var(--ink); }

.check-btn {
  flex: none; width: 54px; height: 54px; border-radius: 17px;
  display: grid; place-items: center;
  background: var(--surface); border: 2.5px solid var(--line-2);
  box-shadow: 0 4px 0 var(--line-2);
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s, border-color 0.2s;
}
.check-btn svg { width: 30px; height: 30px; fill: none; stroke: var(--line-2); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.check-btn:hover svg { stroke: var(--ink-3); }
.check-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--line-2); }
.check-btn.on { background: var(--hc); border-color: var(--hc-deep); box-shadow: 0 4px 0 var(--hc-deep); }
.check-btn.on svg { stroke: #fff; stroke-dasharray: 24; animation: draw 0.35s ease-out; }
.check-btn.on:active { box-shadow: 0 0 0 var(--hc-deep); }
@keyframes draw { from { stroke-dashoffset: 24; } }

.count-ctl { flex: none; display: flex; align-items: center; gap: 6px; }
.count-btn {
  width: 58px; height: 58px; border-radius: 50%; border: 0; padding: 5px;
  background: conic-gradient(var(--hc) calc(var(--p) * 360deg), var(--line) 0);
  box-shadow: 0 4px 0 var(--line-2);
  transition: transform 0.08s, box-shadow 0.08s;
}
.count-btn > span {
  width: 100%; height: 100%; border-radius: 50%;
  display: grid; place-items: center; align-content: center;
  background: var(--surface); line-height: 1;
}
.count-btn b { font: 600 19px var(--font-display); }
.count-btn small { font-size: 11px; color: var(--ink-3); font-weight: 800; }
.count-btn:active { transform: translateY(4px); box-shadow: none; }
.count-btn.on { background: var(--hc); box-shadow: 0 4px 0 var(--hc-deep); display: grid; place-items: center; }
.count-btn.on svg { width: 30px; height: 30px; fill: none; stroke: #fff; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.count-btn.bump { animation: pop 0.3s; }
.mini-btn {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  border: 2px solid var(--line); background: var(--surface);
}
.mini-btn svg { width: 16px; fill: none; stroke: var(--ink-3); stroke-width: 3; stroke-linecap: round; }

.habit-list.bonus .habit-card:not(.done) { opacity: 0.8; }

.add-card {
  width: 100%; margin-top: 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 16px; border-radius: 20px;
  border: 2.5px dashed var(--line-2); background: transparent;
  color: var(--ink-2); font: 600 16px var(--font-display);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.add-card:hover { background: var(--surface); color: var(--brand); border-color: var(--brand); }
.add-card svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }

.empty { padding: 26px 20px 20px; margin-top: 30px; text-align: center; display: grid; gap: 12px; }
.empty-bolt { width: 128px; margin: -70px auto 0; }
.empty h2 { font-size: 26px; }
.quick { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 6px 0 8px; }
.quick-chip {
  padding: 8px 12px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface-2);
  font-weight: 700; font-size: 14px;
  box-shadow: 0 2px 0 var(--line);
}
.quick-chip:active { transform: translateY(2px); box-shadow: none; }

/* ---------- city ---------- */

.city-scene {
  position: relative; overflow: hidden;
  min-height: calc(100dvh - var(--head-h) - var(--tabbar-h) - env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  transition: background 0.6s;
}
body.is-guest .city-scene { min-height: calc(100dvh - var(--head-h) - var(--tabbar-h) - 45px - env(safe-area-inset-bottom)); }
.sky-day { background: linear-gradient(180deg, #7fcbff 0%, #c4e9ff 55%, #eaf8ff 100%); }
.sky-dawn { background: linear-gradient(180deg, #ff9f8a 0%, #ffd2a6 50%, #fff0d9 100%); }
.sky-dusk { background: linear-gradient(180deg, #2e2763 0%, #a2557a 55%, #ffaa74 100%); }
.sky-night { background: linear-gradient(180deg, #050b1f 0%, #10204d 60%, #1f3170 100%); }

.sky-layer { position: absolute; inset: 0; pointer-events: none; }
.stars i { position: absolute; border-radius: 50%; background: #fff; animation: twinkle 3s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: 0.25; } }
.cloud {
  position: absolute; height: 26px; border-radius: 999px; background: rgba(255, 255, 255, 0.85);
  animation: drift linear infinite;
}
.cloud::before, .cloud::after { content: ''; position: absolute; background: inherit; border-radius: 50%; }
.cloud::before { width: 40%; height: 180%; left: 18%; bottom: 20%; }
.cloud::after { width: 30%; height: 140%; left: 50%; bottom: 25%; }
.cloud.c1 { width: 110px; top: 22%; animation-duration: 70s; animation-delay: -20s; }
.cloud.c2 { width: 80px; top: 36%; animation-duration: 95s; animation-delay: -60s; opacity: 0.7; }
.cloud.c3 { width: 140px; top: 14%; animation-duration: 120s; animation-delay: -5s; opacity: 0.85; }
@keyframes drift { from { transform: translateX(-180px); } to { transform: translateX(110vw); } }

.city-hud {
  position: relative; z-index: 2;
  margin: 12px auto 0; width: calc(100% - 32px); max-width: 520px;
  padding: 12px 14px; border-radius: 20px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 2px solid color-mix(in srgb, #fff 45%, transparent);
  box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.5);
  display: grid; gap: 8px;
}
.sky-night .city-hud, .sky-dusk .city-hud { background: rgba(14, 22, 48, 0.62); color: #eef2ff; border-color: rgba(255, 255, 255, 0.12); }
.sky-night .hud-sub, .sky-dusk .hud-sub { color: #b9c4e6; }
.hud-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud-level { font: 600 24px var(--font-display); }
.hud-sub { font-size: 13px; color: var(--ink-2); }
.sky-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; border: 0;
  background: rgba(255, 255, 255, 0.7); color: #1e2a47;
  font: 600 14px var(--font-display);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}
.meter { height: 10px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 12%, transparent); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--meter, var(--sun)), color-mix(in srgb, var(--meter, #ff9f3d) 70%, #ff9f3d)); transition: width 0.6s; }
.sky-night .meter, .sky-dusk .meter { background: rgba(255, 255, 255, 0.16); }

.city-stage { position: relative; z-index: 1; flex: 1; display: grid; place-items: center; padding: 8px 10px 0; }
.city-stage svg.city { width: 100%; max-width: 900px; max-height: calc(100dvh - 250px); height: auto; overflow: visible; }
.city-hint { position: relative; z-index: 2; text-align: center; font-size: 13px; padding: 4px 0 18px; color: #4a5776; }
.sky-night .city-hint, .sky-dusk .city-hint { color: #b9c4e6; }

.bldg { cursor: pointer; }
.bldg:hover { filter: brightness(1.07); }
.bldg:focus { outline: none; }
.bldg.rise { animation: rise 0.9s cubic-bezier(0.25, 1.4, 0.45, 1) both; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes rise { from { transform: scaleY(0.15); opacity: 0.4; } }
.bubble.todo { animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }
.blink { animation: blink 1.4s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.2; } }
.beacon { animation: beacon 2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes beacon { 50% { transform: scale(1.8); opacity: 0.6; } }

/* ---------- stats ---------- */

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.tile {
  display: grid; justify-items: start; gap: 2px;
  padding: 12px; border-radius: 18px;
  background: var(--surface); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  min-width: 0;
}
.tile-icon { font-size: 20px; }
.tile b { font: 600 22px var(--font-display); font-variant-numeric: tabular-nums; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile b.small { font-size: 15.5px; line-height: 1.75; }
.tile span:last-child { font-size: 12px; color: var(--ink-2); line-height: 1.2; }
@media (max-width: 380px) { .tiles { grid-template-columns: repeat(2, 1fr); } }

.heatmap {
  display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  grid-template-columns: repeat(var(--weeks), 1fr);
  gap: 3px;
}
.hm, .hm-legend i {
  position: relative; aspect-ratio: 1; border-radius: 3px;
  background: var(--bg-2);
}
.hm::after, .hm-legend i::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: var(--hm, #22c48a); opacity: var(--o, 0);
}
.hm.none { background: color-mix(in srgb, var(--bg-2) 50%, transparent); }
.hm.future { background: transparent; }
.hm.today { outline: 2px solid var(--ink-3); outline-offset: -1px; }
.hm-legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 10px; font-size: 12px; color: var(--ink-3); --hm: #22c48a; }
.hm-legend i { width: 12px; }

.stat-list { display: grid; gap: 8px; }
.stat-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px 10px 10px; border-radius: 18px;
  background: var(--surface); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line);
  text-align: left;
}
.stat-row .habit-icon { width: 44px; height: 44px; font-size: 22px; border-radius: 13px; }
.stat-row .habit-text { flex: 1; }
.streaks { display: grid; justify-items: end; }
.streaks b { font: 600 17px var(--font-display); }
.streaks small { font-size: 12px; color: var(--ink-3); }

/* ---------- sheets ---------- */

.sheet-root { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 16, 36, 0.45); opacity: 0; transition: opacity 0.25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 600px; margin: 0 auto;
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.2, 1, 0.3, 1);
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, 0.4);
}
.sheet-root.open .sheet-backdrop { opacity: 1; }
.sheet-root.open .sheet { transform: none; }
.sheet-grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 0 auto 8px; }
.sheet-close { position: absolute; top: 12px; right: 14px; z-index: 2; font-size: 16px; color: var(--ink-2); }
.sheet-body h2 { font-size: 24px; margin-bottom: 14px; padding-right: 48px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }

.detail-art {
  margin: 4px -18px 0; padding: 10px 0 0;
  height: 230px; display: grid; place-items: end center;
  border-radius: 0;
}
.detail-art svg { height: 100%; width: auto; max-width: 100%; }
.detail-title { display: flex; align-items: center; gap: 12px; margin: 14px 0 14px; }
.detail-title h2 { margin: 0 0 4px; padding: 0; }
.stage-chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--hc) 18%, var(--surface)); color: var(--ink);
  font: 600 13px var(--font-display);
}
.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.detail-stats div { padding: 10px; border-radius: 16px; background: var(--bg-2); display: grid; gap: 2px; text-align: center; }
.detail-stats b { font: 600 22px var(--font-display); }
.detail-stats span { font-size: 12px; color: var(--ink-2); }
.notice {
  padding: 10px 12px; border-radius: 14px; margin-bottom: 12px; font-size: 14px;
  background: color-mix(in srgb, #e2892f 14%, var(--surface)); border: 2px dashed color-mix(in srgb, #e2892f 50%, transparent);
}
.next-stage { display: grid; gap: 8px; box-shadow: none; }
.next-stage .row { display: flex; justify-content: space-between; font-size: 15px; }
.detail-foot { margin-top: 10px; }

.editor { display: grid; gap: 16px; }
.editor h2 { margin-bottom: 0; }
.editor-preview {
  height: 150px; margin: 0 -18px; display: grid; place-items: end center;
  background: linear-gradient(180deg, #a6dcff, #e6f6ff);
}
.editor-preview svg { height: 100%; width: auto; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji {
  aspect-ratio: 1; border-radius: 12px; font-size: 22px;
  border: 2px solid var(--line); background: var(--surface-2);
  display: grid; place-items: center; padding: 0;
}
.emoji.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--surface)); transform: scale(1.06); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--surface); background: var(--c);
  box-shadow: 0 0 0 2px var(--line), 0 3px 0 2px var(--line);
}
.swatch.on { box-shadow: 0 0 0 3px var(--c), 0 3px 0 3px var(--c); transform: scale(1.08); }
.count-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  aspect-ratio: 1; max-height: 48px; border-radius: 14px;
  border: 2px solid var(--line-2); background: var(--surface-2);
  font: 600 16px var(--font-display); color: var(--ink-3);
  box-shadow: 0 3px 0 var(--line-2); padding: 0;
}
.day.on { background: var(--brand); border-color: var(--brand-deep); color: #fff; box-shadow: 0 3px 0 var(--brand-deep); }
.presets { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.presets button { border: 0; background: var(--bg-2); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 700; color: var(--ink-2); }

.confirm { text-align: center; display: grid; gap: 8px; padding-top: 8px; }
.confirm h2 { padding: 0; margin: 0; }
.confirm-icon { font-size: 48px; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 2px solid var(--line); }
.setting-row p { font-size: 13px; }
.setting-row + .btn, .setting-row + .btn + .btn { margin-top: 12px; }
.sheet-body > .btn + .btn { margin-top: 10px; }
.sheet-body > .tiny { margin-top: 14px; }
.toggle {
  flex: none; width: 54px; height: 32px; border-radius: 999px; border: 0; padding: 3px;
  background: var(--line-2); transition: background 0.2s;
}
.toggle i { display: block; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.toggle.on { background: var(--ok); }
.toggle.on i { transform: translateX(22px); }

/* ---------- modal ---------- */

.modal-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 16, 36, 0.55); opacity: 0; transition: opacity 0.2s; }
.modal {
  position: relative; width: 100%; max-width: 360px;
  padding: 0 20px 20px; border-radius: 28px;
  background: var(--surface); text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.5);
  transform: scale(0.8) translateY(20px); opacity: 0;
  transition: transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1), opacity 0.2s;
}
.modal-root.open .modal-backdrop { opacity: 1; }
.modal-root.open .modal { transform: none; opacity: 1; }
.modal-art {
  height: 210px; margin: 0 -20px 12px; padding-top: 12px;
  border-radius: 28px 28px 0 0;
  background: radial-gradient(circle at 50% 70%, #fff6d1, transparent 60%), linear-gradient(180deg, #9fd8ff, #e6f6ff);
  display: grid; place-items: end center; overflow: hidden;
}
.modal-art svg { height: 100%; width: auto; }
.modal-bolt { width: 150px; padding-bottom: 6px; animation: bob 1.6s ease-in-out infinite; }
.modal-bolt svg { width: 100%; height: auto; }
.modal-kicker { font: 700 13px var(--font-body); text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); }
.modal h2 { font-size: 26px; margin: 4px 0 6px; }
.modal p { color: var(--ink-2); margin-bottom: 18px; }

/* ---------- effects ---------- */

.fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 70; }
.float-text {
  position: fixed; z-index: 71; pointer-events: none;
  transform: translate(-50%, -100%);
  font: 600 18px var(--font-display); color: var(--ok-deep);
  text-shadow: 0 2px 0 #fff;
  animation: floatUp 1.1s ease-out forwards;
}
@keyframes floatUp { to { transform: translate(-50%, -260%); opacity: 0; } }
.toast {
  position: fixed; z-index: 55; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0;
  max-width: calc(100% - 32px);
  padding: 11px 18px; border-radius: 16px;
  background: var(--ink); color: var(--bg);
  font-weight: 700; font-size: 15px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.5);
  transition: transform 0.25s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.2s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Bolt ---------- */

.bolt { width: 100%; height: auto; overflow: visible; }
.bolt-wave .bolt-arm-r { animation: wave 1.2s ease-in-out infinite; transform-origin: 90px 78px; }
@keyframes wave { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-35deg); } 60% { transform: rotate(-10deg); } }
.bolt-happy .bolt-body { animation: hop 1.8s ease-in-out infinite; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 75% { transform: translateY(-5px); } }
.bolt-eyes { animation: blinkEyes 4s infinite; transform-origin: 60px 53px; }
@keyframes blinkEyes { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
.bolt-z { animation: zz 2.4s ease-in-out infinite; }
.bolt-z.z2 { animation-delay: 0.6s; }
@keyframes zz { 0% { opacity: 0; transform: translate(0, 4px); } 50% { opacity: 1; } 100% { opacity: 0; transform: translate(4px, -6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- wider screens ---------- */

@media (min-width: 720px) {
  .tabbar { left: 50%; right: auto; bottom: 16px; transform: translateX(-50%); width: 420px; border: 2px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); padding-bottom: 8px; }
  .view { padding-bottom: 120px; }
  .city-scene { min-height: calc(100dvh - var(--head-h)); }
  .city-hint { padding-bottom: 110px; }
}
