:root {
  --stage: #14110e;
  --paper: #f4eee4;
  --ink: #1c1410;
  --muted: #6d6258;
  --line: #e0d4c4;
  --mark: #f2c14e;
  --header: 48px;
  --tray: 72px;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--stage);
  color: var(--paper);
  font-family: var(--sans);
  user-select: none;
  touch-action: manipulation;
}

button,
a {
  touch-action: manipulation;
}

.top {
  position: sticky;
  top: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  height: calc(var(--header) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0;
  background: var(--stage);
}

.brand {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: rgba(244, 238, 228, 0.55);
  text-decoration: none;
}

.brand:hover {
  color: var(--paper);
}

.app-name {
  justify-self: center;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  color: var(--paper);
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
  cursor: pointer;
}

.app-name[aria-expanded="true"] {
  color: var(--mark);
}

.share {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  justify-self: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(244, 238, 228, 0.55);
  cursor: pointer;
}

.share:hover,
.share:focus-visible {
  color: var(--paper);
}

.share.is-copied {
  color: var(--mark);
}

.share:focus-visible {
  outline: 1px solid var(--mark);
  outline-offset: -6px;
  border-radius: 8px;
}

.share-check {
  display: none;
}

.share.is-copied .share-icon {
  display: none;
}

.share.is-copied .share-check {
  display: block;
}

.share-tip {
  position: absolute;
  top: 50%;
  right: calc(100% - 4px);
  transform: translateY(-50%);
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--mark);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}

.app-menu:not([hidden]) {
  position: sticky;
  top: calc(var(--header) + env(safe-area-inset-top));
  z-index: 6;
  display: flex;
  flex-direction: column;
  padding: 4px 16px 12px;
  background: var(--stage);
  border-bottom: 1px solid rgba(244, 238, 228, 0.08);
}

.app-menu a {
  padding: 12px 8px;
  color: var(--paper);
  font-size: 16px;
  text-decoration: none;
}

.app-menu a[aria-current="page"] {
  color: var(--mark);
}

.fold {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header) - var(--tray) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1.55 1 0;
}

.panel:not(.clear-panel) {
  margin-bottom: 8px;
}

.clear-panel {
  flex: 1.2 1 0;
  background: #181410;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 4px 8px 0 14px;
}

.panel h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--paper);
}

.help {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(244, 238, 228, 0.18);
  border-radius: 50%;
  background: transparent;
  color: rgba(244, 238, 228, 0.4);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
}

.help[aria-expanded="true"] {
  border-color: var(--mark);
  color: var(--mark);
  font-size: 18px;
}

.clear-head {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
}

.clear-head .panel-head {
  padding-bottom: 0;
}

.clear-head #sleep-readout {
  padding: 0 14px 2px;
}

.panel.is-flipped #sleep-readout {
  display: none;
}

.flip {
  flex: 1 1 auto;
  min-height: 0;
  perspective: 900px;
}

.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s ease;
  transform-style: preserve-3d;
}

.panel.is-flipped .flip-inner {
  transform: rotateY(180deg);
}

.flip-front,
.flip-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-front {
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}

.panel.is-flipped .flip-front {
  pointer-events: none;
}

.panel.is-flipped .dose-handle,
.panel.is-flipped .clear-marks {
  visibility: hidden;
}

.flip-back {
  pointer-events: none;
}

.panel.is-flipped .flip-back {
  pointer-events: auto;
}

.flip-front .dose-wrap,
.flip-front .clear-wrap,
.flip-front > svg {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.flip-back {
  overflow: auto;
  padding: 4px 14px 14px;
  transform: rotateY(180deg);
  user-select: text;
  -webkit-overflow-scrolling: touch;
}

.notes-lead {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-align: center;
  color: rgba(244, 238, 228, 0.4);
}

.flip-back dl {
  margin: 0;
}

.flip-back dt {
  margin: 12px 0 4px;
  font-family: var(--serif);
  font-size: clamp(16px, 4.8vw, 22px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 0.95;
  text-align: center;
  color: var(--paper);
}

.flip-back dt:first-child {
  margin-top: 2px;
}

.flip-back dd {
  margin: 0 auto;
  max-width: 34em;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(244, 238, 228, 0.78);
}

.flip-back .cite {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: rgba(244, 238, 228, 0.4);
}

.clear-head p {
  margin: 0;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: rgba(244, 238, 228, 0.62);
}

.clear-head em {
  font-style: normal;
  color: #ff8a65;
}

.panel svg {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: none;
  cursor: ew-resize;
}

.dose-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.dose-plot {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.dose-plot svg,
.clear-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

.clear-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.dose-hud {
  position: relative;
  flex: 0 0 auto;
  height: 28px;
  pointer-events: none;
}

.dose-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2px;
  width: max-content;
  min-width: 48px;
  transform: translateX(-50%);
  cursor: ew-resize;
  touch-action: none;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.dose-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--mark);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

.dose-pill::before,
.dose-pill::after {
  content: "";
  width: 7px;
  height: 10px;
  opacity: 0.42;
  background:
    linear-gradient(currentColor, currentColor) left / 1.5px 100% no-repeat,
    linear-gradient(currentColor, currentColor) right / 1.5px 100% no-repeat;
}

.dose-scale {
  flex: 0 0 auto;
  padding: 2px 0 0;
}

.dose-axis {
  position: relative;
  height: 13px;
}

.dose-axis span {
  position: absolute;
  top: 0;
  color: rgba(244, 238, 228, 0.45);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 1;
  transform: translateX(-50%);
  white-space: nowrap;
}

.dose-unit {
  margin: 3px 0 0;
  text-align: center;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: rgba(244, 238, 228, 0.38);
}

.clear-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.clear-mark {
  position: absolute;
  transform: translate(-50%, -140%);
  color: #f2c14e;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

.sleep-band-label,
.quiet-label {
  position: absolute;
  transform: translateX(-50%);
  color: rgba(244, 238, 228, 0.62);
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-align: center;
}

.sleep-band-label {
  font-size: 11px;
}

.quiet-label {
  transform: translate(-100%, -130%);
  text-align: right;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

#clear-axis {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3px;
  height: 16px;
  pointer-events: none;
}

.dose-stamps {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ridge-stamp {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-family: var(--serif);
  font-size: clamp(16px, 4.8vw, 22px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 0.9;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(10, 8, 6, 0.35);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tray) + env(safe-area-inset-bottom));
  z-index: 9;
  padding: 2px 16px 14px;
  background: var(--paper);
  color: var(--ink);
  border-top: 1px solid var(--line);
}

.sheet-dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(100% + 32px);
  height: 30px;
  margin: 0 -16px 2px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.sheet-dismiss span {
  width: 9px;
  height: 9px;
  margin-top: -1px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(45deg);
}

.sheet-dismiss:hover span {
  border-color: var(--ink);
}

.editor {
  display: none;
  min-height: 168px;
}

.sheet[data-open="age"] [data-editor="age"],
.sheet[data-open="weight"] [data-editor="weight"],
.sheet[data-open="dose"] [data-editor="dose"] {
  display: flex;
  flex-direction: column;
}

.sheet[data-open="time"] [data-editor="time"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.editor-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.field-label {
  margin: 12px 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label:first-child {
  margin-top: 0;
}

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

.stepper button,
.chip {
  min-height: 44px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.stepper button {
  flex: 0 0 48px;
  width: 48px;
  font-size: 24px;
  line-height: 1;
  padding: 0;
}

.stepper-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.stepper-value input {
  width: 3.15em;
  min-width: 3.15em;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(36px, 11vw, 44px);
  font-weight: 500;
  letter-spacing: -0.03em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -webkit-appearance: none;
}

.stepper-value input::-webkit-outer-spin-button,
.stepper-value input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper-value input + span,
.meta {
  color: var(--muted);
  font-size: 14px;
}

.meta {
  margin: 10px 0 0;
  text-align: center;
  min-height: 1.2em;
}

.stepper-clock {
  display: block;
  min-width: 0;
  font-family: var(--serif);
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
  text-align: center;
  white-space: nowrap;
}

.editor-split .chips {
  margin-left: 0;
  margin-right: 0;
  padding-left: 0;
  padding-right: 0;
}

.editor-split .stepper {
  gap: 6px;
}

.editor-split .stepper button {
  flex: 0 0 44px;
  width: 44px;
}

.editor-split .stepper-value {
  min-width: 0;
}

.chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 0 -16px 10px;
  padding: 0 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chip {
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 14px;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

input[type="range"] {
  width: 100%;
  margin: 2px 0 10px;
  accent-color: #c45e1a;
}

input[type="time"] {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-bottom: 4px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff8ee;
  color: var(--ink);
  font: inherit;
  font-size: 18px;
}

.tray {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  height: calc(var(--tray) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  color: var(--ink);
  border-top: 1px solid var(--line);
}

.tray-inner {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: var(--tray);
  max-width: 640px;
  margin: 0 auto;
}

.tray-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 6px 4px 5px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.tray-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 7px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ebe3d6;
}

.tray-item[aria-pressed="true"] .tray-field {
  border-color: var(--ink);
  background: #e0d4c4;
}

.tray-item strong {
  max-width: 100%;
  font-family: var(--serif);
  font-size: clamp(15px, 4.6vw, 18px);
  font-weight: 500;
  letter-spacing: -0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tray-caret {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  margin-top: 1.5px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-135deg);
  transition:
    transform 160ms ease,
    border-color 160ms ease;
}

.tray-item[aria-pressed="true"] .tray-caret {
  margin-top: -1px;
  border-color: var(--ink);
  transform: rotate(45deg);
}

.tray-item > span:last-child {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

@media (min-width: 800px) {
  .sheet {
    left: 50%;
    right: auto;
    width: min(520px, 100%);
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-bottom: 0;
  }

  .fold {
    max-width: 1100px;
    margin: 0 auto;
  }
}
