:root {
  --brand: #0f766e;
  --brand-600: #0d9488;
  --brand-700: #115e59;
  --brand-50: #e6f6f4;
  --brand-100: #c7ebe6;
  --accent: #f59e0b;
  --accent-50: #fff7e6;
  --ok: #15803d;
  --ok-50: #e9f8ee;
  --danger: #dc2626;
  --danger-50: #fdecec;
  --ink: #12201d;
  --ink-2: #4b5a57;
  --ink-3: #7b8885;
  --line: #e2e9e7;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --radius: 16px;
  --shadow: 0 8px 24px -14px rgba(15, 50, 45, .35);
  --nav-h: 68px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Hind Siliguri', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }

/* ---------- brand ---------- */
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; }
.logo-mark { width: 34px; height: 34px; border-radius: 11px; background: var(--brand); display: grid; place-items: center; flex-shrink: 0; }
.logo-mark::after { content: ''; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 9px var(--accent); }
.logo-mark.big { width: 56px; height: 56px; border-radius: 16px; animation: pulse 1.2s ease-in-out infinite; }
.logo-mark.big::after { width: 26px; height: 26px; box-shadow: inset 0 0 0 6px #fff, inset 0 0 0 14px var(--accent); }
@keyframes pulse { 50% { transform: scale(1.08); } }
.boot { min-height: 100vh; display: grid; place-items: center; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 600; font-size: 16px; transition: transform .1s, background .15s, opacity .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 8px 18px -10px rgba(15, 118, 110, .9); }
.btn-primary:hover { background: var(--brand-700); }
.btn-ghost { background: var(--surface); border-color: var(--line); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-danger-text { background: none; border: 0; color: var(--danger); font-weight: 600; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; font-size: 20px; line-height: 1; transition: transform .1s, background .15s; }
.icon-btn:active { transform: scale(.93); }
.icon-btn:disabled { opacity: .4; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 15px; }
.input, .select { width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus, .select:focus { border-color: var(--brand-600); box-shadow: 0 0 0 4px var(--brand-50); }
.hint { font-size: 13px; color: var(--ink-3); }
.error { background: var(--danger-50); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 15px; }

/* ---------- sign in ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(600px 300px at 50% -60px, var(--brand-100), transparent 70%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 22px; padding: 28px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 18px; }
.auth-card .logo { justify-content: center; font-size: 24px; }
.auth-card .tagline { text-align: center; color: var(--ink-2); margin-top: -8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--ink-2); }
.seg button.active { background: var(--surface); color: var(--brand-700); box-shadow: 0 2px 6px -2px rgba(15, 50, 45, .3); }

/* ---------- app shell ---------- */
.shell { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.top { position: sticky; top: 0; z-index: 10; background: rgba(244, 247, 246, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 12px 16px 10px; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.month { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.month strong { font-size: 17px; }
.month .icon-btn { border: 0; background: var(--bg); }
.content { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { font-size: 18px; margin-bottom: 4px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* bottom navigation */
.nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.nav-in { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.nav button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 12px; color: var(--ink-3); font-weight: 600; font-size: 13px; }
.nav button svg { width: 24px; height: 24px; }
.nav button.active { color: var(--brand); background: var(--brand-50); }

/* ---------- summary ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat small { display: block; color: var(--ink-3); font-weight: 600; font-size: 13px; }
.stat b { display: block; font-size: 24px; line-height: 1.25; margin-top: 2px; }
.stat.rate { grid-column: 1 / -1; background: linear-gradient(135deg, var(--brand), var(--brand-700)); color: #fff; border: 0; box-shadow: var(--shadow); }
.stat.rate small { color: rgba(255, 255, 255, .8); }
.stat.rate b { font-size: 34px; }
.stat.rate .formula { font-size: 14px; color: rgba(255, 255, 255, .85); margin-top: 4px; }
.person { display: flex; flex-direction: column; gap: 10px; }
.person-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.person-head b { font-size: 17px; }
.person-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.person-grid div { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.person-grid small { display: block; color: var(--ink-3); font-size: 12.5px; font-weight: 600; }
.person-grid span { font-weight: 700; font-size: 16px; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.pill.get { background: var(--ok-50); color: var(--ok); }
.pill.give { background: var(--danger-50); color: var(--danger); }
.pill.even { background: var(--bg); color: var(--ink-2); }
.howto { background: var(--accent-50); border: 1px solid #fde7b0; border-radius: var(--radius); padding: 14px 16px; }
.howto summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::after { content: '＋'; color: var(--accent); }
.howto[open] summary::after { content: '－'; }
.howto ol { margin: 10px 0 0 20px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }

/* ---------- meals ---------- */
.day { display: flex; align-items: center; gap: 8px; }
.day .input { text-align: center; font-weight: 600; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick button { flex: 1; min-width: 70px; height: 40px; border-radius: 10px; border: 1.5px dashed var(--brand-100); background: var(--brand-50); color: var(--brand-700); font-weight: 600; font-size: 14px; }
.meal-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.meal-row:last-child { border-bottom: 0; }
.meal-row .name { font-weight: 600; font-size: 16.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--brand-50); color: var(--brand-700); font-size: 24px; font-weight: 700; line-height: 1; }
.stepper button:active { transform: scale(.92); }
.stepper button:disabled { opacity: .35; }
.stepper output { min-width: 44px; text-align: center; font-size: 20px; font-weight: 700; }
.day-total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 10px; border-top: 2px solid var(--line); margin-top: 4px; }
.saved { font-size: 13px; color: var(--ok); font-weight: 600; min-height: 18px; text-align: right; }

/* ---------- bazar & members ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .main b { display: block; font-size: 16px; }
.list-row .main small { color: var(--ink-3); font-size: 13.5px; }
.amount { font-weight: 700; font-size: 17px; white-space: nowrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; font-size: 16px; }
.empty { text-align: center; padding: 28px 16px; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .emoji { font-size: 40px; }

/* ---------- own vs others ---------- */
.you { display: inline-block; vertical-align: middle; margin-left: 4px; padding: 1px 8px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 700; }
.card.mine { border: 2px solid var(--brand-600); box-shadow: 0 8px 20px -14px rgba(15, 118, 110, .7); }
.mess-name { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-name { max-width: 28vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.link { border: 0; background: none; padding: 0; color: var(--brand-700); text-decoration: underline dotted; text-underline-offset: 3px; }
.mine-card { border: 2px solid var(--brand-600); background: linear-gradient(180deg, var(--brand-50), var(--surface) 60%); display: flex; flex-direction: column; gap: 14px; }
.big-stepper { display: flex; align-items: center; justify-content: center; gap: 22px; }
.big-stepper button { width: 64px; height: 64px; border-radius: 18px; border: 0; background: var(--brand); color: #fff; font-size: 34px; font-weight: 700; line-height: 1; box-shadow: 0 10px 20px -12px rgba(15, 118, 110, .9); }
.big-stepper button:active { transform: scale(.92); }
.big-stepper button:disabled { opacity: .35; }
.big-stepper output { min-width: 80px; text-align: center; font-size: 44px; font-weight: 700; color: var(--brand-700); }
.quick button.on { background: var(--brand); color: #fff; border-style: solid; border-color: var(--brand); }
.meal-row b { font-size: 18px; }
.me-row { background: var(--brand-50); margin: 0 -16px; padding: 10px 16px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat.rate { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
