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

:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-input: #111111;
  --border: #2a2a2a;
  --border-focus: #444444;
  --text: #e8e8e8;
  --text-muted: #666666;
  --text-dim: #999999;
  --accent: #e8a030;
  --threshold: #e05555;
  --now: #4488cc;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  padding: 0;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-shrink: 0;
  padding-top: 32px;
  padding-bottom: 28px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

header h1 {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text);
}

.info-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #555;
  background: none;
  color: #999;
  font-family: var(--font);
  font-size: 11px;
  font-style: italic;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.info-btn:hover {
  border-color: var(--border-focus);
  color: var(--text-dim);
}

/* Footer tab bar */
.tab-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding: 12px 16px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 100;
}

/* Tabs */
.tab-nav {
  display: flex;
  gap: 3px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 15px;
  padding: 8px 28px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover {
  color: var(--text-dim);
}

.tab-btn.active {
  background: var(--border);
  color: var(--text);
}

/* Panes */
.tab-pane {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 80px;
  -webkit-overflow-scrolling: touch;
}

.tab-pane.hidden {
  display: none !important;
}

.placeholder {
  color: var(--text-muted);
  font-size: 13px;
  padding: 48px 0;
  text-align: center;
}

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

.section-header .label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.btn-add {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-add:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

#dose-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dose-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}

.dose-row .custom-halflife {
  display: none;
  grid-column: 1 / -1;
  margin-top: 4px;
}

.dose-row .custom-halflife.visible {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-halflife label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px 0;
  text-align: center;
}

.empty-state.hidden {
  display: none;
}

/* Controls */
.controls-section {
  display: flex;
  gap: 24px;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-group label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Inputs */
input[type="number"],
input[type="time"],
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input[type="number"]:focus,
input[type="time"]:focus,
select:focus {
  border-color: var(--border-focus);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-with-unit input,
.input-with-unit select {
  width: auto;
}

.input-with-unit #window-select {
  width: 70px;
}

.unit {
  font-size: 12px;
  color: var(--text-muted);
}

/* Time group */
.time-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.time-group select {
  width: auto;
}

.time-hour-select {
  min-width: 88px;
}

.time-minute-select {
  min-width: 54px;
}

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

/* Remove button */
.btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}

.btn-remove:hover {
  color: var(--threshold);
}

/* Chart */
.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
}

.chart-section canvas {
  width: 100% !important;
}

/* Summary */
.crossing-summary {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  padding: 4px 0;
}

.crossing-summary.hidden {
  display: none;
}

.crossing-summary strong {
  color: var(--text);
}

/* -------------------------------------------------------------------------
   Simple mode — comic-book cutout aesthetic
   ------------------------------------------------------------------------- */

#simple-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.simple-entry {
  margin-bottom: 36px;
}

.entry-section-label {
  font-family: 'Bangers', cursive;
  font-size: 30px;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 14px;
  text-align: center;
  width: 100%;
}

/* Drink cards */
.drink-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.drink-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-top: 6px;
}

.drink-card {
  width: 112px;
  border: 3px solid #000;
  box-shadow: 5px 5px 0 #000;
  border-radius: 10px;
  cursor: pointer;
  padding: 12px 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
  user-select: none;
  background: #fff;
}

.drink-tile:nth-child(1) .drink-card { transform: rotate(-2deg); }
.drink-tile:nth-child(2) .drink-card { transform: rotate(1.5deg); }
.drink-tile:nth-child(3) .drink-card { transform: rotate(-1deg); }

.drink-card:hover {
  transform: rotate(0deg) translate(-3px, -3px) !important;
  box-shadow: 8px 8px 0 #000;
}

.drink-card.selected {
  transform: rotate(2deg) translate(3px, 3px) !important;
  box-shadow: 2px 2px 0 #000;
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.coffee-card  { background: #E88042; }
.tea-card     { background: #5DBFA0; }
.mystery-card { background: #7B2FBE; }

.mystery-card:not(.mystery-chosen) .drink-svg {
  animation: mk-hue 5s linear infinite;
}

@keyframes mk-hue {
  from { filter: hue-rotate(0deg)   saturate(1.8) brightness(1.1); }
  to   { filter: hue-rotate(360deg) saturate(1.8) brightness(1.1); }
}

.drink-svg {
  width: 72px;
  height: 68px;
}

.drink-label {
  font-family: 'Bangers', cursive;
  font-size: 17px;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  text-align: center;
  line-height: 1.15;
  word-break: break-word;
  min-height: calc(2 * 1.15em);
  width: 112px;
}

.drink-mg {
  font-family: 'Bangers', cursive;
  font-size: 20px;
  letter-spacing: 0.05em;
  color: #000;
  background: #FFD700;
  border: 2px solid #000;
  border-radius: 6px;
  padding: 3px 10px;
  box-shadow: 2px 2px 0 #000;
  line-height: 1.2;
}

.drink-mg.hidden { visibility: hidden; }
.drink-tile:hover .drink-mg.hidden { visibility: visible; }
[data-selected-drink="tea"] .drink-tile:nth-child(1):hover .drink-mg.hidden,
[data-selected-drink="tea"] .drink-tile:nth-child(3):hover .drink-mg.hidden { visibility: hidden; }

/* Tea wheel */
.tea-wheel {
  position: relative;
  width: 368px;
  height: 175px;
  margin-top: -44px;
}

.tea-wheel.hidden { display: none; }

.tea-option {
  position: absolute;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid #000;
  box-shadow: 3px 3px 0 #000;
  background: var(--tc);
  color: #fff;
  font-family: 'Bangers', cursive;
  font-size: 18px;
  letter-spacing: 0.04em;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.1;
  transition: transform 0.1s, box-shadow 0.1s;
}

.tea-option:hover {
  transform: scale(1.12) !important;
  box-shadow: 5px 5px 0 #000;
}

/* Arc positions: 6 × 76px circles in a bowl curve, 368px wide (matches card row) */
.tea-option:nth-child(1) { left: 0;     top: 0;    }
.tea-option:nth-child(2) { left: 51px;  top: 57px; }
.tea-option:nth-child(3) { left: 111px; top: 99px; }
.tea-option:nth-child(4) { left: 181px; top: 99px; }
.tea-option:nth-child(5) { left: 241px; top: 57px; }
.tea-option:nth-child(6) { left: 292px; top: 0;    }

/* Mystery popup */
.mystery-popup {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  background: #fff;
  border: 3px solid #000;
  box-shadow: 5px 5px 0 #000;
  border-radius: 8px;
  padding: 8px;
  min-width: 148px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mystery-popup.hidden { display: none; }

.mystery-option {
  background: #FFD700;
  border: 2px solid #000;
  border-radius: 5px;
  padding: 6px 10px;
  font-family: 'Bangers', cursive;
  font-size: 16px;
  letter-spacing: 0.05em;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
  box-shadow: 2px 2px 0 #000;
}

.mystery-option:hover { background: #ffe84d; box-shadow: 3px 3px 0 #000; }

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

.mystery-option-mg {
  font-size: 13px;
  opacity: 0.65;
  flex-shrink: 0;
}

/* Time step */
.entry-time-step {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.entry-time-step.hidden { display: none; }

.entry-time-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.comic-time-group {
  gap: 6px;
}

.comic-time-group select {
  background: #fff;
  border: 3px solid #000;
  color: #000;
  font-family: 'Bangers', cursive;
  font-size: 20px;
  letter-spacing: 0.05em;
  padding: 6px 28px 6px 10px;
  box-shadow: 3px 3px 0 #000;
  border-radius: 6px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23000'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  width: auto;
  min-width: 96px;
  cursor: pointer;
}

.comic-time-group select:focus { outline: none; border-color: #000; }

.comic-time-group .simple-minute-select { min-width: 68px; }

.comic-sep {
  font-family: 'Bangers', cursive;
  font-size: 30px;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

.entry-remove-btn {
  background: none;
  border: 2px solid #444;
  color: #555;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}

.entry-remove-btn:hover { color: #e05555; border-color: #e05555; }

/* Result section */
.simple-result { margin-top: 8px; }
.simple-result.hidden { display: none; }

.result-label {
  font-family: 'Bangers', cursive;
  font-size: 26px;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 16px;
}

.ticker-digits {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tick-box {
  width: 56px;
  height: 70px;
  background: #FFD700;
  border: 3px solid #000;
  box-shadow: 4px 4px 0 #000;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bangers', cursive;
  font-size: 48px;
  color: #000;
  line-height: 1;
}

.tick-colon {
  font-family: 'Bangers', cursive;
  font-size: 54px;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  line-height: 1;
  margin-bottom: 4px;
}

.tick-ampm {
  font-family: 'Bangers', cursive;
  font-size: 24px;
  letter-spacing: 0.05em;
  color: #000;
  background: #e0e0e0;
  border: 3px solid #000;
  box-shadow: 4px 4px 0 #000;
  border-radius: 6px;
  padding: 6px 10px;
  align-self: flex-end;
  margin-bottom: 4px;
}

.ticker-message {
  font-family: 'Bangers', cursive;
  font-size: 22px;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* + Add button */
.comic-add-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #000;
  background: #FFD700;
  color: #000;
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  box-shadow: 4px 4px 0 #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, box-shadow 0.1s;
}

.comic-add-btn.hidden { display: none; }

.entry-add-btn {
  width: 40px;
  height: 40px;
  font-size: 26px;
}

.comic-add-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #000;
}

.comic-add-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #000;
}

/* Responsive */
@media (max-width: 540px) {
  .dose-row {
    grid-template-columns: 1fr 72px;
    grid-template-rows: auto auto;
  }

  .dose-row .time-input {
    grid-column: 1;
  }

  .dose-row .btn-remove {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
  }

  .controls-section {
    flex-wrap: wrap;
    gap: 16px;
  }
}

/* Simple mode mobile — scale cards + tea wheel to fit narrow screens */
@media (max-width: 400px) {
  .drink-cards { gap: 10px; }

  .drink-card {
    width: 96px;
    padding: 10px 6px;
  }

  .drink-label { width: 96px; font-size: 15px; }

  .drink-svg { width: 60px; height: 56px; }

  /* tea wheel: 3 × 96 + 2 × 10 = 308px; scale arc positions to match */
  .tea-wheel { width: 308px; height: 148px; margin-top: -38px; }

  .tea-option {
    width: 64px;
    height: 64px;
    font-size: 15px;
  }

  .tea-option:nth-child(1) { left: 0;     top: 0;    }
  .tea-option:nth-child(2) { left: 42px;  top: 48px; }
  .tea-option:nth-child(3) { left: 92px;  top: 84px; }
  .tea-option:nth-child(4) { left: 152px; top: 84px; }
  .tea-option:nth-child(5) { left: 202px; top: 48px; }
  .tea-option:nth-child(6) { left: 244px; top: 0;    }
}

/* Info modal */
.info-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.info-modal.hidden { display: none; }

.info-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(2px);
}

.info-sheet {
  position: relative;
  background: #141414;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 82vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 28px 40px;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
}

.info-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}

.info-close:hover { border-color: var(--border-focus); color: var(--text); }

.info-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  padding-right: 36px;
}

.info-section {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 24px 0 10px;
}

.info-body {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.info-body strong { color: var(--text); font-weight: 500; }

.info-formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 18px;
  margin: 12px 0 4px;
}

.info-formula-part {
  font-family: 'Courier New', monospace;
  font-size: 15px;
  color: #f0c060;
  background: #222;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 3px 8px;
}

.info-formula-op {
  font-size: 13px;
  color: var(--text-muted);
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-bottom: 4px;
}

.info-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px 8px 0;
  border-bottom: 1px solid var(--border);
}

.info-table td {
  color: var(--text-dim);
  padding: 7px 8px 7px 0;
  border-bottom: 1px solid #1e1e1e;
  vertical-align: top;
}

.info-table td:first-child { color: var(--text); font-weight: 500; white-space: nowrap; }
.info-table td:nth-child(2) { color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.info-table em { font-style: italic; color: inherit; }

.info-cite {
  font-size: 11px;
  color: #444;
  margin-top: 10px;
  line-height: 1.6;
}

.info-disclaimer {
  font-size: 12px;
  line-height: 1.6;
  color: #666;
  border-top: 1px solid var(--border);
  margin-top: 24px;
  padding-top: 16px;
}
