:root {
  --color-bg: #FFF8EE;
  --color-surface: #FFFFFF;
  --color-text: #3B2A1E;
  --color-text-muted: #8a7360;
  --color-primary: #E08E2B;
  --color-primary-dark: #C97319;
  --color-primary-contrast: #FFFFFF;
  --color-danger: #C0392B;
  --color-border: #F0E4D3;
  --color-success-bg: #E7F6EC;
  --color-success-text: #1E7B34;
  --color-error-bg: #FBEAEA;
  --color-error-text: #B23A3A;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(59, 42, 30, 0.08);
  --nav-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 17px; }
p { line-height: 1.4; }
a { color: var(--color-primary-dark); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-title { font-weight: 700; font-size: 18px; }

.install-btn {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.content {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 24px);
}

.is-guest .content { padding-bottom: 24px; }

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.link-more { font-size: 13px; text-decoration: none; font-weight: 600; }

.flash {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 14px;
}
.flash-success { background: var(--color-success-bg); color: var(--color-success-text); }
.flash-error { background: var(--color-error-bg); color: var(--color-error-text); }

.empty-state { color: var(--color-text-muted); font-size: 14px; }
.hint { color: var(--color-text-muted); font-size: 12.5px; margin-top: 8px; }

/* Dashboard */
.today-card h2 { margin-bottom: 14px; }
.today-summary { display: flex; gap: 12px; }
.today-figure {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
}
.today-figure strong { font-size: 26px; }
.today-figure span { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

.quick-add-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.btn-quick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 14px 6px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.btn-quick:active { transform: scale(0.96); border-color: var(--color-primary); }
.btn-quick.is-loading { opacity: 0.6; pointer-events: none; }
.btn-quick-emoji { font-size: 26px; }
.btn-quick-label { font-size: 12.5px; font-weight: 600; }

/* Buttons */
.btn {
  display: inline-block;
  text-align: center;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-primary { background: var(--color-primary); color: var(--color-primary-contrast); }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-danger { background: var(--color-error-bg); color: var(--color-error-text); }

/* Entries */
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  gap: 10px;
}
.entry-item:last-child { border-bottom: none; }
.entry-item-link { padding: 0; }
.entry-main-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 0;
  text-decoration: none;
  color: inherit;
  gap: 10px;
}
.entry-main { display: flex; flex-direction: column; min-width: 0; }
.entry-label { font-weight: 600; font-size: 14.5px; }
.entry-meta { font-size: 12.5px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-side { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.entry-units { font-weight: 700; font-size: 14px; }
.entry-date { font-size: 11.5px; color: var(--color-text-muted); }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 8px; }
.pagination .btn { padding: 8px 12px; font-size: 13px; }
.pagination-info { font-size: 12.5px; color: var(--color-text-muted); }

/* Forms */
.stacked-form { display: flex; flex-direction: column; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13.5px; font-weight: 600; }
.field small { font-weight: 400; color: var(--color-text-muted); }
.field input, .field select {
  font-family: inherit;
  font-size: 16px;
  font-weight: 400;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.switch-field { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.switch-field input { width: 20px; height: 20px; }

/* Auth pages */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 32px); }
.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
  width: 100%;
  text-align: center;
}
.auth-logo { font-size: 40px; margin-bottom: 4px; }
.auth-subtitle { color: var(--color-text-muted); font-size: 13.5px; margin-bottom: 18px; }
.auth-form { text-align: left; }
.auth-switch { margin-top: 16px; font-size: 13.5px; color: var(--color-text-muted); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-tile {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
}
.stat-tile strong { display: block; font-size: 20px; }
.stat-tile span { font-size: 12px; color: var(--color-text-muted); }

#monthlyChart { display: block; width: 100%; }

.type-breakdown { list-style: none; margin: 0; padding: 0; }
.type-breakdown li { margin-bottom: 14px; }
.type-breakdown li:last-child { margin-bottom: 0; }
.type-breakdown-header { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 6px; }
.progress-bar { background: var(--color-bg); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar-fill { background: var(--color-primary); height: 100%; border-radius: 999px; }

/* Leaderboard */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab {
  flex: 1;
  text-align: center;
  padding: 9px 6px;
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.tab.active { background: var(--color-primary); color: var(--color-primary-contrast); }

.leaderboard-list { list-style: none; margin: 0; padding: 0; }
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--color-border);
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row.is-me { background: var(--color-bg); border-radius: var(--radius-sm); padding-left: 8px; padding-right: 8px; }
.leaderboard-rank { width: 30px; font-weight: 700; color: var(--color-text-muted); }
.leaderboard-name { flex: 1; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.leaderboard-units { font-weight: 700; }

.badge {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-border);
  padding: 2px 8px;
  border-radius: 999px;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 0 8px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 10.5px;
  font-weight: 600;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--color-primary-dark); }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--color-text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
  white-space: nowrap;
}
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 540px) {
  .content { max-width: 560px; }
  .bottom-nav { max-width: 560px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--color-border); border-right: 1px solid var(--color-border); border-radius: var(--radius) var(--radius) 0 0; }
}
