/* Life OS: tokens + shared components (SPEC §7). Screen styles live in screens/*.css. */

:root {
  --bg: #101215;
  --surface: #191C21;
  --surface-2: #15181C;
  --chip: #22262C;
  --border: #2C3138;
  --text: #ECEDEF;
  --text-2: #C9CDD3;
  --muted: #9AA1AB;
  --accent: #F0A63A;
  --ok: #57C08A;
  --ok-bg: #15201A;
  --ok-border: #2F5A43;
  --warn: #F0C77A;
  --warn-bg: #2A2316;
  --warn-border: #6B5320;
  --danger: #F2B1AC;

  --ring-border: #4A5058;
  --divider: #22262C;
  --line: #D5D8DD;
  --strike: #7A818B;
  --accent-bg: #3A2E17;
  --accent-text: #F6D79A;
  --on-accent: #1A1406;
  --on-ok: #0E1A13;
  --ok-text: #7FD3A6;

  --r-card: 14px;
  --r-input: 10px;
  --tap: 44px;
  --nav-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.sheet-open, html.sheet-open body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a { color: var(--accent); }
a:hover { color: #F6C57A; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; font-weight: 600; line-height: 1.2; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(8px + var(--safe-t)) 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
.screen { display: flex; flex-direction: column; gap: 8px; padding-top: 16px; }
.loading, .broke { align-items: flex-start; gap: 12px; padding-top: 48px; }
.broke-msg {
  margin: 0; padding: 12px; width: 100%; white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 13px; color: var(--danger);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-input);
}

/* ---------- nav: bottom bar under 768px, sticky top bar from 768px ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + var(--safe-b));
}
.nav-inner {
  max-width: 640px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
}
.nav-tab {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tap); font-size: 13px; color: var(--muted); text-decoration: none;
  border-radius: var(--r-input);
}
.nav-tab:hover { color: var(--text-2); }
.nav-tab.active { color: var(--accent); font-weight: 600; }
.nav-sync {
  position: absolute; top: 6px; right: 8px;
  width: 6px; height: 6px; border-radius: 50%; background: transparent;
}
.nav-sync.s-pending { background: var(--accent); }
.nav-sync.s-offline { background: var(--warn); }
.nav-sync.s-error { background: var(--danger); }

@media (min-width: 768px) {
  .nav {
    position: sticky; top: 0; bottom: auto;
    border-top: 0; border-bottom: 1px solid var(--border);
    padding: calc(4px + var(--safe-t)) 16px 4px;
  }
  .nav-inner { display: flex; gap: 4px; padding: 0 0; }
  .nav-tab { padding: 0 14px; font-size: 14px; }
  .nav-sync { top: 50%; right: 16px; margin-top: -3px; }
  .app { padding-top: 8px; padding-bottom: 48px; }
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 10px 6px 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
}
.card.done, .done.card { background: var(--ok-bg); border-color: var(--ok-border); }
.tap {
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.tap input, .tap textarea, .tap select { user-select: text; -webkit-user-select: text; }
.card.tap:active { filter: brightness(1.08); }

.line { font-size: 14px; line-height: 1.4; padding-right: 8px; color: var(--line); overflow-wrap: anywhere; }

/* ---------- ring / dot / chip ---------- */
.tick {
  width: var(--tap); height: var(--tap); flex: none; margin-left: auto;
  display: flex; align-items: center; justify-content: center;
}
.ring {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--ring-border);
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s;
}
.ring.on { background: var(--ok); border-color: var(--ok); color: var(--on-ok); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; line-height: 1; padding: 6px 10px;
  border-radius: 999px; background: var(--chip); color: var(--text-2);
  white-space: nowrap; border: 1px solid transparent;
}
.chip-btn { cursor: pointer; min-height: 32px; padding: 6px 12px; }
.chip.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-text); }
.chip.ok { color: var(--ok-text); }
.chip.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }

/* ---------- headings ---------- */
.h2 {
  margin: 0; font-size: 13px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.h2-row { display: flex; align-items: baseline; gap: 8px; margin-top: 14px; padding: 0 4px; }
.h2-sub { margin-left: auto; font-size: 12px; color: var(--muted); }
.screen > .h2 { margin-top: 14px; padding: 0 4px; }
.label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ---------- inputs / buttons ---------- */
.input {
  display: block; width: 100%; min-height: var(--tap);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-input);
  padding: 10px 12px; color: var(--text); font-size: 15px; line-height: 1.4;
  resize: vertical;
}
.input::placeholder { color: #6E7580; }
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { min-height: 64px; }
input[type="time"].input, input[type="number"].input { font-family: var(--mono); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-2);
  font-size: 15px; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #3A4048; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: #F4B254; border-color: #F4B254; }
.btn-danger { color: var(--danger); }
.btn-danger.armed { background: #3A1E1C; border-color: var(--danger); }
.btn-ghost { background: none; border: 1px dashed var(--ring-border); color: var(--accent); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }
.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 0; cursor: pointer;
}
.icon-btn:disabled { color: var(--ring-border); cursor: default; }

/* ---------- sheet ---------- */
.sheet-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 6, 8, .6); animation: fade .15s ease-out; }
.sheet {
  position: relative; width: 100%; max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(24px + var(--safe-b));
  display: flex; flex-direction: column; gap: 12px;
  animation: sheet-up .18s ease-out;
  outline: none;
  overscroll-behavior: contain;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #3A4048; align-self: center; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-title { margin: 0; font-size: 18px; font-weight: 600; }
.sheet-sub { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); text-transform: uppercase; }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }

@media (min-width: 768px) {
  .sheet-root { align-items: center; padding: 24px; }
  .sheet {
    max-width: 480px; border: 1px solid var(--border); border-radius: 16px;
    padding: 18px 20px 20px; animation: pop .15s ease-out;
  }
  .sheet-handle { display: none; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

/* ---------- list editor ---------- */
.le { gap: 0; padding-top: 4px; padding-bottom: 8px; }
.le-row { display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
.le-row + .le-row { border-top: 1px solid var(--divider); }
.le-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 6px 0; }
.le-text { font-size: 14px; line-height: 1.4; color: var(--line); overflow-wrap: anywhere; }
.le-meta { font-size: 12px; color: var(--muted); }
.le-row.is-done .le-text { text-decoration: line-through; color: var(--strike); }
.le-add { display: flex; gap: 8px; padding: 8px 8px 0 0; }
.le-add .input { flex: 1; min-width: 0; }
.le-add-btn { min-height: var(--tap); }

/* ---------- toast ---------- */
.toast-host {
  position: fixed; left: 0; right: 0; z-index: 60; pointer-events: none;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  display: flex; justify-content: center; padding: 0 16px;
}
.toast {
  pointer-events: auto; max-width: 480px;
  background: #2A2F36; color: var(--text); border: 1px solid #3A4048;
  border-radius: 12px; padding: 12px 16px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  animation: sheet-up .18s ease-out;
}
@media (min-width: 768px) { .toast-host { bottom: 24px; } }

/* ---------- token gate ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.gate-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.gate-logo {
  width: 56px; height: 56px; border-radius: 14px; background: var(--accent); color: var(--bg);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 30px; margin-bottom: 8px;
}
.gate-title { margin-bottom: 14px; }
.gate-error { font-size: 13px; color: var(--danger); }
.gate .btn { margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
