:root {
  --bg: #0a0812;
  --bg2: #0f0c1a;
  --card: #141020;
  --card2: #1a1430;
  --line: #241d3a;
  --line2: #342a56;
  --text: #f2eefc;
  --muted: #a79ec4;
  --dim: #7d7599;
  --accent: #a78bfa;
  --accent2: #cbbaff;
  --accent-deep: #7c3aed;
  --amber: #fbbf24;
  --red: #fb7185;
  --radius: 16px;
  font-synthesis: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

body {
  background:
    radial-gradient(820px 460px at 12% -12%, rgba(124, 58, 237, 0.22), transparent 70%),
    radial-gradient(680px 380px at 100% 4%, rgba(167, 139, 250, 0.10), transparent 68%),
    var(--bg);
  background-attachment: fixed;
}

.wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 20px 88px;
}

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand .mark {
  width: 17px; height: 17px;
  border-radius: 6px;
  background: linear-gradient(150deg, var(--accent2), var(--accent-deep));
  box-shadow: 0 0 14px rgba(167, 139, 250, 0.4);
}
.brand span.k { color: var(--dim); font-weight: 500; margin-left: 2px; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.live i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 2.6s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(167, 139, 250, 0); }
  100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}

.label {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 650;
}

/* ---------- hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px 22px 0;
  background:
    radial-gradient(520px 240px at 88% -30%, rgba(167, 139, 250, 0.18), transparent 70%),
    linear-gradient(165deg, #191130 0%, #120e22 58%, #0f0c1b 100%);
}

.heroTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.readout {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 12px 0 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
  line-height: 0.92;
}
.readout .int {
  font-size: clamp(54px, 12vw, 92px);
  font-weight: 700;
}
.readout .frac {
  font-size: clamp(24px, 5.5vw, 40px);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.03em;
}
.readout .unit {
  font-size: 15px;
  color: var(--muted);
  font-weight: 550;
  letter-spacing: 0;
  margin-left: 6px;
}

.sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.sub b { color: var(--text); font-weight: 600; }

/* stats: a single strip inside the hero, cards elsewhere */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 18px;
}
.hero .stats {
  gap: 0;
  margin: 18px -22px 0;
  border-top: 1px solid var(--line);
}
.hero .stat {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.014);
  padding: 12px 22px 14px;
}
.hero .stat:last-child { border-right: 0; }

.stat {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat span {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 5px;
  font-weight: 600;
}
.stat strong {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 12px;
}

.cardHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.headLeft {
  display: flex;
  align-items: center;
  gap: 9px;
}

/* ---------- charts ---------- */
.chartWrap { position: relative; }

.chart {
  width: 100%;
  height: 164px;
  display: block;
  overflow: visible;
  cursor: crosshair;
  touch-action: none;
}
.chart text {
  fill: var(--dim);
  font-size: 9.5px;
  font-family: inherit;
  letter-spacing: 0.02em;
}

.tip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  pointer-events: none;
  background: #191330;
  border: 1px solid var(--line2);
  border-radius: 9px;
  padding: 5px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  box-shadow: 0 10px 24px rgba(5, 0, 18, 0.6);
  white-space: nowrap;
}
.tip b { color: var(--accent2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tip span { color: var(--dim); font-size: 9.5px; letter-spacing: 0.03em; }

/* ---------- daily limit ---------- */
.limit { margin-top: 12px; }
.limitRow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 9px;
}
.track {
  height: 6px;
  border-radius: 99px;
  background: #1b1531;
  overflow: hidden;
}
.fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent2));
  transition: width 0.4s ease;
}
.fill.over { background: linear-gradient(90deg, var(--amber), var(--red)); }

/* ---------- section headings ---------- */
h2 {
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 650;
  margin: 24px 0 10px;
}

/* ---------- presets ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
}

.drink {
  position: relative;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 13px 13px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease,
              box-shadow 0.15s ease;
}
.drink:hover {
  border-color: var(--line2);
  background: var(--card2);
  transform: translateY(-2px);
  box-shadow: 0 12px 26px -14px rgba(124, 58, 237, 0.75);
}
.drink:active { transform: translateY(0) scale(0.99); }

.drink .nm {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.015em;
  padding-right: 14px;
  white-space: nowrap;
}
.drink .sz {
  font-size: 10.5px;
  color: var(--dim);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.drink .mgrow {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-top: 10px;
}
.drink .mg {
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.drink .unit2 { font-size: 10.5px; color: var(--muted); font-weight: 550; }
.drink .plus {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 13px;
  line-height: 1;
  color: var(--dim);
  transition: color 0.15s ease;
}
.drink:hover .plus { color: var(--accent); }

.swatch {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
}

/* ---------- forms ---------- */
input {
  width: 100%;
  background: #0c0917;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.16);
}
input::placeholder { color: #574f74; }

.custom {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.9fr auto;
  gap: 8px;
  align-items: center;
}

button.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #fdfbff;
  border: 0;
  border-radius: 10px;
  padding: 9px 16px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 8px 18px -10px rgba(124, 58, 237, 0.9);
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.35; cursor: default; box-shadow: none; }

/* ---------- log ---------- */
.log { padding: 4px 16px; }
.entry {
  display: grid;
  grid-template-columns: 104px 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.entry:last-child { border-bottom: 0; }
.entry .t { color: var(--dim); font-size: 11px; }
.entry .d { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.entry .d b { font-weight: 550; font-size: 12.5px; letter-spacing: -0.005em; }
.entry .d span { font-size: 10.5px; color: var(--dim); }
.entry .now {
  color: var(--accent2);
  font-weight: 650;
  text-align: right;
  min-width: 74px;
}
.entry .now small { color: var(--dim); font-weight: 400; font-size: 10px; }

.iconbtn {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  padding: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  font: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.iconbtn.rm { width: 30px; height: 30px; font-size: 13px; }
.iconbtn:hover { color: var(--text); border-color: var(--line2); }
.iconbtn.rm:hover {
  color: var(--red);
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
}

.empty {
  color: var(--dim);
  font-size: 12.5px;
  padding: 16px 2px 14px;
  line-height: 1.5;
}

/* ---------- settings ---------- */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.row + .row { margin-top: 14px; }
.row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 190px;
  height: 4px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent), #2a2244);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid #120e22;
  background: var(--accent2);
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--accent), 0 2px 8px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid #120e22;
  background: var(--accent2);
  cursor: pointer;
}

.hint {
  font-size: 11px;
  color: var(--dim);
  margin-top: 10px;
  line-height: 1.55;
}

footer {
  margin-top: 28px;
  font-size: 10.5px;
  color: #4b4466;
  text-align: center;
  line-height: 1.6;
}

/* ---------- toast / undo ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #fdfbff;
  font-weight: 600;
  font-size: 12.5px;
  padding: 10px 16px;
  border-radius: 99px;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  box-shadow: 0 16px 34px -14px rgba(124, 58, 237, 0.95);
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.toast.undoing {
  pointer-events: auto;
  background: #191330;
  color: var(--text);
  border: 1px solid var(--line2);
  font-weight: 500;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.9);
}
.toast.undoing span { font-size: 12.5px; }
.undoBtn {
  background: var(--accent);
  color: #150e28;
  border: 0;
  border-radius: 99px;
  padding: 5px 12px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.undoBtn:hover { background: var(--accent2); }

/* ---------- log time ---------- */
.when {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 11px;
  flex-wrap: wrap;
}
.when input {
  width: auto;
  min-width: 200px;
  padding: 7px 10px;
  font-size: 12px;
  color-scheme: dark;
}
.when .whendim { font-size: 10.5px; color: var(--dim); }

/* ---------- history ---------- */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #0d0a18;
  border: 1px solid var(--line);
  border-radius: 11px;
}
.tab {
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  font-size: 10.5px;
  font-weight: 550;
  letter-spacing: 0.01em;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.on {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #fdfbff;
  font-weight: 650;
}

.chart.chart-h { height: 186px; }
.histStats { margin-top: 14px; }

.peaks { margin-top: 12px; }
.peak {
  display: grid;
  grid-template-columns: 100px 68px 1fr;
  gap: 12px;
  align-items: baseline;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.peak .t { color: var(--dim); }
.peak b { color: var(--accent2); font-weight: 650; font-size: 11.5px; }
.peak .drop { color: var(--dim); }
.peak.more {
  grid-template-columns: 1fr;
  color: var(--dim);
  border-top: 0;
  padding-top: 10px;
}

/* ---------- focus + responsive ---------- */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 700px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .wrap { padding: 16px 14px 84px; }
  .hero { padding: 18px 16px 0; border-radius: 18px; }
  .hero .stats { margin: 16px -16px 0; }
  .hero .stat { padding: 10px 12px 12px; }
  .hero .stat strong { font-size: 12px; }
  .hero .stat span { font-size: 8.5px; letter-spacing: 0.1em; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .histStats { grid-template-columns: 1fr 1fr; }
  .histStats .stat:last-child { grid-column: span 2; }
  .custom { grid-template-columns: 1fr 1fr; }
  .custom button { grid-column: span 2; }
  .entry { grid-template-columns: 1fr auto auto; gap: 10px; }
  .entry .t { display: none; }
  .log { padding: 4px 14px; }
  input[type="range"] { width: 130px; }
  .chart { height: 150px; }
  .chart.chart-h { height: 160px; }
  .peak { grid-template-columns: 1fr auto; }
  .peak .drop { grid-column: span 2; }
}

/* ---------- move between devices ---------- */
.syncRow {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.syncRow .tab {
  border: 1px solid var(--line);
  background: #0d0a18;
  padding: 6px 11px;
}
.syncRow .tab:hover:not(:disabled) { border-color: var(--line2); }
.syncRow .tab:disabled { opacity: 0.45; cursor: default; }
.filehide { display: none; }

.qrBox {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
}
.qrPic {
  flex: 0 0 172px;
  background: #fff;
  border-radius: 12px;
  padding: 6px;
  line-height: 0;
}
.qrPic svg { width: 100%; height: auto; display: block; }
.qrBox .hint { margin-top: 0; flex: 1; }

.hint.warn { color: #fca5a5; }

.scan {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 18, 0.84);
  backdrop-filter: blur(6px);
}
.scan.on { display: flex; }
.scanCard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 16px;
  box-shadow: 0 26px 60px rgba(4, 0, 14, 0.7);
}
.scanCard video {
  width: min(78vw, 320px);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  background: #000;
}
.scanHint {
  font-size: 11px;
  color: var(--dim);
  max-width: 300px;
  text-align: center;
  line-height: 1.5;
}

@media (max-width: 520px) {
  .qrBox { flex-direction: column; align-items: flex-start; }
  .qrPic { align-self: center; }
}
