:root {
  --bg: #faf8f4;
  --fg: #1e1b16;
  --muted: #6b6357;
  --row-odd: #ffffff;
  --row-even: #f3efe7;
  --sleep-odd: #4e5f8d;
  --sleep-even: #415178;
  --sleep-fg: #eef2ff;
  --accent: #b8763a;
  --accent-strong: #8a4f1e;
  --alert: #c4281b;
  --border: #e3ddd1;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --rail-bg: #ffffff;
  --selected-ring: 0 0 0 3px var(--accent);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.site-header {
  text-align: center;
  padding: 24px 16px 8px;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  grid-template-areas: "table drinks";
  gap: 16px;
  max-width: 780px;
  margin: 16px auto 0;
  padding: 0 16px;
  align-items: start;
}
.table-wrap { grid-area: table; }
.drinks { grid-area: drinks; }

.table-wrap {
  position: relative;
  background: var(--row-odd);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.wake-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 6px 8px;
  background: #f7f2e9;
  border-bottom: 1px solid var(--border);
  user-select: none;
  font-size: 0.9rem;
  color: var(--fg);
  touch-action: manipulation;
}
.wake-label strong { font-weight: 700; }
.wake-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--accent-strong);
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, border-color 120ms ease;
  touch-action: manipulation;
}
.wake-btn:hover { background: #fff5e6; border-color: var(--accent); }
.wake-btn:active { background: #ffe6c4; }

.hours {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.hours tr {
  transition: background 120ms ease;
  cursor: pointer;
}
.hours tr:hover { filter: brightness(0.97); }

.hours tr.hour-odd  { background: var(--row-odd); }
.hours tr.hour-even { background: var(--row-even); }

.hours tr.sleep { color: var(--sleep-fg); }
.hours tr.sleep.hour-odd  { background: var(--sleep-odd); }
.hours tr.sleep.hour-even { background: var(--sleep-even); }

.hours tr.warn .col-total { color: #a07212; font-weight: 700; }
.hours tr.warn.sleep .col-total { color: #f5c04a; font-weight: 700; }
.hours tr.alert .col-total { color: var(--alert); font-weight: 700; }
.hours tr.alert.sleep .col-total { color: #ff7a70; font-weight: 700; }

.hours td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.95rem;
}
.hours tr:last-child td { border-bottom: none; }

.col-total { width: 68px; font-variant-numeric: tabular-nums; font-weight: 600; }
.col-marker { width: 44px; text-align: center; font-size: 1.65rem; line-height: 1; }
.col-hour { width: 58px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hours tr.sleep .col-hour { color: #a8b2cc; }
.col-drinks { padding-left: 4px; cursor: pointer; min-height: 32px; }
.col-drinks:empty::before {
  content: "+";
  color: var(--muted);
  opacity: 0;
  font-size: 1.2rem;
}
.hours tr:hover .col-drinks:empty::before { opacity: 0.5; }

.drink-chip {
  display: inline-block;
  width: 44px;
  height: 44px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 2px;
  cursor: grab;
  padding: 2px;
  border-radius: 6px;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.drink-chip:active { cursor: grabbing; }
.drink-chip.chip-armed {
  transform: scale(1.15);
  background: rgba(184, 118, 58, 0.18);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.drink-chip:hover { background: rgba(196, 40, 27, 0.2); }
.hours tr.sleep .drink-chip:hover { background: rgba(255, 106, 94, 0.3); }

.hours tr.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #fff5e0 !important;
}
.hours tr.drop-target.sleep { background: #3a4a78 !important; }

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  width: 44px;
  height: 44px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  opacity: 0.9;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
  user-select: none;
  -webkit-user-drag: none;
}

/* Drink rail */
.drinks {
  position: sticky;
  top: 16px;
  background: var(--rail-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.drinks-title {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.drink-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.drink-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: grab;
  background: #fafafa;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  text-align: center;
}
.drink-item:active { cursor: grabbing; }
.drink-item:hover { background: #f2ece1; }
.drink-item.selected {
  border-color: var(--accent);
  background: #fff5e6;
  transform: scale(1.04);
}
.drink-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}
.drink-meta { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.drink-name { font-weight: 600; font-size: 0.9rem; }
.drink-mg { font-size: 0.75rem; color: var(--muted); }
.drinks-hint {
  margin: 10px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
}

.controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.control-halflife {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.control-halflife > span {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 4px;
  line-height: 1.1;
}
.control-halflife input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}
.control-halflife strong { color: var(--fg); font-weight: 700; }

.reset-btn {
  flex: 1 1 0;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--alert);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.reset-btn:hover { background: #fdecea; border-color: var(--alert); }
.reset-btn:active { background: #fbd8d4; }

.graph-wrap {
  max-width: 780px;
  margin: 8px auto 0;
  padding: 0 16px;
}
.graph-title {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 6px;
  font-weight: 600;
}
.graph {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.faq {
  max-width: 780px;
  margin: 80px auto 0;
  padding: 0 16px;
}
.faq h2 { font-size: 1.1rem; color: var(--muted); margin: 30px 0 8px; }
.faq ul { margin: 0; padding-left: 20px; color: var(--fg); }
.faq li { margin-bottom: 6px; line-height: 1.45; }

.site-footer {
  text-align: center;
  padding: 48px 16px 32px;
  margin-top: 24px;
}
.footer-logo {
  display: block;
  margin: 0 auto 8px;
  width: 96px;
  height: auto;
  max-width: 40%;
}
.footer-title {
  margin: 0 0 8px;
  font-size: 2.25rem;
  letter-spacing: -0.02em;
}
.site-footer a {
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 600;
}
.site-footer a:hover { text-decoration: underline; }

/* Mobile: stack, put drinks as a fixed bottom bar */
@media (max-width: 640px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "drinks"
      "table";
    padding: 0 10px;
  }
  .drinks {
    position: sticky;
    top: 0;
    border-radius: 0 0 12px 12px;
    padding: 8px 10px;
    z-index: 20;
  }
  .drinks-title { display: none; }
  .drinks-hint { display: none; }
  .drink-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .drink-item {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
  }
  .drink-icon { width: 28px; height: 28px; }
  .drink-meta { line-height: 1; align-items: center; }
  .drink-name { display: none; }
  .drink-mg { font-size: 0.68rem; }

  .hours td { padding: 12px 6px; font-size: 0.92rem; }
  .col-total { width: 56px; }
  .col-marker { width: 38px; font-size: 1.5rem; }
  .col-hour { width: 50px; }

  .controls { margin-top: 8px; gap: 6px; }
  .control-halflife > span { font-size: 0.65rem; }
  .reset-btn { padding: 4px 10px; font-size: 0.75rem; }
}
