:root {
  --bg: #f7f3ee;
  --bg-card: #fffcf8;
  --ink: #2c2a28;
  --ink-soft: #6b6560;
  --line: #e8e0d6;
  --accent: #7a9e8e;
  --accent-deep: #5a7d6e;
  --accent-soft: #e4efe9;
  --warm: #d4a574;
  --warm-soft: #f5ebe0;
  --rose: #c97b84;
  --rose-soft: #f8e8ea;
  --sky: #7a9eb8;
  --sky-soft: #e6f0f5;
  --done: #5a7d6e;
  --pending: #c4b8a8;
  --shadow: 0 4px 16px rgba(60, 45, 30, 0.07);
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 44px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

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

body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse at top, #fff9f2 0%, var(--bg) 55%),
    var(--bg);
  line-height: 1.35;
}

button, input, select {
  font: inherit;
  color: inherit;
}

.app {
  max-width: 430px;
  margin: 0 auto;
  height: 100%;
  max-height: 100dvh;
  padding:
    max(8px, env(safe-area-inset-top))
    12px
    max(8px, env(safe-area-inset-bottom))
    12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

/* Header — compact */
.header {
  flex-shrink: 0;
  padding: 0 2px;
}

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

.brand { min-width: 0; }

.logo {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-deep);
  line-height: 1.1;
}

.day-meta {
  margin: 2px 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--warm-soft);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn.sm {
  min-height: 36px;
  min-width: 36px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover { background: var(--accent-deep); }

.hint {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* Last event banner — unmistakable */
.last-banner {
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

.last-banner.flash {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 158, 142, 0.28), var(--shadow);
  animation: last-pulse 0.85s ease;
}

.last-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin-bottom: 2px;
}

.last-main {
  font-size: 1.22rem;
  font-weight: 750;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--ink);
}

.last-meta:empty { display: none; }

.last-meta {
  margin-top: 3px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 500;
  &:empty { display: none; }
}

@keyframes last-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

/* Today counts — feed/meds prominent, diapers below */
.summary {
  flex-shrink: 0;
}

.summary-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-pill {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  min-height: 56px;
  text-align: left;
}

.summary-pill .emoji { font-size: 1.35rem; line-height: 1; flex-shrink: 0; }
.summary-pill .pill-body { min-width: 0; flex: 1; }
.summary-pill .label {
  font-size: 0.68rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.summary-pill .count {
  font-size: 1.15rem;
  font-weight: 750;
  line-height: 1.1;
}
.summary-pill.prominent {
  min-height: 84px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  background: var(--bg-card);
}
.summary-pill.prominent .emoji { font-size: 1.7rem; }
.summary-pill.prominent .count { font-size: 1.45rem; }
.summary-pill.secondary {
  min-height: 52px;
  padding: 8px 10px;
  opacity: 0.96;
}
.summary-pill.secondary .emoji { font-size: 1.15rem; }
.summary-pill.secondary .count { font-size: 1.05rem; }

.summary-pill .next-block {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.summary-pill .next-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.summary-pill .next-time {
  font-size: 1.05rem;
  font-weight: 750;
  color: var(--accent-deep);
  line-height: 1.1;
}
.summary-pill.meds .next-time { color: var(--rose); }
.summary-pill.meds { background: var(--rose-soft); }
.summary-pill.meds.prominent { background: #fff5f6; border-color: #efd0d4; }
.summary-pill.feed.prominent { background: #f3faf6; border-color: #cfe0d7; }
.summary-pill.sleep { background: var(--sky-soft); }
.summary-pill.dirty { background: var(--warm-soft); }
.summary-pill.wet { background: var(--sky-soft); }

/* Gentle nudge — one line */
.gentle-nudge {
  flex-shrink: 0;
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--warm-soft);
  border: 1px solid #e8d4bc;
  color: #6b5340;
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gentle-nudge[hidden] { display: none !important; }

.gentle-nudge .nudge-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--warm);
  margin-right: 4px;
}

/* Clock — square face that fits available space without clipping */
.clock-section {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  overflow: hidden; /* clip to card; padding keeps face/hand inside */
}

.clock-wrap {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  container-type: size;
  overflow: visible;
}

#clock {
  display: block;
  width: min(100cqw, 100cqh, 100%, 420px);
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  touch-action: manipulation;
  overflow: visible;
  flex: 0 0 auto;
}

.clock-face {
  fill: #fffaf5;
  stroke: var(--line);
  stroke-width: 2;
  filter: url(#softShadow);
}

.clock-ring {
  fill: none;
  stroke: #efe6db;
  stroke-width: 1.5;
  stroke-dasharray: 3 5;
}

.tick {
  stroke: #d8cfc3;
  stroke-width: 1.5;
  stroke-linecap: round;
}
.tick.major {
  stroke: #b8aa98;
  stroke-width: 2.2;
}

.hour-label {
  fill: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
}

.clock-hand {
  stroke: var(--rose);
  stroke-width: 3.5;
  stroke-linecap: round;
  /* Rotation is SVG transform in user units — do not set CSS transform-origin */
}

.clock-hub { fill: var(--rose); }

.clock-now {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
}

.marker {
  cursor: pointer;
  transition: transform 0.12s ease;
}
.marker:active { transform: scale(0.92); }

.marker-dot { stroke-width: 2.5; }
.marker.pending .marker-dot {
  fill: #fff;
  stroke: var(--pending);
}
.marker.done .marker-dot {
  fill: var(--done);
  stroke: var(--done);
}
.marker.missed .marker-dot {
  fill: var(--warm-soft);
  stroke: var(--warm);
}

.marker-emoji {
  font-size: 11px;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

/* Quick log */
.quick-add {
  flex-shrink: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  justify-content: stretch;
  width: 100%;
  padding: 0 2px;
}

.quick-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex: 1 1 0;
  justify-content: center;
  min-width: 0;
  min-height: 40px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75rem;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.quick-btn:active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Ring status bar — compact footer */
.ring-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  min-height: 40px;
  overflow: hidden;
}

.ring-live-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 158, 142, 0.22);
  animation: live-blink 1.8s ease-in-out infinite;
}

.ring-bar.is-offline .ring-live-dot {
  background: var(--warm);
  box-shadow: none;
  animation: none;
}

.ring-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

.ring-badge .badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.ring-badge.offline { color: #8a6a45; }
.ring-badge.offline .badge-dot { background: var(--warm); }

.ring-source {
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
}

.ring-sync {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Dialog */
.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(440px, calc(100vw - 24px));
  width: 100%;
  max-height: min(90dvh, 640px);
  box-shadow: 0 20px 50px rgba(40, 30, 20, 0.2);
  background: var(--bg-card);
  overflow: auto;
}

.dialog::backdrop {
  background: rgba(40, 30, 20, 0.35);
}

.dialog-inner {
  padding: 20px;
  margin: 0;
}

.dialog-inner h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.settings-list {
  list-style: none;
  margin: 14px 0;
  padding: 0;
}

.settings-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.settings-list .emoji {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
}

.settings-list input[type="text"] {
  flex: 1;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.settings-add {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 16px;
}

.settings-add input {
  flex: 1;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.settings-add select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

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

/* Short phones: shrink clock further */
@media (max-height: 700px) {
  .app { gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); }
  .last-main { font-size: 1.08rem; }
  .last-banner { padding: 10px 12px; }
  .summary-pill { min-height: 48px; padding: 6px 2px; }
  .clock-section { min-height: 180px; }
  #clock { width: min(100cqw, 100cqh, 100%, 280px); }
  .quick-btn { min-height: 36px; padding: 0 10px; font-size: 0.78rem; }
}

@media (max-height: 620px) {
  .day-meta { display: none; }
  /* Keep Next times visible even on short phones */
  .clock-section { min-height: 160px; }
  #clock { width: min(100cqw, 100cqh, 100%, 220px); }
  .gentle-nudge { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .marker, .last-banner { transition: none; }
  .last-banner.flash { animation: none; }
  .ring-live-dot { animation: none; }
}

/* Dashboard layout: the information column stays left; the day clock stays right. */
.dashboard {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.main-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-section {
  flex-shrink: 0;
  padding: 0;
}

/* Dashboard clock: square via container queries; padding keeps face unclipped. */
.clock-section {
  height: 100%;
}

.clock-wrap {
  overflow: hidden;
}

#clock {
  margin: auto;
}

@media (max-height: 700px) {
  .summary-pill.prominent { min-height: 72px; padding: 10px 12px; }
  .summary-pill.prominent .next-time { font-size: 0.95rem; }
  .summary-pill.secondary { min-height: 46px; }
}

@media (max-height: 620px) {
  .summary-pill .label { font-size: 0.6rem; }
  .summary-pill.prominent { min-height: 64px; padding: 8px 10px; }
  .summary-pill.prominent .count { font-size: 1.2rem; }
  .summary-pill.prominent .next-time { font-size: 0.9rem; }
}

/* Tablet/landscape/desktop: main column + quick taps left, full clock right. */
@media (min-width: 760px) and (orientation: landscape), (min-width: 900px) {
  .app {
    max-width: 1200px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    gap: 12px;
  }

  .dashboard {
    grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 14px;
  }

  .main-column { gap: 10px; }
  .summary-grid { gap: 10px; }
  .summary-row { gap: 10px; }
  .summary-pill.prominent {
    min-height: 108px;
    padding: 16px 14px;
  }
  .summary-pill.prominent .emoji { font-size: 2rem; }
  .summary-pill.prominent .label { font-size: 0.78rem; }
  .summary-pill.prominent .count { font-size: 1.7rem; }
  .summary-pill.prominent .next-time { font-size: 1.25rem; }
  .summary-pill.secondary {
    min-height: 64px;
    padding: 12px 12px;
  }
  .summary-pill.secondary .count { font-size: 1.25rem; }

  .clock-section { padding: 16px; min-height: 280px; }
  #clock { width: min(100cqw, 100cqh, 100%, 520px); }
  .quick-btn { min-height: 48px; font-size: 0.82rem; }
}


/* DEMO clock toggle — unmistakable when active */
.btn.demo {
  border: 1px solid #c97b84;
  background: #fff;
  color: #a14d57;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-width: 4.5rem;
}
.btn.demo.is-on,
body.demo-on .btn.demo {
  background: #c97b84;
  color: #fff;
  border-color: #a14d57;
  box-shadow: 0 0 0 2px rgba(201, 123, 132, 0.35);
  animation: demo-pulse 1.4s ease-in-out infinite;
}
@keyframes demo-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(201, 123, 132, 0.25); }
  50% { box-shadow: 0 0 0 4px rgba(201, 123, 132, 0.45); }
}
@media (prefers-reduced-motion: reduce) {
  .btn.demo.is-on { animation: none; }
}

.demo-banner {
  flex-shrink: 0;
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: #c97b84;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
}
.demo-banner[hidden] { display: none !important; }

body.demo-on .clock-hand {
  stroke: #c97b84;
}
body.demo-on .clock-now {
  fill: #a14d57;
}
