:root {
  color-scheme: light;
  --bg: #eef5f1;
  --ink: #1c2b26;
  --muted: #5d726a;
  --line: rgba(28, 43, 38, 0.1);
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --accent: #2f6f5e;
  --accent-soft: #d7ebe3;
  --rose: #b56b6a;
  --rose-soft: #f3e0de;
  --avg: #3d6f8f;
  --danger: #9b3d3d;
  --shadow: 0 18px 40px rgba(40, 70, 58, 0.08);
  --radius: 22px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
}

.hidden { display: none !important; }

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background:
    linear-gradient(180deg, #e7f2ec 0%, #f3efe8 48%, #eef4f0 100%);
}

.wash {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.7;
  animation: drift 18s ease-in-out infinite alternate;
}

.wash-a {
  width: 55vmax;
  height: 55vmax;
  top: -18vmax;
  right: -12vmax;
  background: radial-gradient(circle, rgba(181, 214, 201, 0.9), transparent 68%);
}

.wash-b {
  width: 48vmax;
  height: 48vmax;
  bottom: -16vmax;
  left: -14vmax;
  background: radial-gradient(circle, rgba(232, 196, 188, 0.55), transparent 70%);
  animation-delay: -6s;
}

.leaf {
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 60% 40% 55% 45%;
  opacity: 0.18;
  background: linear-gradient(135deg, #6ea58f, transparent);
  animation: sway 14s ease-in-out infinite alternate;
}

.leaf-a { top: 18%; left: -40px; transform: rotate(-18deg); }
.leaf-b {
  bottom: 12%;
  right: -50px;
  background: linear-gradient(135deg, #c98984, transparent);
  animation-delay: -4s;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(-18px, 22px, 0) scale(1.06); }
}

@keyframes sway {
  from { transform: rotate(-12deg) translateY(0); }
  to { transform: rotate(8deg) translateY(12px); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--accent);
}

.muted { color: var(--muted); }

.lede {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.error-text {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 0.92rem;
}

/* PIN */
.pin-gate {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.pin-card {
  width: min(420px, 100%);
  padding: 36px 28px;
  border-radius: 28px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}

.pin-card h1 {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.pin-form {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.pin-form input,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.85);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pin-form input:focus,
.field input:focus,
.field textarea:focus {
  border-color: rgba(47, 111, 94, 0.45);
  box-shadow: 0 0 0 3px rgba(47, 111, 94, 0.12);
}

.pin-form button,
.primary-btn {
  border-radius: 14px;
  padding: 14px 18px;
  background: var(--accent);
  color: #f4fbf8;
  font-weight: 600;
}

.pin-form button:hover,
.primary-btn:hover { filter: brightness(1.05); }

/* App shell */
.app {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 calc(40px + var(--safe-bottom));
  animation: rise 0.45s ease both;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 7vw, 3rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.topbar-actions {
  display: flex;
  gap: 6px;
  padding-top: 6px;
}

.ghost-btn {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.ghost-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.5); }

.pulse {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}

.pulse-main,
.pulse-side,
.chart-block,
.insight,
.history-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
}

.pulse-main {
  padding: 22px;
  box-shadow: var(--shadow);
}

.pulse-value {
  margin: 10px 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 8vw, 3.2rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.pulse-value small {
  margin-left: 8px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

.pulse-sub {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.pulse-side {
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: center;
}

.pulse-side span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.pulse-side strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
}

.actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}

.action-btn {
  text-align: left;
  padding: 18px 18px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.action-btn:hover { transform: translateY(-1px); border-color: rgba(47, 111, 94, 0.35); }

.action-btn.primary {
  background: linear-gradient(160deg, #3d8874 0%, #2f6f5e 100%);
  color: #f5fbf8;
  border-color: transparent;
}

.action-btn.primary .action-hint { color: rgba(245, 251, 248, 0.78); }

.action-label {
  display: block;
  font-weight: 650;
  font-size: 1.05rem;
}

.action-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tab {
  padding: 10px 14px 12px;
  color: var(--muted);
  font-weight: 550;
  position: relative;
}

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

.tab.is-active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.chart-block {
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.chart-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
}

.chart-head .muted {
  margin: 4px 0 0;
  font-size: 0.88rem;
  line-height: 1.4;
}

.range-pills,
.filter-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.range-pill,
.filter-pill {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid transparent;
}

.range-pill.is-active,
.filter-pill.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(47, 111, 94, 0.18);
}

.chart-frame {
  width: 100%;
  height: 220px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.2));
  border: 1px solid rgba(28, 43, 38, 0.06);
  overflow: hidden;
}

.chart-frame svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 20px;
  text-align: center;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.swatch.net { background: var(--accent); }
.swatch.avg { background: var(--avg); }

.insight {
  padding: 18px 20px;
}

.insight p:last-child {
  margin: 8px 0 0;
  font-size: 1.05rem;
  line-height: 1.5;
}

.history-toolbar { margin-bottom: 12px; }

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  text-align: left;
  width: 100%;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.history-item:hover {
  border-color: rgba(47, 111, 94, 0.3);
  transform: translateY(-1px);
}

.history-item .title {
  font-weight: 600;
  margin: 0;
}

.history-item .meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.history-item .note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--ink);
  opacity: 0.82;
  font-size: 0.92rem;
  line-height: 1.4;
}

.history-item .value {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  text-align: right;
}

.history-item .value small {
  display: block;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent);
  margin-right: 6px;
}

.badge.weight {
  background: var(--rose-soft);
  color: var(--rose);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

/* Sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(28, 43, 38, 0.28);
  backdrop-filter: blur(4px);
  animation: rise 0.2s ease both;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 50;
  width: min(560px, 100%);
  max-height: min(92dvh, 760px);
  overflow: auto;
  background: #fbfaf7;
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: 0 -20px 50px rgba(28, 43, 38, 0.12);
  padding: 10px 20px calc(24px + var(--safe-bottom));
  animation: slideUp 0.28s ease both;
}

@keyframes slideUp {
  from { transform: translate(-50%, 24px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(28, 43, 38, 0.18);
  margin: 4px auto 10px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
}

.sheet-form {
  display: grid;
  gap: 14px;
  padding-bottom: 8px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--muted);
}

.field em {
  font-style: normal;
  opacity: 0.7;
  font-weight: 400;
}

.field textarea { resize: vertical; min-height: 84px; }

.field-hint {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.kind-field {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.kind-field legend {
  width: 100%;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--muted);
}

.kind-field label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.kind-field input { accent-color: var(--accent); }

.sheet-actions {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.danger-btn {
  padding: 12px 16px;
  border-radius: 14px;
  color: var(--danger);
  font-weight: 600;
  background: rgba(155, 61, 61, 0.08);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #f5faf7;
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
}

@media (max-width: 640px) {
  .pulse,
  .actions {
    grid-template-columns: 1fr;
  }

  .app {
    width: min(100% - 20px, 720px);
    padding-top: 20px;
  }

  .chart-frame { height: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
