@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;600;700;800&family=Varela+Round&display=swap');

:root {
  --bg: #f8fafc;
  --fg: #0f172a;
  --card: #ffffff;
  --muted: #475569;
  --soft: #f0f8f6;
  --line: #e1f2ed;
  --primary: #059669;
  --on-primary: #000000;
  --danger: #dc2626;
  --good: #047857;
  --ring: #059669;
  --shadow: none;
  --top: 0;
  --tab: 0;
  --sheet: 30;
  --modal: 40;
  --coach: 50;
  --toast: 60;
  color-scheme: light;
  font-family: 'Nunito Sans', sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --fg: #f8fafc;
    --card: #111827;
    --muted: #cbd5e1;
    --soft: #13261f;
    --line: #1f3a34;
    --primary: #34d399;
    --on-primary: #000000;
    --danger: #f87171;
    --good: #6ee7b7;
    --ring: #34d399;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); }
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: transparent; }
button:disabled { cursor: default; opacity: 0.45; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
.phone {
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--bg);
}
.top h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: 'Varela Round', sans-serif;
  font-size: 22px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  position: relative;
  flex: 0 0 44px;
}
.icon-btn:active { background: var(--soft); }
.icon-btn svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.75; }
.dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}
.avatar-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--soft);
  font-size: 20px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
}
.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
  z-index: var(--tab);
}
.tabbar button {
  min-height: 48px;
  border-radius: 12px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.tabbar button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.75; }
.tabbar button[aria-current='page'] { color: var(--fg); background: var(--soft); }
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--soft);
  border-radius: 12px;
  margin-bottom: 14px;
}
.seg button { min-height: 40px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed='true'] { background: var(--card); color: var(--fg); }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 10px;
}
.row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  min-height: 64px;
  padding: 8px 0;
}
.row + .row { border-top: 1px solid var(--line); }
.grow { flex: 1; min-width: 0; }
.grow strong, .grow small { display: block; }
.grow small, .muted { color: var(--muted); font-size: 13px; }
.money { font-variant-numeric: tabular-nums; font-weight: 800; }
.good { color: var(--good); }
.owe { color: var(--danger); }
.primary, .secondary, .danger {
  min-height: 48px;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary { background: var(--primary); color: var(--on-primary); width: 100%; }
.primary:active { filter: brightness(0.92); }
.secondary { background: var(--card); border: 1px solid var(--line); }
.danger { background: transparent; color: var(--danger); }
.fab {
  position: sticky;
  bottom: 8px;
  margin-top: 12px;
}
h2 {
  font-family: 'Varela Round', sans-serif;
  font-size: 20px;
  font-weight: 400;
  margin: 0 0 8px;
}
.field { display: grid; gap: 6px; margin: 12px 0; }
.field label { font-size: 13px; font-weight: 700; }
.field input, .field select {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 0 12px;
}
.err { color: var(--danger); font-size: 13px; font-weight: 700; }
.sheet, .auth, .boot, .coach {
  position: fixed;
  inset: 0;
  z-index: var(--sheet);
  background: color-mix(in srgb, var(--fg) 45%, transparent);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.auth, .boot { align-items: stretch; background: var(--bg); z-index: var(--modal); overflow-y: auto; touch-action: pan-y; }
.boot { place-items: center; display: grid; }
.panel {
  width: min(430px, 100%);
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: min(88dvh, 720px);
  overflow-y: auto;
  touch-action: pan-y;
}
.auth-card { width: min(430px, 100%); margin: auto; padding: 24px 16px 32px; }
.brand { font-family: 'Varela Round', sans-serif; font-size: 28px; margin-bottom: 8px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions > * { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 700;
}
.chip[aria-pressed='true'] { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.qr { width: min(220px, 70vw); margin: 8px auto; display: block; background: #fff; border-radius: 12px; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.emoji-grid button { min-height: 44px; font-size: 22px; border-radius: 10px; }
.emoji-grid button[aria-pressed='true'] { background: var(--soft); }
.guest { font-size: 12px; font-weight: 800; color: var(--muted); }
.coach { align-items: center; padding: 16px; z-index: var(--coach); }
.coach-card { width: min(360px, 100%); background: var(--card); border-radius: 20px; padding: 18px; }
.scene {
  height: 140px;
  border-radius: 16px;
  background: var(--soft);
  margin-bottom: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.scene b {
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--primary);
}
@media (prefers-reduced-motion: no-preference) {
  .scene b { animation: pulse 1.4s ease-in-out infinite; }
}
@keyframes pulse {
  50% { transform: translateY(-8px); }
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  z-index: var(--toast);
  max-width: min(360px, calc(100% - 32px));
}
.empty { text-align: center; padding: 28px 8px; }
.empty p { color: var(--muted); }
.item { touch-action: pan-y; }
