:root {
  /* Colors - Modern Clean Palette */
  --primary: #2f6df6;
  --primary-dark: #1a54d4;
  --bg-body: #f7f8fa;
  --bg-card: #ffffff;
  
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  
  --border: #e5e7eb;
  --border-focus: rgba(47, 109, 246, 0.4);
  
  /* Brand Colors */
  --c-red: #ef4444;
  --c-silver: #64748b;
  --c-gold: #d97706;
  --c-black: #1f2937;
  --c-yellow: #fbbf24;
  --c-green: #10b981;
  
  /* Dimensions */
  --header-h: 60px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  
  /* Spacing */
  --gap: 16px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-float: 0 10px 15px -3px rgba(0,0,0,0.08);
}

/* Reset & Base */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  height: 100%;
  font-family: 'Inter', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}

button { font-family: inherit; border: none; cursor: pointer; user-select: none; padding: 0; background: none; }
button:active { transform: scale(0.97); transition: transform 0.1s; }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.wrap {
  width: 100%;
  max-width: 480px; /* Mobile focused max-width */
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(247, 248, 250, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}

.header-content {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 10px; }
.app-icon { font-size: 22px; }
.title { font-size: 18px; font-weight: 800; margin: 0; letter-spacing: -0.02em; }

.header-actions { display: flex; gap: 8px; }
.action-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 99px;
  background: white;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.action-btn.icon-only { width: 36px; padding: 0; color: var(--text-muted); }

/* --- Main Layout --- */
.main {
  /* Dynamic padding calculated via JS, fallback provided */
  padding-top: 16px;
  padding-bottom: calc(var(--bottom-h, 200px) + 20px);
}

/* --- Plate Grid --- */
.plate-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.plate-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 12px 16px 12px 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
  border: 1px solid white;
}

.plate-visual {
  width: 70px;
  height: 70px;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.plate-img {
  width: 110%; /* Slight overlap look */
  height: 110%;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.12));
}

.plate-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.plate-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.plate-name { font-size: 17px; font-weight: 700; }
.name-red { color: var(--c-red); }
.name-silver { color: var(--c-silver); }
.name-gold { color: var(--c-gold); }
.name-black { color: var(--c-black); }

.plate-price {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 6px;
}

.counter-row {
  display: flex;
  align-items: center;
  justify-content: flex-end; /* Align right */
  gap: 12px;
}
.ctr-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: #f3f4f6;
  color: var(--primary);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctr-btn.plus { background: var(--primary); color: white; box-shadow: 0 2px 5px rgba(47, 109, 246, 0.3); }
.ctr-val {
  font-size: 20px;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ctr-val.zero { color: var(--border); }

/* --- Extras Section --- */
.section { margin-top: 32px; }
.section-header h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 12px 4px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.chip {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  transition: all 0.1s;
}
.chip:active { background: #f9fafb; border-color: var(--primary); color: var(--primary); }

.custom-trigger-row { margin-bottom: 16px; }
.custom-input-btn {
  width: 100%;
  background: white;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-weight: 600;
}
.custom-input-btn:active { background: #f9fafb; border-color: var(--text-light); }
.icon-plus { font-size: 18px; font-weight: 700; }

/* Extra Items List */
.extra-list { display: flex; flex-direction: column; gap: 10px; }
.extra-item {
  background: white;
  padding: 8px 8px 8px 16px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.extra-price { font-weight: 700; font-size: 16px; color: var(--text-main); }
.extra-actions { display: flex; align-items: center; gap: 12px; }
.remove-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 18px;
}

/* --- Bottom Sticky Bar --- */
.bottom-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  /* Glassmorphism background */
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(0,0,0,0.06);
  padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
  padding-top: 8px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.04);
}

/* Timer Area (Floating pill above footer logic) */
.timer-area { margin-bottom: 12px; }

.timer-start-btn {
  width: 100%;
  background: #eef2ff;
  color: var(--primary);
  font-weight: 600;
  padding: 10px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.timer-active-bar {
  background: var(--text-main);
  border-radius: 40px;
  color: white;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.timer-left { display: flex; flex-direction: column; gap: 2px; }
.timer-label { font-size: 10px; text-transform: uppercase; color: #9ca3af; letter-spacing: 0.5px; }
.timer-val { font-family: monospace; font-size: 16px; font-weight: 700; letter-spacing: -0.5px; }
.timer-val.danger { color: var(--c-red); }

.timer-controls { display: flex; gap: 8px; }
.t-btn {
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 600;
}

/* Summary Panel */
.summary-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
}

.sum-main { display: flex; flex-direction: column; }
.sum-label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 2px; }

/* Updated .sum-amount to align per-person tag */
.sum-amount { 
  font-size: 32px; 
  font-weight: 800; 
  line-height: 1; 
  letter-spacing: -1px; 
  color: var(--text-main);
  display: flex;
  align-items: baseline; /* Aligns the small text with the big number */
  gap: 6px;
}
.currency { font-size: 20px; vertical-align: top; margin-right: 2px; font-weight: 600; }

/* New Per Person Tag next to Total */
.avg-price-tag {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-light);
  letter-spacing: -0.01em;
}

.sum-details { margin-top: 4px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.detail-sep { margin: 0 4px; opacity: 0.5; }

.sum-actions { display: flex; align-items: center; }

.split-control {
  background: #f3f4f6;
  border-radius: 16px;
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.split-btn {
  width: 36px;
  height: 36px;
  background: white;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.split-info { text-align: center; min-width: 60px; }
.split-count { font-size: 13px; font-weight: 700; color: var(--text-main); }
.split-avg { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

/* Footer Credit */
.credit-footer {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-top: 32px;
  opacity: 0.6;
}

/* --- Modal --- */
.modal { position: fixed; inset: 0; z-index: 200; display: none; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); }

.modal-sheet {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-body);
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.modal-value-display { font-size: 36px; font-weight: 800; color: var(--text-main); letter-spacing: -1px; }
.modal-close-btn { width: 36px; height: 36px; background: #e5e7eb; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-main); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.key {
  background: white;
  padding: 16px 0;
  border-radius: 12px;
  font-size: 24px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.key-sec { background: transparent; box-shadow: none; color: var(--c-red); }
.key-primary { background: var(--primary); color: white; font-size: 18px; font-weight: 700; }

/* Media Queries for very small screens */
@media (max-width: 360px) {
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .sum-amount { font-size: 26px; }
}

/* --- Auth / User Profile Styles --- */
.auth-section {
  display: flex;
  align-items: center;
}

.login-btn {
  background: var(--c-black);
  color: white;
  border: none;
}

/* --- Updated User Profile to be Icon Only --- */
.user-profile {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: white;
  padding: 0;
  width: 36px; /* Matches action-btn icon-only width */
  height: 36px;
  border-radius: 50%; /* Perfect circle */
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  overflow: hidden;
}

.user-name {
  display: none; /* Hide name */
}

.user-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}