:root {
  --bg: #f6f1ea;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #eadfd2;
  --accent: #ea580c;
  --accent-ink: #ffffff;
  --good: #166534;
  --good-bg: #dcfce7;
  --wait: #1d4ed8;
  --wait-bg: #dbeafe;
  --warn: #9a3412;
  --warn-bg: #ffedd5;
  --bad: #9f1239;
  --bad-bg: #ffe4e6;
  --shadow: 0 12px 30px rgba(88, 48, 12, 0.08);
  --radius: 22px;
  --shell: 100%;
  --tap: 48px;
  color-scheme: light;
  font-family: Nunito, "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 16.5px;
  line-height: 1.4;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.tile, .key, .tab, .chip, .icon-btn { user-select: none; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

.shell {
  width: min(100%, var(--shell));
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(900px 420px at 10% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    var(--bg);
}
.shell.simple { --tap: 58px; font-size: 18px; }

.stage, .main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.stage {
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  padding-top: calc(16px + env(safe-area-inset-top));
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: 1.15rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 800; }
.lede, .muted, .meta { color: var(--muted); }
.lede { margin-top: 6px; }
.eyebrow {
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--accent);
  margin-bottom: 6px;
}
.section { margin: 18px 0 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grow { flex: 1; }

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 22px;
}
.tile {
  position: relative;
  min-height: 168px;
  border: 0;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
}
.tile:focus-visible, .btn:focus-visible, .key:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .chip:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.tile .avatar {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 40px;
  background: color-mix(in srgb, var(--c, var(--accent)) 18%, white);
  box-shadow: inset 0 0 0 3px var(--c, var(--accent));
  margin-bottom: 6px;
}
.tile-name { font-weight: 800; font-size: 1.25rem; }
.tile-sub { color: var(--muted); font-size: 0.92rem; }
.tile-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.72rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 3px 8px;
}

.dots { display: flex; gap: 14px; justify-content: center; margin: 22px 0 8px; }
.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 55%, #d6d3d1);
  background: transparent;
}
.dot.on { background: var(--accent); border-color: var(--accent); }
.shake { animation: shake 0.4s linear; }
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
.pin-error {
  min-height: 2.6em;
  text-align: center;
  color: var(--bad);
  font-weight: 700;
  margin: 8px 0 0;
}
.lock-clock { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--warn); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(100%, 340px);
  margin: 16px auto 0;
}
.key {
  height: 72px;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 4px 0 #e7d9c8;
  font-size: 1.7rem;
  font-weight: 800;
}
.shell.simple .key { height: 84px; font-size: 2rem; }
.key:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #e7d9c8; }
.key:disabled { opacity: 0.45; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-weight: 800; font-size: 1.15rem; }
.who-sub { color: var(--muted); font-size: 0.85rem; }
.avatar.sm {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 24px;
  flex: none;
}
.header-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn, .text-btn {
  border: 0;
  background: transparent;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: 14px;
}
.icon-btn { position: relative; font-size: 1.35rem; }
.text-btn { font-weight: 800; color: var(--accent); padding: 0 8px; }
.badge {
  position: absolute;
  top: 4px;
  right: 2px;
  background: var(--bad);
  color: white;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  font-size: 0.68rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

.hero {
  background: var(--surface);
  background-image: linear-gradient(165deg, color-mix(in srgb, var(--accent) 18%, white), #fff 68%);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}
.hero-points {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.shell.simple .hero-points { font-size: 3rem; }
.hero-money { font-size: 1.35rem; font-weight: 800; margin-top: 4px; }
.hero-sub { color: var(--muted); margin-top: 4px; font-weight: 700; }
.strip {
  background: var(--surface);
  border-radius: 16px;
  padding: 10px 14px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card.lapsed { background: #f3f1ee; color: #57534e; box-shadow: none; }
.card.lapsed .pill.missed { filter: none; }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.desc { margin-top: 6px; white-space: pre-wrap; }
.meta { font-size: 0.92rem; margin-top: 4px; font-weight: 700; }
.note {
  margin-top: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 700;
}
.card .row { margin-top: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 800;
  background: #f5f5f4;
  color: #44403c;
  flex: none;
}
.pill.open { background: #ffedd5; color: #9a3412; }
.pill.wait { background: var(--wait-bg); color: var(--wait); }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.missed { background: #e7e5e4; color: #57534e; }

.btn {
  min-height: var(--tap);
  border-radius: 16px;
  border: 0;
  padding: 10px 14px;
  font-weight: 800;
  background: var(--accent);
  color: var(--accent-ink);
}
.btn.secondary { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--bad); color: white; }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.55; }

.chip {
  min-height: 44px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  padding: 6px 12px;
  font-weight: 800;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.shell.simple .chip { min-height: 52px; font-size: 1.05rem; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; margin-top: 12px; }
.field span { font-size: 0.92rem; }
input, textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  font-size: 16px;
  font-weight: 700;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 45%, white); border-color: var(--accent); }
.mask { -webkit-text-security: disc; }
.form-error { color: var(--bad); font-weight: 800; min-height: 1.2em; margin-top: 8px; }
.hint { color: var(--muted); font-weight: 700; font-size: 0.92rem; margin-top: 6px; }

.bar {
  height: 12px;
  background: #f1ebe4;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: inherit; }

.tabbar {
  display: flex;
  position: sticky;
  bottom: 0;
  background: rgba(255, 252, 248, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  z-index: 6;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  min-height: 56px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.72rem;
  position: relative;
}
.tab-icon { font-size: 1.2rem; line-height: 1; }
.tab.on { background: var(--accent); color: var(--accent-ink); }
.tab-count {
  position: absolute;
  top: 4px;
  right: calc(50% - 28px);
  background: var(--bad);
  color: white;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  font-size: 0.65rem;
  display: grid;
  place-items: center;
}
.tab.on .tab-count { background: white; color: var(--bad); }

.empty, .loading {
  text-align: center;
  padding: 28px 10px;
  color: var(--muted);
  font-weight: 700;
}
.empty-emoji { font-size: 2.4rem; margin-bottom: 6px; }
.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 8px;
  border-radius: 50%;
  border: 4px solid #f1e4d4;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(100%, var(--shell));
  max-height: min(92dvh, 820px);
  overflow: auto;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
}
.grab {
  width: 46px;
  height: 5px;
  border-radius: 99px;
  background: #e7d9c8;
  margin: 2px auto 10px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.preview { width: 100%; border-radius: 16px; margin-top: 10px; max-height: 280px; object-fit: cover; }
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.notif { 
  width: 100%;
  text-align: left;
  display: flex;
  gap: 10px;
  border: 0;
  background: var(--surface);
  border-radius: 16px;
  padding: 12px;
  margin-top: 8px;
}
.notif.unread { box-shadow: inset 4px 0 0 var(--accent); }
.notif-icon { font-size: 1.4rem; }
.notif-title, .notif-body { display: block; }
.notif-title { font-weight: 800; }
.notif-body { color: var(--muted); font-weight: 700; }

.ledger {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  list-style: none;
}
.ledger-icon { font-size: 1.3rem; width: 1.6rem; text-align: center; }
.ledger-note { font-weight: 800; }
.ledger-amt { margin-left: auto; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.ledger-amt.pos { color: var(--good); }
.ledger-amt.neg { color: var(--bad); }
.list { list-style: none; margin: 8px 0 0; padding: 0; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(72px + env(safe-area-inset-top));
  transform: translateX(-50%);
  width: min(92%, 420px);
  background: #1c1917;
  color: white;
  padding: 12px 14px;
  border-radius: 16px;
  font-weight: 800;
  z-index: 35;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(28, 25, 23, 0.18);
}
.toast.in-flow {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  width: 100%;
  margin: 0 0 12px;
  z-index: 1;
}
.toast.bad { background: #9f1239; }
.busy-flag {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 12px;
  z-index: 40;
}

.link { color: var(--accent); font-weight: 800; }

@media (min-width: 700px) {
  :root { --shell: 820px; }
  .tiles { gap: 16px; }
  .tile { min-height: 210px; }
  .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
}
@media (min-width: 1100px) {
  body { background: #e6d9c8; }
  .shell {
    height: 100dvh;
    box-shadow: 0 0 0 1px rgba(80, 40, 10, 0.05), 0 24px 60px rgba(80, 40, 10, 0.12);
  }
}
@media (prefers-reduced-motion: reduce) {
  .shake, .spinner { animation: none; }
}
