:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
  --coffee: #e8a04a;
  --coffee-soft: rgba(232, 160, 74, 0.16);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 600px; height: 600px; overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { width: 100%; height: 100%; position: relative; }
.screen { width: 100%; height: 100%; position: absolute; top: 0; left: 0; display: flex; flex-direction: column; }
.screen.hidden { display: none; }
.focusable { transition: all 0.15s ease; border: 2px solid transparent; cursor: pointer; outline: none; }
.focusable:focus { border-color: var(--focus-ring); box-shadow: 0 0 20px var(--focus-glow); }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 16px; flex-shrink: 0;
  background: var(--bg-primary);
  border-bottom: 1px solid #22222e;
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: 0.3px; }
.brand-ico { font-size: 22px; }
.clock { font-size: 18px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.title { font-size: 20px; font-weight: 600; }
.topbar-spacer { width: 72px; }
.iconbtn {
  background: var(--bg-tertiary); color: var(--text-primary);
  border-radius: 10px; padding: 8px 14px; font-size: 16px; font-weight: 600;
  min-height: 44px; min-width: 72px;
}

/* ---------- Home ---------- */
.home-body {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 16px 18px 18px; gap: 14px;
}
.level-card {
  width: 100%; display: flex; flex-direction: column; align-items: center;
  background: var(--bg-secondary); border-radius: 16px; padding: 14px 16px 16px;
}
.level-value { font-size: 72px; font-weight: 800; line-height: 1; color: var(--coffee); font-variant-numeric: tabular-nums; }
.level-value .unit { font-size: 26px; font-weight: 600; color: var(--text-secondary); margin-left: 6px; }
.level-label { font-size: 15px; color: var(--text-secondary); margin-top: 4px; }
.status-pill {
  margin-top: 12px; padding: 6px 16px; border-radius: 999px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.3px;
}
.s-clear  { background: rgba(0,255,136,0.14); color: var(--accent-secondary); }
.s-low    { background: rgba(160,160,176,0.14); color: var(--text-secondary); }
.s-mod    { background: rgba(0,212,255,0.14); color: var(--accent); }
.s-high   { background: var(--coffee-soft); color: var(--coffee); }
.s-vhigh  { background: rgba(255,68,102,0.16); color: var(--danger); }

.spark { width: 540px; height: 120px; display: block; }
.insight {
  width: 100%; text-align: center; font-size: 15px; line-height: 1.4;
  color: var(--text-secondary); min-height: 40px;
  display: flex; align-items: center; justify-content: center; padding: 0 6px;
}

/* ---------- Buttons ---------- */
.btn {
  width: 100%; background: var(--bg-tertiary); color: var(--text-primary);
  border-radius: var(--radius-md); font-size: 18px; font-weight: 600;
  min-height: 56px; display: flex; align-items: center; justify-content: center;
}
.btn-primary {
  background: linear-gradient(135deg, var(--coffee), #d4882f);
  color: #1a1206; font-weight: 800; min-height: 72px; font-size: 21px;
}
.btn-sm { min-height: 56px; font-size: 16px; }
.btn-danger { background: rgba(255,68,102,0.16); color: var(--danger); font-weight: 700; }
.btn-row { width: 100%; display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Lists (log + history) ---------- */
.list {
  flex: 1; overflow-y: auto; padding: 12px 16px 20px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.list::-webkit-scrollbar { width: 0; height: 0; }

.drink {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--bg-secondary); color: var(--text-primary);
  border-radius: var(--radius-md); padding: 0 18px; min-height: 64px;
  text-align: left; scroll-margin: 16px;
}
.drink-emoji { font-size: 26px; width: 32px; text-align: center; }
.drink-name { flex: 1; font-size: 18px; font-weight: 600; }
.drink-mg { font-size: 17px; font-weight: 700; color: var(--coffee); font-variant-numeric: tabular-nums; }
.drink.custom-row .drink-mg { color: var(--accent); }

/* ---------- Custom amount ---------- */
.custom-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px; }
.custom-display { display: flex; align-items: baseline; gap: 8px; }
.custom-num { font-size: 96px; font-weight: 800; color: var(--coffee); line-height: 1; font-variant-numeric: tabular-nums; }
.custom-unit { font-size: 32px; font-weight: 600; color: var(--text-secondary); }
.custom-hint { font-size: 15px; color: var(--text-muted); margin-top: -8px; }
.adjust-row { display: flex; gap: 12px; width: 100%; }
.adj {
  flex: 1; background: var(--bg-tertiary); color: var(--text-primary);
  border-radius: var(--radius-md); min-height: 64px; font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Curve ---------- */
.curve-body { flex: 1; display: flex; flex-direction: column; padding: 16px 18px; gap: 14px; }
.curve-canvas { width: 100%; height: 270px; display: block; background: var(--bg-secondary); border-radius: 14px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg-secondary); border-radius: 12px; padding: 12px 14px; }
.stat-k { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 18px; justify-content: center; font-size: 13px; color: var(--text-secondary); }
.lg { display: flex; align-items: center; gap: 6px; }
.lg-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.lg-coffee { background: var(--coffee); }
.lg-now { background: var(--accent); }
.lg-dash { width: 16px; height: 0; border-top: 2px dashed var(--text-muted); display: inline-block; }

/* ---------- History ---------- */
.hist-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hist-summary { padding: 14px 18px 4px; flex-shrink: 0; }
.hist-total { font-size: 18px; font-weight: 600; }
.hist-total b { color: var(--coffee); font-size: 22px; }
.hist-total .over { color: var(--danger); }
.hist-bar { height: 8px; border-radius: 4px; background: var(--bg-tertiary); margin-top: 8px; overflow: hidden; }
.hist-bar-fill { height: 100%; background: var(--coffee); border-radius: 4px; transition: width 0.3s ease; }
.hist-bar-fill.over { background: var(--danger); }
.hist-empty { text-align: center; color: var(--text-muted); font-size: 16px; padding: 40px 20px; }

.log-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--bg-secondary); color: var(--text-primary);
  border-radius: var(--radius-md); padding: 0 16px; min-height: 60px;
  text-align: left; scroll-margin: 16px;
}
.log-emoji { font-size: 22px; width: 28px; text-align: center; }
.log-info { flex: 1; display: flex; flex-direction: column; }
.log-name { font-size: 17px; font-weight: 600; }
.log-time { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.log-mg { font-size: 16px; font-weight: 700; color: var(--coffee); font-variant-numeric: tabular-nums; }
.log-x { font-size: 18px; color: var(--text-muted); margin-left: 4px; }
.log-item.pending { background: rgba(255,68,102,0.16); }
.log-item.pending .log-confirm { color: var(--danger); font-weight: 700; font-size: 15px; flex: 1; }

/* ---------- Settings ---------- */
.set-body { flex: 1; display: flex; flex-direction: column; padding: 16px 18px; gap: 14px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-secondary); border-radius: 14px; padding: 14px 16px; min-height: 72px;
}
.set-label { font-size: 18px; font-weight: 600; display: flex; flex-direction: column; }
.set-sub { font-size: 13px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }
.adjuster { display: flex; align-items: center; gap: 12px; }
.adj-round {
  flex: none; width: 48px; height: 48px; min-height: 48px; border-radius: 50%;
  font-size: 26px; font-weight: 700; padding: 0; line-height: 1;
}
.adj-val { font-size: 19px; font-weight: 700; min-width: 72px; text-align: center; font-variant-numeric: tabular-nums; }
.set-body .btn-danger { margin-top: auto; }

/* ---------- Toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--bg-tertiary); color: var(--text-primary);
  padding: 12px 22px; border-radius: 999px; font-size: 16px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6); border: 1px solid #2a2a3a;
  z-index: 50; max-width: 80%; text-align: center;
  opacity: 0; transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
