:root {
  --bg: #f4f6f7;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #6b7684;
  --primary: #2A9D8F;
  --primary-light: #e3f5f2;
  --primary-dark: #1c7a6d;
  --accent: #F4A261;
  --danger: #e63946;
  --warning-bg: #fff4e5;
  --warning-text: #8a5a00;
  --border: #e5e9ec;
  --radius: 18px;
  --shadow: 0 2px 12px rgba(20, 30, 40, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --card: #1a222b;
    --text: #edf1f4;
    --muted: #93a2b0;
    --primary: #3bc4b2;
    --primary-light: #163430;
    --primary-dark: #2ba897;
    --accent: #f6ab6e;
    --danger: #ff6b6f;
    --warning-bg: #3a2c12;
    --warning-text: #f2c879;
    --border: #2a333d;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.hero {
  text-align: center;
  padding: 32px 20px;
  margin-bottom: 8px;
  border-radius: 24px;
  background: radial-gradient(circle at 25% 20%, var(--primary-light), transparent 65%),
              radial-gradient(circle at 80% 0%, rgba(244, 162, 97, 0.15), transparent 55%);
}
.hero-emoji { font-size: 52px; line-height: 1; animation: float 3s ease-in-out infinite; }
.hero h1 { margin: 10px 0 6px; font-size: 1.7rem; letter-spacing: -0.02em; }
.hero-sub { color: var(--muted); font-size: 0.95rem; margin: 0; line-height: 1.45; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: background .2s ease, box-shadow .2s ease;
}
.card.center { text-align: center; }
.card h2 { margin-top: 0; font-size: 1.1rem; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all .15s ease;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.field input, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--card);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.upload-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; border: 2px dashed var(--border); border-radius: 16px;
  padding: 36px 16px; cursor: pointer; color: var(--muted); text-align: center;
  transition: border-color .15s ease, background .15s ease; margin-bottom: 14px;
}
.upload-box:active { border-color: var(--primary); background: var(--primary-light); }
.upload-icon { font-size: 2.2rem; }
.upload-text { font-weight: 600; color: var(--text); }
.upload-hint { font-size: 0.82rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.photo-preview { margin: 10px 0 14px; border-radius: 12px; overflow: hidden; }
.photo-preview img { width: 100%; display: block; border-radius: 12px; margin-bottom: 8px; }

.btn-primary, .btn-ghost, .btn-danger {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: transform .1s ease, background .15s ease, opacity .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(42, 157, 143, 0.3); }
.btn-primary:active { background: var(--primary-dark); transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); width: auto; padding: 10px 16px; }
.btn-ghost:active { background: var(--primary-light); transform: scale(0.98); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:active { transform: scale(0.98); }

.error {
  color: var(--danger);
  background: var(--warning-bg);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.footer-note { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 20px; }
.support-note a { color: var(--primary); }

.manual-item-row {
  display: grid;
  grid-template-columns: 1fr 90px 60px auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.manual-item-row input { padding: 10px; border-radius: 10px; border: 1px solid var(--border); width: 100%; background: var(--card); color: var(--text); }
.remove-item-btn { background: none; border: none; color: var(--danger); font-size: 1.2rem; cursor: pointer; }

.bill-header { text-align: center; padding: 12px 0 4px; }
.bill-header h1 { margin: 0 0 4px; font-size: 1.4rem; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0; }
.header-actions { display: flex; justify-content: center; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.badge-closed {
  background: var(--bg); color: var(--muted); font-size: 0.8rem; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
}

.me-card {
  background: var(--primary-light); border: 1px solid var(--primary);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 16px; font-size: 0.9rem;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }

.avatar-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.avatar-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--border);
  padding: 5px 12px 5px 5px; border-radius: 999px; font-size: 0.8rem; box-shadow: var(--shadow);
}
.avatar-circle {
  width: 24px; height: 24px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.68rem; flex-shrink: 0;
}

.progress-wrap { margin: 4px 0 18px; }
.progress-track { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .45s ease;
}
.progress-label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-top: 6px; }

.items-list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 10px; border-radius: 12px; margin-bottom: 8px; background: var(--bg);
  cursor: pointer; border: 2px solid transparent;
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.item-row:active { transform: scale(0.98); }
.item-row.mine { border-color: var(--primary); background: var(--primary-light); }
.item-row.fully-claimed:not(.mine) { opacity: 0.75; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 500; }
.item-meta { font-size: 0.8rem; color: var(--muted); }
.item-price { font-weight: 600; white-space: nowrap; margin-left: 10px; }
.item-claimers { display: flex; gap: 4px; margin-left: 10px; }
.claimer-dot {
  width: 20px; height: 20px; border-radius: 50%; color: #fff; font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  border: 2px solid var(--card); margin-left: -6px;
}

.warning { background: var(--warning-bg); color: var(--warning-text); }

.summary-list { list-style: none; margin: 0; padding: 0; }
.summary-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.summary-row:last-child { border-bottom: none; }
.summary-row.mine { font-weight: 700; }
.summary-name { display: flex; align-items: center; gap: 8px; }
.grand-total { text-align: right; margin: 10px 0 0; }

.payment-info { font-size: 1.1rem; font-weight: 600; background: var(--bg); padding: 10px 14px; border-radius: 10px; }

.all-done-badge {
  text-align: center; font-size: 0.85rem; color: var(--primary); font-weight: 600;
  margin: -6px 0 16px;
}

.qr-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.qr-modal {
  background: var(--card); border-radius: var(--radius); padding: 24px;
  text-align: center; max-width: 320px; width: 100%;
}
.qr-modal img { width: 100%; max-width: 260px; height: auto; border-radius: 8px; background: #fff; padding: 8px; }
.qr-modal .btn-ghost { margin-top: 12px; }

.pwa-hint {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 40;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 14px 16px;
  font-size: 0.85rem; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.pwa-hint button {
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  padding: 8px 12px; font-size: 0.85rem; white-space: nowrap; cursor: pointer;
}
.pwa-hint .pwa-hint-close {
  background: transparent; color: var(--muted); font-size: 1.1rem; padding: 0 4px;
}

.toast-container {
  position: fixed; top: 14px; left: 12px; right: 12px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 0.85rem; box-shadow: var(--shadow); max-width: 90%;
  animation: toast-in .25s ease, toast-out .3s ease 2.4s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

.confetti-piece {
  position: fixed; top: -12px; width: 8px; height: 14px; z-index: 70;
  opacity: 0.9; animation: confetti-fall 2.3s linear forwards; pointer-events: none;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(560deg); opacity: 0; }
}

@media (max-width: 360px) {
  .manual-item-row { grid-template-columns: 1fr 70px 50px auto; }
}
