/* LUCA Diary — tokens and every style in the app, in shell → view order. */

/* ---- tokens ------------------------------------------------------------- */

:root {
  --paper: #ffffff;
  --ink: #0a0a0a;
  --accent: #a6182c;
  --rose: #d6455a;
  --amber: #f9a82d;
  --muted: #6e6e6e;
  --rule: #e4e4e4;
  --slot: #f2f2f2;
  --panel: #141210;
  --panel-ink: #f3ede6;
  --panel-rule: #2a2521;
  --panel-link: #b9b0a5;
  --sans: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Space Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --gutter: clamp(20px, 4vw, 64px);
  --section-y: clamp(48px, 8vw, 110px);
  --grid-gap: clamp(8px, 1.4vw, 20px);

  /* layout */
  --measure: 1100px;
  --stream: 720px;
  --rail: 220px;
  --topbar-h: 52px;
  --tabbar-h: 60px;
}

/* ---- base --------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body.has-sheet {
  overflow: hidden;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

/* ---- shell -------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.topbar-label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.shell {
  display: block;
}

.main {
  min-height: 50vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

.main:focus {
  outline: none;
}

/* ---- left rail (desktop) ------------------------------------------------ */

.rail {
  display: none;
}

.rail-item {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  background: none;
  border: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-align: left;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}

.rail-item.is-active {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

.rail-out {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
}

/* ---- bottom tab bar (mobile) -------------------------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 1px solid var(--rule);
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 44px;
  padding: 0;
  background: none;
  border: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}

/* the outer tabs sit on the window edge, so the ring goes inside them */
.tab:focus-visible {
  outline-offset: -2px;
}

.tab.is-active:not(.tab-capture) {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

.tab-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--paper);
  transform: translateY(-8px);
}

.tab-dot svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

/* ---- login -------------------------------------------------------------- */

.is-locked .rail,
.is-locked .tabbar {
  display: none;
}

.login {
  max-width: 340px;
  margin: 0 auto;
  padding: 14vh var(--gutter) 0;
}

.login .field-input {
  margin-bottom: 14px;
}

.login .btn {
  width: 100%;
}

/* ---- forms and buttons -------------------------------------------------- */

.field {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-input {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.35;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
}

.field-input:focus {
  border-color: var(--ink);
}

.field-input::placeholder {
  color: var(--muted);
}

.field-mono {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.field-area {
  resize: none;
  overflow-y: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 2px;
  text-decoration: none;
  cursor: pointer;
}

.btn:disabled {
  color: var(--muted);
  border-color: var(--rule);
  cursor: default;
}

.btn-ink {
  background: var(--ink);
  color: var(--paper);
}

.btn-ink:disabled {
  background: var(--slot);
  color: var(--muted);
  border-color: var(--rule);
}

.btn-wide {
  width: 100%;
}

.btn-big {
  flex: 1 1 0;
  min-height: 88px;
}

.btn-danger {
  border-color: var(--rule);
  color: var(--muted);
}

.btn-danger.is-armed {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}

/* ---- diary stream ------------------------------------------------------- */

.stream {
  max-width: calc(var(--stream) + var(--gutter) * 2);
  margin-inline: auto;
  padding: 0 var(--gutter) 24px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 14px 0 0;
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.chip-x {
  font-size: 15px;
  color: var(--muted);
}

.day-heading {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  z-index: 2;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 14px 0 8px;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

/* The heading's own box stops at the gutter, but the photos under it bleed to
   the window edge. A backdrop that bleeds too keeps a photo from showing through
   the strips beside a stuck heading; the rule itself stays on the gutter. */
.day-heading::before {
  content: '';
  position: absolute;
  inset: 0 calc(var(--gutter) * -1);
  z-index: -1;
  background: var(--paper);
}

/* 44px of tap area without letting the sticky heading grow */
.month-print {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: -14px 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.entry {
  padding: 18px 0 30px;
}

.entry-main {
  display: block;
  width: 100%;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.caption {
  display: block;
  margin-top: 12px;
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.35;
}

.stamp {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.shot {
  display: block;
  width: 100%;
  background: var(--slot);
}

.shot-img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.shot-img.is-loaded {
  opacity: 1;
}

.shot-square .shot-img {
  height: 100%;
  object-fit: cover;
}

.entry-photo .shot {
  margin-inline: calc(var(--gutter) * -1);
  width: auto;
}

.entry-selfie {
  position: relative;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

/* the thumb sits outside the button, so the button covers the row instead */
.entry-selfie .entry-main::after {
  content: '';
  position: absolute;
  inset: 0;
}

.entry-selfie .shot {
  width: 96px;
}

.entry-selfie .caption,
.entry-selfie .stamp {
  margin-top: 0;
}

.entry-selfie .stamp {
  margin-top: 6px;
}

.entry-note .entry-main {
  padding-left: 14px;
  border-left: 2px solid var(--accent);
}

.entry-note .caption {
  margin-top: 0;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: -6px 0 0;
}

/* the tags share the text column; relative keeps them above the row's overlay */
.entry-selfie .tags {
  position: relative;
}

.entry-note .tags {
  padding-left: 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.stream-status,
.status,
.hint {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stream-status {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 8px 0 0;
  min-height: 18px;
}

.link-btn {
  min-height: 44px;
  padding: 0 2px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.stream-sentinel {
  height: 1px;
}

.empty {
  padding: 56px 0 24px;
}

.empty-mono {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.empty-sans {
  margin: 10px 0 0;
  font-size: 18px;
}

.empty-sans a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
}

/* ---- capture ------------------------------------------------------------ */

.capture {
  max-width: calc(var(--stream) + var(--gutter) * 2);
  margin-inline: auto;
  padding: 16px var(--gutter) 32px;
}

.kinds {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.kind {
  flex: 1 1 0;
  min-height: 44px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.kind.is-active {
  color: var(--ink);
  border-color: var(--ink);
}

.photo-area {
  margin-bottom: 14px;
}

.preview {
  margin: 0;
}

.preview-img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--slot);
}

.preview-actions,
.pickers {
  display: flex;
  gap: 10px;
}

.preview-actions {
  margin-top: 10px;
}

.capture-stamp {
  margin: 0 0 18px;
}

.caption-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.caption-row .field-area {
  max-height: calc(3 * 1.35em + 22px);
}

.mic {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--ink);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.mic svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

.mic.is-listening {
  color: var(--accent);
  border-color: var(--accent);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@keyframes mic-pulse {
  50% {
    opacity: 0.45;
  }
}

.interim {
  margin: 8px 0 0;
  color: var(--muted);
}

.interim:empty {
  margin: 0;
}

.hint,
.status {
  margin: 8px 0 0;
}

.status {
  min-height: 18px;
}

/* ---- today -------------------------------------------------------------- */

.today,
.selfies,
.health,
.settings {
  max-width: calc(var(--stream) + var(--gutter) * 2);
  margin-inline: auto;
  padding: 16px var(--gutter) 32px;
}

.today-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.today-title {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.day-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1;
  color: var(--ink);
  background: none;
  border: 0;
  cursor: pointer;
}

.day-step:disabled {
  color: var(--rule);
  cursor: default;
}

/* The autosave flag annotates the day it saved against, so it rides in the
   header beside the date rather than reserving a line above the first row. */
.saved {
  position: absolute;
  top: 50%;
  right: 52px;
  transform: translateY(-50%);
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.saved.is-fading {
  animation: saved-fade 1.4s ease forwards;
}

@keyframes saved-fade {
  0%,
  55% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 16px 0;
  border-bottom: 1px solid var(--rule);
}

.row-label {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* the first control in every row is 44px tall: sit the label on its centre line */
.row > .row-label {
  padding-top: 13px;
}

.row-body {
  min-width: 0;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.stepper-value {
  min-width: 92px;
  font-family: var(--mono);
  font-size: 24px;
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--ink);
}

.scale {
  width: max-content;
  max-width: 100%;
}

.scale-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
  border: 1px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
}

.dot.is-on {
  background: var(--accent);
  border-color: var(--accent);
}

.scale-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.weight {
  display: flex;
  align-items: center;
  gap: 10px;
}

.weight-input {
  width: 130px;
  font-size: 20px;
}

.unit {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.water {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.water-total {
  font-family: var(--mono);
  font-size: 18px;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.selfie-slot {
  width: 96px;
  height: 96px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: none;
  border: 1px dashed var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.selfie-taken {
  display: block;
  width: 96px;
}

.selfie-thumb {
  display: block;
  width: 96px;
  height: 96px;
  object-fit: cover;
  background: var(--slot);
}

.link-out {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-align: left;
  color: var(--ink);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.macros {
  margin-top: 2px;
}

.streak {
  display: inline-block;
  margin: 22px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* Amber marks a streak worth keeping; ink on the amber keeps the text readable. */
.streak.is-hot {
  padding: 5px 9px;
  color: var(--ink);
  background: var(--amber);
  border-radius: 2px;
}

/* ---- selfies ------------------------------------------------------------ */

.selfies-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.selfies-head .stream-status {
  margin: 0;
}

.selfie-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--grid-gap);
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.selfie-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.selfie-img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--slot);
}

.selfie-day {
  display: block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.lapse {
  padding-top: 16px;
}

.lapse-stage {
  display: block;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  background: var(--slot);
  border: 1px solid var(--rule);
  border-radius: 2px;
}

/* Under reduced motion the stage is a plain box, not a control. */
button.lapse-stage {
  cursor: pointer;
}

.lapse-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lapse-stamp {
  max-width: 420px;
  margin: 10px auto 0;
  text-align: center;
}

.lapse-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.lapse-range {
  width: 220px;
  min-height: 44px;
  accent-color: var(--accent);
}

/* ---- health ------------------------------------------------------------- */

.health-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.ranges {
  display: flex;
  gap: 8px;
}

.range-btn {
  min-width: 60px;
  min-height: 44px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.range-btn.is-active {
  color: var(--ink);
  border-color: var(--ink);
}

.stat-strip {
  margin: 18px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.chart {
  padding: 16px 0;
  border-bottom: 1px solid var(--rule);
}

.chart-label {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.chart-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.chart-holder {
  flex: 1 1 auto;
  min-width: 0;
}

.chart-svg {
  display: block;
}

.chart-scale {
  flex: 0 0 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-align: right;
  color: var(--muted);
}

.chart-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-bar,
.chart-point {
  fill: var(--ink);
}

.chart-today {
  fill: var(--accent);
}

.chart-axis {
  stroke: var(--rule);
  stroke-width: 1;
}

.pattern {
  padding: 16px 0 0;
}

/* ---- map ---------------------------------------------------------------- */

.map-view {
  padding-bottom: 20px;
}

.map-canvas {
  width: 100%;
  /* fill what is left between the top bar and the tab bar */
  height: calc(100vh - var(--topbar-h) - var(--tabbar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 64px);
  height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 64px);
  min-height: 320px;
  background: var(--slot);
}

.map-canvas.leaflet-container .leaflet-tile-pane {
  filter: grayscale(1) contrast(1.05);
}

.map-canvas.leaflet-container {
  font-family: var(--sans);
}

.pin {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
}

/* Leaflet ships rounded, shadowed chrome; bring it back to paper and rule. */
.map-canvas.leaflet-container .leaflet-popup-content-wrapper,
.map-canvas.leaflet-container .leaflet-popup-tip {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: none;
}

/* The tip is a rotated square: only the two edges that face out should show. */
.map-canvas.leaflet-container .leaflet-popup-tip {
  border-top: 0;
  border-left: 0;
}

.map-canvas.leaflet-container .leaflet-popup-content {
  margin: 10px 12px;
  font-family: var(--sans);
}

.map-canvas.leaflet-container .leaflet-popup-close-button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-family: var(--mono);
  font-size: 16px;
  line-height: 44px;
  color: var(--muted);
}

.map-canvas.leaflet-container .leaflet-control-zoom {
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: none;
}

.map-canvas.leaflet-container .leaflet-control-zoom a {
  width: 44px;
  height: 44px;
  font-family: var(--mono);
  font-size: 18px;
  line-height: 44px;
  color: var(--ink);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
}

.map-canvas.leaflet-container .leaflet-control-zoom a:last-child {
  border-bottom: 0;
}

.map-canvas.leaflet-container .leaflet-control-zoom a.leaflet-disabled {
  color: var(--rule);
  background: var(--paper);
}

/* The map bleeds to the window edge on a phone; Leaflet's own `margin:0` would
   run the plate into the corner, so it keeps the app's gutter instead. */
.map-canvas.leaflet-container .leaflet-control-attribution {
  margin-right: var(--gutter);
  padding: 3px 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--paper);
  border-radius: 0;
}

.map-canvas.leaflet-container .leaflet-control-attribution a {
  color: var(--muted);
}

.map-popup {
  display: block;
  color: var(--ink);
  text-decoration: none;
}

.map-thumb {
  display: block;
  width: 168px;
  height: 126px;
  margin-bottom: 6px;
  object-fit: cover;
  background: var(--slot);
}

.map-view .status,
.map-view .hint,
.map-view .empty {
  padding-inline: var(--gutter);
}

/* ---- settings ----------------------------------------------------------- */

.set-row {
  padding: 16px 0;
  border-bottom: 1px solid var(--rule);
}

.set-row:last-child {
  border-bottom: 0;
}

.set-url {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink);
  word-break: break-all;
}

.set-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.set-steps {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1.8;
  color: var(--muted);
}

.set-note {
  margin: 10px 0 0;
  font-size: 16px;
  line-height: 1.45;
}

/* ---- print: single photo ------------------------------------------------ */

.print {
  max-width: calc(var(--stream) + var(--gutter) * 2);
  margin-inline: auto;
  padding: 16px var(--gutter) 32px;
}

.print-head {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.print-title {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.print-head .stamp {
  margin-top: 6px;
}

.print-sub {
  margin: 10px 0 6px;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.month-list {
  display: flex;
  flex-direction: column;
}

.month-link {
  display: flex;
  align-items: center;
  min-height: 52px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}

/* the stage tracks the photo's own shape, capped so the controls stay in view */
.crop-stage {
  position: relative;
  width: min(100%, calc(56 * var(--crop-ratio) * 1vh));
  margin-inline: auto;
  overflow: hidden;
  aspect-ratio: var(--crop-ratio);
  background: var(--slot);
  touch-action: none;
}

.crop-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.crop-window {
  position: absolute;
  padding: 0;
  background: none;
  border: 1px solid var(--paper);
  /* everything outside the window sits under an ink scrim */
  box-shadow: 0 0 0 9999px rgba(10, 10, 10, 0.5);
  cursor: grab;
  touch-action: none;
}

.crop-window.is-dragging {
  cursor: grabbing;
}

.crop-corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--paper);
}

.crop-tl {
  top: -1px;
  left: -1px;
  border-right: 0;
  border-bottom: 0;
}

.crop-tr {
  top: -1px;
  right: -1px;
  border-left: 0;
  border-bottom: 0;
}

.crop-bl {
  bottom: -1px;
  left: -1px;
  border-right: 0;
  border-top: 0;
}

.crop-br {
  bottom: -1px;
  right: -1px;
  border-left: 0;
  border-top: 0;
}

.print-quality {
  margin: 14px 0 18px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* amber marks a crop that will print soft; ink on amber keeps it readable */
.print-quality.is-soft {
  display: inline-block;
  padding: 5px 9px;
  color: var(--ink);
  background: var(--amber);
  border-radius: 2px;
}

.picks {
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

.picks-legend {
  padding: 0;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.picks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pick {
  position: relative;
  display: inline-flex;
}

.pick-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.pick-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
}

.pick-input:checked + .pick-face {
  color: var(--ink);
  border-color: var(--ink);
}

.pick-input:disabled + .pick-face {
  color: var(--rule);
  border-color: var(--rule);
  cursor: default;
}

.pick-input:focus-visible + .pick-face {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.print-field {
  margin-bottom: 12px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.print-range {
  flex: 1 1 auto;
  max-width: 260px;
  min-height: 44px;
  accent-color: var(--accent);
}

.range-value {
  min-width: 46px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
  cursor: pointer;
}

.check-input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.print-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* the single-photo print sheet is built off screen and printed by print.css */
.print-single {
  position: absolute;
  left: -9999px;
  top: 0;
}

/* ---- print: month spread ------------------------------------------------ */

.print-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-top: 14px;
}

.picks-tight {
  margin-bottom: 0;
}

.print-status {
  margin: 12px 0 0;
}

/* the preview is the printed sheet itself, scaled down to the viewport */
.print-preview {
  overflow: hidden;
  margin-top: 16px;
  border: 1px solid var(--rule);
  background: var(--paper);
}

.print-sheet {
  width: 186mm;
  table-layout: fixed;
  border-collapse: collapse;
  transform-origin: top left;
  background: var(--paper);
  color: var(--ink);
}

.print-sheet.is-a5 {
  width: 128mm;
}

.sheet-block {
  padding-bottom: 8mm;
}

/* the table header: once at the top on screen, on every page in print. The gap
   under the rule is the header's own padding, so it repeats with it. */
.sheet-runner {
  padding: 0 0 5mm;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 8pt;
  letter-spacing: 0.08em;
  text-align: left;
  color: var(--ink);
}

.sheet-runner-line {
  display: block;
  padding-bottom: 2mm;
  border-bottom: 0.3mm solid var(--ink);
}

.sheet-cell {
  padding: 0;
  vertical-align: top;
}

/* the gap above a date rule is padding, not margin: a margin is dropped where a
   day group fragments, and the rule would then sit on the entry above it */
.sheet-day {
  margin: 0 0 2mm;
  padding-top: 2mm;
  padding-bottom: 1.5mm;
  font-family: var(--mono);
  font-size: 7.5pt;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 0.2mm solid var(--rule);
}

.sheet-row {
  display: flex;
  align-items: flex-start;
  gap: 8mm;
  /* padding, again so the space survives a page break inside the day */
  padding-bottom: 4mm;
}

.sheet-item {
  flex: 0 0 calc(50% - 4mm);
  min-width: 0;
  margin: 0;
}

/* the photo block is capped so three rows of entries fit an A4 page; on A5 the
   column is already narrower than the cap */
.sheet-slot,
.sheet-meta {
  max-width: 60mm;
}

.sheet-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--slot);
}

.sheet-photo {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.sheet-meta {
  display: block;
  margin: 1.5mm 0 0;
}

.sheet-item-note .sheet-meta {
  padding-left: 3mm;
  border-left: 0.6mm solid var(--accent);
}

.sheet-caption {
  display: block;
  font-family: var(--sans);
  font-size: 10pt;
  line-height: 1.3;
}

.sheet-stamp {
  display: block;
  margin-top: 1mm;
  font-family: var(--mono);
  font-size: 7.5pt;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet-section {
  margin: 0 0 4mm;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 9pt;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.faces {
  display: flex;
  flex-wrap: wrap;
  gap: 2mm;
}

.face {
  display: block;
  width: 1.6cm;
  height: 1.6cm;
  object-fit: cover;
  background: var(--slot);
}

.numbers {
  max-width: 92mm;
}

.sheet-number {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6mm;
  padding: 2.5mm 0;
  border-bottom: 0.2mm solid var(--rule);
}

.sheet-number-label {
  font-family: var(--mono);
  font-size: 8pt;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.sheet-number-value {
  font-family: var(--mono);
  font-size: 11pt;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.sheet-empty {
  margin: 0;
  font-family: var(--mono);
  font-size: 9pt;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* ---- sheet -------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  /* scrim: --ink at 45% */
  background: rgba(10, 10, 10, 0.45);
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 88vh;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-radius: 2px 2px 0 0;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px var(--gutter);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.sheet-title {
  margin: 0;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}

.sheet-close {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 2px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}

.sheet-close-mark {
  font-size: 15px;
}

.sheet-body {
  overflow-y: auto;
  padding: 18px var(--gutter) 28px;
  -webkit-overflow-scrolling: touch;
}

.detail-photo {
  display: block;
  width: auto;
  max-width: 100%;
  /* keep the caption and the actions reachable under a tall photo */
  max-height: 60vh;
  margin: 0 auto 20px;
  background: var(--slot);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.more {
  display: flex;
  flex-direction: column;
}

.more-item {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-align: left;
  color: var(--ink);
  text-decoration: none;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}

.more-out {
  color: var(--muted);
  border-bottom: 0;
}

/* ---- toast -------------------------------------------------------------- */

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter);
  pointer-events: none;
}

/* Locked out there is no tab bar to clear, so the toast sits on the safe area. */
.app.is-locked ~ .toast-host {
  bottom: calc(env(safe-area-inset-bottom) + 24px);
}

/* A sheet fills the bottom of the screen; a toast there would land on the form.
   Reset in the desktop block, where the sheet is centred instead. */
body.has-sheet .toast-host {
  top: calc(env(safe-area-inset-top) + var(--topbar-h) + 12px);
  bottom: auto;
}

.toast {
  margin: 0;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
}

/* ---- desktop ------------------------------------------------------------ */

@media (min-width: 900px) {
  .shell {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr);
    gap: var(--grid-gap);
    max-width: var(--measure);
    margin-inline: auto;
  }

  /* The sticky offset is the rail's own box, so it matches the top bar and the
     padding below does the spacing — otherwise the two stack and the rail drops
     a second gap on any page long enough to scroll. */
  .rail {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--topbar-h);
    align-self: start;
    padding: 16px 0 0 var(--gutter);
  }

  .tabbar {
    display: none;
  }

  .is-locked .shell {
    display: block;
  }

  .main {
    padding-bottom: var(--section-y);
  }

  .topbar {
    /* the wordmark lines up with the rail, the label with the stream's far edge */
    padding-left: max(var(--gutter), calc((100% - var(--measure)) / 2 + var(--gutter)));
    padding-right: max(
      var(--gutter),
      calc(100% - max(0px, (100% - var(--measure)) / 2) - var(--rail) - var(--grid-gap) - var(--stream))
    );
  }

  .stream,
  .capture,
  .today,
  .selfies,
  .health,
  .print,
  .settings,
  .map-view {
    max-width: var(--stream);
    margin-inline: 0;
    padding-left: 0;
    padding-right: 0;
  }

  /* every view opens on the same line as the rail's first item */
  .stream {
    padding-top: 16px;
  }

  /* on desktop nothing bleeds past the stream, so the backdrop needs no gutters */
  .day-heading::before {
    display: none;
  }

  .row {
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 16px;
  }

  .selfie-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .map-view {
    padding-top: 16px;
  }

  .map-canvas {
    height: calc(100vh - var(--topbar-h) - 112px);
    height: calc(100dvh - var(--topbar-h) - 112px);
  }

  .map-view .status,
  .map-view .hint,
  .map-view .empty {
    padding-inline: 0;
  }

  .entry-photo .shot {
    margin-inline: 0;
    width: 100%;
  }

  .toast-host {
    bottom: 24px;
  }

  /* The sheet is centred here rather than stuck to the bottom, so the toast
     stays down — tucked into the strip the sheet's 86vh cap always leaves. */
  body.has-sheet .toast-host {
    top: auto;
    bottom: 12px;
  }

  /* the map stops at the stream here, so the plate needs no gutter of its own */
  .map-canvas.leaflet-container .leaflet-control-attribution {
    margin-right: 0;
  }

  .sheet-backdrop {
    align-items: center;
  }

  .sheet {
    max-width: var(--stream);
    max-height: 86vh;
    border-radius: 2px;
  }

  .detail-photo {
    max-height: 46vh;
  }

  .login {
    padding-top: 12vh;
  }
}

/* ---- motion ------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
