:root {
  --bg-0: #140e0a;
  --bg-1: #1f1510;
  --bg-2: #2a1c14;
  --ink: #f3e6d4;
  --ink-dim: #b9a48c;
  --amber: #e8a045;
  --amber-hot: #ffc56a;
  --line: rgba(243, 230, 212, 0.12);
  --danger: #e07060;
  --ok: #8fbf7a;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 14px;
  --max: 720px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg-0);
  line-height: 1.45;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(232, 160, 69, 0.22), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 80%, rgba(90, 40, 20, 0.45), transparent 50%),
    radial-gradient(ellipse 50% 35% at 0% 60%, rgba(40, 24, 16, 0.8), transparent 45%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 60%);
  animation: atmosphere-drift 18s ease-in-out infinite alternate;
}

@keyframes atmosphere-drift {
  from { filter: hue-rotate(0deg) brightness(1); }
  to { filter: hue-rotate(-8deg) brightness(1.05); }
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0;
  color: var(--amber-hot);
  text-shadow: 0 0 40px rgba(232, 160, 69, 0.25);
}

.top {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  animation: rise 0.7s ease both;
}

main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 4rem;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.ghost:hover {
  color: var(--ink);
  border-color: rgba(243, 230, 212, 0.3);
}

.gauge-section {
  text-align: center;
  padding: 1.5rem 0 2.5rem;
  animation: rise 0.8s ease 0.08s both;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  color: var(--ink-dim);
  margin: 0 0 1rem;
}

.gauge-ring {
  position: relative;
  width: min(340px, 88vw);
  margin: 0 auto 1rem;
  overflow: visible;
}

.gauge-svg {
  width: 100%;
  height: auto;
  overflow: visible;
  transform: rotate(-90deg);
}

.gauge-track,
.gauge-glow,
.gauge-fill {
  fill: none;
  stroke-width: 8;
}

.gauge-track {
  stroke: rgba(243, 230, 212, 0.1);
}

.gauge-glow {
  stroke: var(--amber);
  stroke-width: 16;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  opacity: 0.32;
  filter: blur(6px);
  transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 1, 0.36, 1), stroke 0.4s ease;
}

.gauge-fill {
  stroke: var(--amber);
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 1, 0.36, 1), stroke 0.4s ease;
}

.gauge-readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.1rem;
}

.mg-value {
  font-family: var(--font-mono);
  font-size: clamp(2.6rem, 8.5vw, 3.5rem);
  font-weight: 500;
  line-height: 1;
  animation: pulse-soft 2.8s ease-in-out infinite;
}

.mg-unit {
  font-size: 0.95rem;
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.88; }
}

.half-life {
  color: var(--ink-dim);
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}

.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: 360px;
  margin: 0 auto;
}

.totals > div {
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.totals-label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 0.25rem;
}

.totals-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
}

.add-section,
.chart-section,
.history-section {
  animation: rise 0.85s ease 0.16s both;
}

.chart-section {
  margin-bottom: 2.5rem;
}

.chart-shell {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(42, 28, 20, 0.55), rgba(20, 14, 10, 0.35));
  overflow: hidden;
  padding: 0.35rem 0.25rem 0.15rem;
}

.timeline {
  display: block;
  width: 100%;
  height: auto;
  min-height: 220px;
}

.timeline .grid-line {
  stroke: rgba(243, 230, 212, 0.08);
  stroke-width: 1;
}

.timeline .axis-label {
  fill: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 11px;
}

.timeline .area-past {
  fill: url(#amber-fill);
  opacity: 0.9;
}

.timeline .line-past {
  fill: none;
  stroke: var(--amber-hot);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(232, 160, 69, 0.35));
}

.timeline .line-future {
  fill: none;
  stroke: var(--amber);
  stroke-width: 2;
  stroke-dasharray: 5 6;
  stroke-linecap: round;
  opacity: 0.75;
}

.timeline .now-line {
  stroke: rgba(243, 230, 212, 0.45);
  stroke-width: 1.25;
  stroke-dasharray: 3 4;
}

.timeline .now-dot {
  fill: var(--ink);
  stroke: var(--amber-hot);
  stroke-width: 2;
}

.timeline .dose-mark {
  fill: var(--bg-0);
  stroke: var(--amber);
  stroke-width: 1.75;
  transition: fill 0.15s ease, stroke 0.15s ease, r 0.15s ease;
}

.timeline .dose-mark.is-hot {
  fill: var(--amber-hot);
  stroke: var(--ink);
  stroke-width: 2;
}

.timeline .crosshair {
  stroke: rgba(255, 197, 106, 0.35);
  stroke-width: 1;
  pointer-events: none;
}

.timeline .hover-dot {
  fill: var(--amber-hot);
  stroke: var(--bg-0);
  stroke-width: 2;
  pointer-events: none;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  transform: translate(-50%, calc(-100% - 10px));
  background: rgba(20, 14, 10, 0.92);
  border: 1px solid rgba(232, 160, 69, 0.4);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  background: rgba(20, 14, 10, 0.35);
}

.chart-empty[hidden] {
  display: none;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.chart-legend .leg {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.chart-legend .leg::before {
  content: "";
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--amber-hot);
}

.chart-legend .leg.future::before {
  background: repeating-linear-gradient(
    90deg,
    var(--amber) 0 4px,
    transparent 4px 8px
  );
}

.chart-legend .leg.now::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--amber-hot);
}

.chart-legend .leg.dose::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--amber);
}


h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.65rem;
  margin: 0 0 0.35rem;
}

h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.15rem;
  margin: 0 0 0.85rem;
}

.section-lede {
  margin: 0 0 1.25rem;
  color: var(--ink-dim);
}

.presets {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.preset {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(42, 28, 20, 0.9), rgba(20, 14, 10, 0.6));
  color: inherit;
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.preset:hover,
.preset:focus-visible {
  border-color: rgba(232, 160, 69, 0.55);
  outline: none;
}

.preset:active {
  transform: scale(0.985);
}

.preset-name {
  display: block;
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: 0.15rem;
}

.preset-meta {
  color: var(--ink-dim);
  font-size: 0.9rem;
}

.coffee-block {
  cursor: default;
}

.coffee-head {
  margin-bottom: 0.85rem;
}

.coffee-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: end;
}

.coffee-controls label {
  font-size: 0.8rem;
  color: var(--ink-dim);
  display: grid;
  gap: 0.35rem;
}

.manual {
  border-top: 1px solid var(--line);
  padding-top: 1.35rem;
}

.manual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.manual-grid .span-2 {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-dim);
}

.optional {
  opacity: 0.7;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(232, 160, 69, 0.45);
  outline-offset: 1px;
  border-color: transparent;
}

button[type="submit"],
#btn-coffee {
  border: none;
  background: linear-gradient(180deg, var(--amber-hot), var(--amber));
  color: #1a1008;
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.75rem 1.2rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}

button[type="submit"]:hover,
#btn-coffee:hover {
  filter: brightness(1.05);
}

button[type="submit"]:active,
#btn-coffee:active {
  transform: scale(0.98);
}

.flash {
  margin-top: 0.85rem;
  color: var(--ok);
  font-size: 0.95rem;
}

.flash.error {
  color: var(--danger);
}

.history {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.history li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
  animation: rise 0.45s ease both;
}

.history .label {
  font-weight: 500;
}

.history .when {
  display: block;
  color: var(--ink-dim);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.history .amounts {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.history .remaining {
  color: var(--amber);
  display: block;
}

.history .dose {
  color: var(--ink-dim);
  font-size: 0.8rem;
}

.history button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-dim);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}

.history button:hover {
  color: var(--danger);
  border-color: rgba(224, 112, 96, 0.5);
}

.empty {
  color: var(--ink-dim);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(232, 160, 69, 0.2), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

.login-shell {
  width: min(400px, 100%);
  animation: rise 0.7s ease both;
}

.login-shell h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.8rem;
  margin: 0.35rem 0 0.4rem;
}

.login-shell .lede {
  color: var(--ink-dim);
  margin: 0 0 1.5rem;
}

.login-shell form {
  display: grid;
  gap: 0.75rem;
}

.login-shell button {
  margin-top: 0.35rem;
}

.error {
  color: var(--danger);
  margin: 0;
}

@media (max-width: 560px) {
  .manual-grid {
    grid-template-columns: 1fr;
  }

  .coffee-controls {
    grid-template-columns: 1fr;
  }

  .history li {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }

  .history button {
    grid-column: 2;
    grid-row: 1 / 3;
  }
}
