*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --good:        #16a34a;
  --good-light:  #22c55e;
  --good-bg:     #f0fdf4;
  --good-border: #86efac;
  --bad:         #dc2626;
  --bad-light:   #ef4444;
  --bad-bg:      #fef2f2;
  --bad-border:  #fca5a5;
  --water:       #1d4ed8;
  --water-bg:    #eff6ff;
  --water-border:#93c5fd;
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --text:        #0f172a;
  --text-muted:  #475569;
  --border:      #cbd5e1;
  --radius:      14px;
  --shadow:      0 1px 4px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --good:        #4ade80;
    --good-light:  #86efac;
    --good-bg:     #052e16;
    --good-border: #166534;
    --bad:         #f87171;
    --bad-light:   #fca5a5;
    --bad-bg:      #450a0a;
    --bad-border:  #7f1d1d;
    --water:       #60a5fa;
    --water-bg:    #172554;
    --water-border:#1e40af;
    --bg:          #0f172a;
    --surface:     #1e293b;
    --text:        #f1f5f9;
    --text-muted:  #94a3b8;
    --border:      #334155;
    --shadow:      0 1px 4px rgba(0,0,0,0.4);
  }
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ─── Login ─────────────────────────────────────── */

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 40px 28px;
  text-align: center;
}

.login-icon { font-size: 52px; margin-bottom: 12px; line-height: 1; }

.login-card h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.login-card input[type=password] {
  width: 100%;
  padding: 14px 16px;
  font-size: 18px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 4px;
}

.login-card input[type=password]:focus {
  outline: none;
  border-color: var(--good);
}

.login-card button[type=submit] {
  width: 100%;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  background: var(--good);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.login-card button[type=submit]:active { opacity: 0.85; }

.login-error {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid var(--bad-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 12px;
}

/* ─── Header ─────────────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-date {
  font-size: 14px;
  color: var(--text-muted);
}

.summary-row {
  display: flex;
  gap: 8px;
}

.badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  min-width: 64px;
  justify-content: center;
}

.badge-good   { background: var(--good-bg);  color: var(--good);  border: 1.5px solid var(--good-border); }
.badge-bad    { background: var(--bad-bg);   color: var(--bad);   border: 1.5px solid var(--bad-border);  }
.badge-water  { background: var(--water-bg); color: var(--water); border: 1.5px solid var(--water-border); }

/* ─── Main content ───────────────────────────────── */

.main {
  padding: 14px 14px 0;
  max-width: 600px;
  margin: 0 auto;
}

/* ─── Cards / sections ───────────────────────────── */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.2px;
}

.card-header.good  { color: var(--good); }
.card-header.bad   { color: var(--bad); }
.card-header.water { color: var(--water); }
.card-header.log   { color: var(--text); }

/* ─── Water controls ─────────────────────────────── */

.water-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 18px 20px;
}

.water-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--water-border);
  background: var(--water-bg);
  color: var(--water);
  font-size: 28px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.1s;
  line-height: 1;
}

.water-btn:active {
  transform: scale(0.88);
  background: var(--water-border);
}

.water-center { text-align: center; }

.water-count {
  font-size: 36px;
  font-weight: 800;
  color: var(--water);
  line-height: 1;
  letter-spacing: -1px;
}

.water-unit {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ─── Food entry form ────────────────────────────── */

.entry-form { padding: 14px 14px 10px; }

.entry-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}

.time-select {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.time-select:focus { outline: none; border-color: var(--good); }

.cat-toggle {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  flex-shrink: 0;
}

.cat-btn {
  padding: 10px 14px;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}

.cat-btn + .cat-btn { border-left: 1.5px solid var(--border); }

.cat-btn.active.cat-good { background: var(--good); color: #fff; }
.cat-btn.active.cat-bad  { background: var(--bad);  color: #fff; }

.entry-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.entry-input {
  flex: 1;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
}

.entry-input:focus { outline: none; border-color: var(--good); }

.entry-submit {
  padding: 12px 20px;
  border-radius: 9px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background: var(--good);
  color: #fff;
  white-space: nowrap;
  transition: background 0.15s;
}

.entry-submit.submit-bad { background: var(--bad); }
.entry-submit:active { opacity: 0.8; }

/* ─── Recent chips ───────────────────────────────── */

.recents-section {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 2px;
}

.recents-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.recents-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  padding: 7px 13px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border: 1.5px solid;
  transition: transform 0.1s;
}

.chip:active { transform: scale(0.92); }

.chip-good {
  background: var(--good-bg);
  color: var(--good);
  border-color: var(--good-border);
}

.chip-bad {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: var(--bad-border);
}

/* ─── Score strip ────────────────────────────────── */

.score-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.score-track {
  flex: 1;
  height: 6px;
  background: var(--bad-bg);
  border-radius: 3px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  background: var(--good);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.score-msg {
  font-size: 13px;
  font-weight: 600;
  color: var(--good);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── Today's log ────────────────────────────────── */

.log-list { list-style: none; }

.log-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  animation: slide-in 0.2s ease-out;
}

.log-item:last-child { border-bottom: none; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.log-dot.good { background: var(--good); }
.log-dot.bad  { background: var(--bad);  }

.log-name {
  flex: 1;
  font-size: 16px;
  font-weight: 500;
}

.log-delete {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.log-delete:active { background: var(--bad-bg); color: var(--bad); }

.log-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

.log-time-header {
  list-style: none;
  padding: 8px 16px 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* ─── History ────────────────────────────────────── */

.history-day {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

.history-day-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.history-date {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.history-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-bar {
  padding: 12px 16px;
}

.bar-track {
  height: 8px;
  background: var(--bad-bg);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.bar-fill {
  height: 100%;
  background: var(--good);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.bar-label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.history-entries {
  border-top: 1px solid var(--border);
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.history-entry:last-child { border-bottom: none; }

.no-history {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 16px;
}

/* ─── Bottom tab bar ─────────────────────────────── */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  gap: 3px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tab-item.active { color: var(--good); }

.tab-icon { font-size: 24px; line-height: 1; }

/* ─── Logout link ────────────────────────────────── */

.logout-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 8px;
}

/* ─── Learn page ─────────────────────────────────── */

.learn-tip-card {
  border-radius: var(--radius);
  border: 1.5px solid;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 20px 18px 22px;
  text-align: center;
}

.learn-tip-card.tip-good {
  background: var(--good-bg);
  border-color: var(--good-border);
}

.learn-tip-card.tip-bad {
  background: var(--bad-bg);
  border-color: var(--bad-border);
}

.learn-tip-card.tip-neutral {
  background: var(--surface);
  border-color: var(--border);
}

.tip-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
}

.tip-good .tip-label  { color: var(--good); }
.tip-bad  .tip-label  { color: var(--bad); }
.tip-neutral .tip-label { color: var(--text-muted); }

.tip-icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 10px;
}

.tip-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 10px;
}

.tip-body {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  text-align: left;
}

/* Recipe card */

.recipe-card { padding: 16px; }

.recipe-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.recipe-icon { font-size: 36px; line-height: 1; flex-shrink: 0; }

.recipe-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.recipe-time {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.recipe-why {
  font-size: 14px;
  color: var(--good);
  font-weight: 500;
  background: var(--good-bg);
  border: 1px solid var(--good-border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 14px;
  line-height: 1.4;
}

.recipe-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 12px;
}

.recipe-ingredients {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.recipe-ingredients li {
  font-size: 15px;
  padding-left: 14px;
  position: relative;
  line-height: 1.4;
}

.recipe-ingredients li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--good);
  font-weight: 700;
}

.recipe-method {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}

/* Collapsible sections */

.learn-details { }

.learn-summary {
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.learn-summary::-webkit-details-marker { display: none; }

.learn-summary::after {
  content: '›';
  font-size: 18px;
  color: var(--text-muted);
  transition: transform 0.2s;
  display: inline-block;
}

details[open] .learn-summary::after { transform: rotate(90deg); }

.learn-content {
  padding: 0 16px 18px;
  border-top: 1px solid var(--border);
}

.learn-content p {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  margin-top: 12px;
}

/* Food guide */

.food-guide-section { margin-top: 14px; }

.food-guide-heading {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.food-guide-section.good .food-guide-heading { color: var(--good); }
.food-guide-section.bad  .food-guide-heading { color: var(--bad); }

.food-guide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.food-guide-item {
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 7px;
  line-height: 1.3;
}

.food-guide-section.good .food-guide-item {
  background: var(--good-bg);
  color: var(--text);
}

.food-guide-section.bad .food-guide-item {
  background: var(--bad-bg);
  color: var(--text);
}

/* ─── Recipe carousel ────────────────────────────────── */

.cat-filter-row {
  display: flex;
  gap: 7px;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.cat-filter-row::-webkit-scrollbar { display: none; }

.cat-filter {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cat-filter.active {
  background: var(--good);
  color: #fff;
  border-color: var(--good);
}

.carousel-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.carousel-arrow {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.1s;
}

.carousel-arrow:disabled { opacity: 0.3; cursor: default; }
.carousel-arrow:not(:disabled):active { background: var(--border); }

.carousel-pos {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.pref-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.pref-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.pref-btn:active { opacity: 0.7; }

.pref-like.active {
  background: var(--good-bg);
  border-color: var(--good-border);
}

.recipe-carousel-card {
  padding: 16px;
  transition: opacity 0.15s ease;
}

.recipe-none {
  padding: 28px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.5;
}

/* Recipe card content (rendered by JS) */

.rc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.rc-cat {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.rc-time {
  font-size: 13px;
  color: var(--text-muted);
}

.rc-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 8px;
}

.rc-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 10px;
}

.rc-why {
  font-size: 14px;
  color: var(--good);
  font-weight: 500;
  background: var(--good-bg);
  border: 1px solid var(--good-border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.rc-section {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.rc-ingredients {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rc-ingredients li {
  font-size: 15px;
  padding-left: 14px;
  position: relative;
  line-height: 1.4;
}

.rc-ingredients li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--good);
  font-weight: 700;
}

.rc-method {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
}
