/* ============ Tokens, reset, app chrome ============ */
:root {
  --blue: #007aff;
  --blue-press: #0071e3;
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --label: #1c1c1e;
  --secondary: rgba(60, 60, 67, 0.6);
  --tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.22);
  --hairline: rgba(60, 60, 67, 0.18);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.2);
  --bar-bg: rgba(249, 249, 249, 0.83);
  --star: #f09a2b;
  --star-track: rgba(60, 60, 67, 0.18);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 96px;
  --tabbar-h: 53px;
  --sheet-ease: cubic-bezier(0.32, 0.72, 0, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --label: #f5f5f7;
    --secondary: rgba(235, 235, 245, 0.6);
    --tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.65);
    --hairline: rgba(255, 255, 255, 0.12);
    --fill: rgba(120, 120, 128, 0.24);
    --fill-2: rgba(120, 120, 128, 0.36);
    --bar-bg: rgba(22, 22, 24, 0.8);
    --star-track: rgba(235, 235, 245, 0.2);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font-family: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

#app { position: fixed; inset: 0; overflow: hidden; }

/* ---------- Nav bar ---------- */
.nav-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  height: var(--nav-h);
  padding: env(safe-area-inset-top) 16px 0;
  background: transparent;
  transition: background-color 0.24s ease;
  pointer-events: none;
}
.nav-bar > * { pointer-events: auto; }
.nav-bar.collapsed {
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: inset 0 -0.5px 0 var(--hairline);
}
.nav-large { padding-top: 38px; }
.nav-meta {
  display: flex; align-items: center; justify-content: space-between;
  height: 26px; opacity: 1;
  transition: opacity 0.18s ease, transform 0.24s ease;
}
.nav-date {
  font-size: 13px; font-weight: 700; letter-spacing: 0.02em;
  color: var(--secondary); text-transform: uppercase;
}
.avatar {
  width: 34px; height: 34px; margin-top: -8px;
  border-radius: 50%;
  background: linear-gradient(180deg, #5ac8fa, #0a84ff);
  color: #fff; font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease;
}
.avatar:active { transform: scale(0.94); }
.nav-title {
  margin: 2px 0 0;
  font-size: 33px; font-weight: 800; letter-spacing: 0.01em; line-height: 41px;
  transition: opacity 0.18s ease, transform 0.24s var(--sheet-ease);
}
.nav-compact {
  position: absolute; inset: env(safe-area-inset-top) 0 0 0;
  height: 44px; display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.22s ease;
}
.nav-title-compact { font-size: 17px; font-weight: 600; }
.nav-bar.collapsed .nav-title,
.nav-bar.collapsed .nav-meta { opacity: 0; transform: translateY(-30px); pointer-events: none; }
.nav-bar.collapsed .nav-compact { opacity: 1; transform: translateY(0); }
.nav-bar.collapsed { height: calc(44px + env(safe-area-inset-top)); }

/* ---------- Pages ---------- */
.tabs-root { position: absolute; inset: 0; }
.tab-page {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--nav-h) + env(safe-area-inset-top)) 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s ease;
}
.tab-page.active { opacity: 1; visibility: visible; }
.page-col { max-width: 720px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 900px) { .page-col { max-width: 860px; } }

/* ---------- Tab bar ---------- */
.tab-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: inset 0 0.5px 0 var(--hairline);
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--secondary); border-radius: 6px;
}
.tab-btn .tab-icon { width: 27px; height: 27px; display: block; }
.tab-btn .tab-icon svg { width: 100%; height: 100%; display: block; }
.tab-btn .tab-label { font-size: 10px; font-weight: 500; letter-spacing: 0.01em; }
.tab-btn.active { color: var(--blue); }
.tab-btn:active { opacity: 0.65; }
body.sheet-open .tab-bar { opacity: 0; pointer-events: none; }
body.sheet-open .tab-bar, .tab-bar { transition: opacity 0.2s ease; }

/* ---------- Sheets ---------- */
.sheet-overlay {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0);
  visibility: hidden;
  transition: background 0.32s ease, visibility 0.32s;
}
.sheet-overlay.active { background: rgba(0, 0, 0, 0.35); visibility: visible; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; top: 0;
  background: var(--bg-elev);
  border-radius: 12px 12px 0 0;
  transform: translateY(103%);
  transition: transform 0.46s var(--sheet-ease);
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
}
.sheet.presented { transform: translateY(0); }
.sheet-grab {
  height: 34px; flex: none;
  display: flex; align-items: center; justify-content: center;
  cursor: grab; touch-action: none;
}
.sheet-grab::before {
  content: ""; width: 38px; height: 5px; border-radius: 3px;
  background: var(--fill-2);
}
.sheet-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.sub-sheet {
  top: 12%;
  border-radius: 12px 12px 0 0;
  background: var(--bg-elev);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3);
}

@media (min-width: 720px) {
  .sheet.pd-sheet {
    left: 50%; right: auto; top: 28px; bottom: 28px;
    width: min(580px, calc(100vw - 48px));
    margin-left: calc(min(580px, (100vw - 48px)) / -2);
    border-radius: 20px;
    transform: translateY(calc(100% + 60px));
  }
  .sheet.pd-sheet.presented { transform: translateY(0); }
  .sub-sheet {
    left: 50%; right: auto; top: 12%; bottom: 4%;
    width: min(520px, calc(100vw - 48px));
    margin-left: calc(min(520px, (100vw - 48px)) / -2);
    border-radius: 20px;
    transform: translateY(calc(100% + 80px));
  }
  .sub-sheet.presented { transform: translateY(0); }
}

/* ---------- Press physics ---------- */
.pressable { transition: transform 0.34s cubic-bezier(0.22, 1.4, 0.36, 1), box-shadow 0.24s ease; }
.pressable.pressed { transform: scale(0.965); transition: transform 0.1s ease; }
@media (hover: hover) {
  .pressable:hover { box-shadow: 0 6px 22px rgba(0, 0, 0, 0.1); }
}
@media (prefers-reduced-motion: reduce) {
  .pressable, .pressable.pressed { transform: none !important; transition: none !important; }
  .sheet { transition-duration: 0.01s; }
}
