:root {
  color-scheme: light;
  --paper: #f5f1e8;
  --cream: #fffdf7;
  --pine: #12483e;
  --pine-dark: #082c27;
  --coral: #ff5b45;
  --lime: #d8f47b;
  --bg: var(--paper);
  --card: var(--cream);
  --ink: #0b302b;
  --muted: #5b6d68;
  --line: rgba(11, 48, 43, .15);
  --accent: var(--pine);
  --accent-soft: #e6eee9;
  --ok: #107c55;
  --warn: #8c5a00;
  --danger: #a32920;
  --danger-soft: #fff0ef;
  --shadow: 0 12px 36px rgba(8, 44, 39, .09);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button, label, input[type="radio"], input[type="checkbox"] { touch-action: manipulation; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  color: var(--cream);
  background: rgba(8, 44, 39, .96);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  backdrop-filter: blur(10px);
}
.topbar__inner, .page, .footer {
  width: min(100%, 640px);
  margin: 0 auto;
}
.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 11px 16px;
  gap: 12px;
}
.eyebrow { color: var(--coral); font-size: 11px; font-weight: 900; letter-spacing: .11em; text-transform: uppercase; }
.topbar .eyebrow { color: var(--lime); }
h1 { margin: 0; font-size: clamp(22px, 6vw, 30px); line-height: 1.12; }
h2 { margin: 0; font-size: 20px; line-height: 1.25; }

.page { padding: 16px 14px 110px; }
.footer { padding: 4px 16px calc(28px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 13px; }
.noscript { padding: 12px; color: #fff; background: var(--danger); text-align: center; }

.card {
  margin: 0 0 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.card--compact { padding: 13px 16px; }
.login-card { max-width: 480px; margin: 28px auto; }
.participant-line, .section-title, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.participant-line strong { display: block; font-size: 18px; }
.section-title { margin: 24px 3px 11px; align-items: end; }
.section-title .muted { font-size: 13px; text-align: right; }
.panel-head { margin-bottom: 14px; }

.muted, .hint, .optional { color: var(--muted); }
.muted { margin: 6px 0 14px; }
.hint { margin: 6px 0 12px; font-size: 13px; }
.optional { font-size: 13px; font-weight: 400; }

.notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #b9ded0;
  border-left: 4px solid var(--ok);
  border-radius: 11px;
  background: #edf8f3;
}
.notice--error { border-color: #efbbb7; border-left-color: var(--danger); background: var(--danger-soft); color: #7d211a; }
.notice--ok { border-left-color: var(--ok); }
.notice--safety { border-color: #f1d3ab; border-left-color: var(--warn); background: #fff8ed; }
.notice--plain { border-color: var(--line); border-left-color: var(--pine); background: #f2f3eb; font-size: 14px; }

.sync-pill {
  max-width: 130px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--warn);
  background: #fff3d6;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.action {
  display: flex;
  min-height: 98px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink);
  background: var(--card);
  font-weight: 800;
  text-align: left;
  box-shadow: 0 4px 14px rgba(25, 67, 57, .04);
  cursor: pointer;
}
.action:active { transform: translateY(1px); }
.action--urine { border-color: #dfcb72; background: #fff7c9; }
.action--fluid { border-color: #a9d2e3; background: #e9f7fb; }
.action--stairs { color: var(--cream); border-color: var(--pine); background: var(--pine); }
.action--stairs .action__icon { color: var(--lime); }
.action--selfie { color: var(--pine-dark); border-color: var(--coral); background: var(--coral); }
.action--selfie .action__icon { color: var(--pine-dark); }
.action__icon { color: var(--accent); font-size: 26px; line-height: 1; }

label:not(.choice):not(.check-choice) { display: block; margin: 13px 0 6px; font-weight: 700; }
input[type="text"], input[type="tel"], input[type="number"], input[type="datetime-local"], input:not([type]), textarea, select {
  display: block;
  width: 100%;
  min-height: 47px;
  padding: 10px 12px;
  border: 1px solid #b8c9c3;
  border-radius: 13px;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(23, 107, 88, .22); outline-offset: 1px; }

fieldset { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
legend { margin-bottom: 9px; padding: 0; font-weight: 800; }
.choice-grid { display: grid; gap: 8px; }
.choice-grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice-grid--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-stack { display: grid; gap: 8px; }
.choice-stack--top { margin-top: 11px; }
.choice, .check-choice {
  position: relative;
  display: flex;
  min-height: 45px;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--cream);
  cursor: pointer;
}
.choice input, .check-choice input { width: 19px; height: 19px; flex: 0 0 auto; margin: 0; accent-color: var(--accent); }
.choice:has(input:checked), .check-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice--warning:has(input:checked), .check-choice--danger:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); }

.color-scale { display: block; width: 100%; height: auto; margin: 5px 0 11px; border: 1px solid var(--line); border-radius: 12px; }
.grade-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.grade-grid label { min-width: 0; cursor: pointer; }
.grade-grid input { position: absolute; opacity: 0; pointer-events: none; }
.grade-grid span {
  display: grid;
  min-height: 43px;
  place-items: center;
  border: 2px solid transparent;
  border-radius: 9px;
  background: #eef3f1;
  font-weight: 800;
}
.grade-grid input:checked + span { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.grade--1 { background: #f8f3ba !important; }
.grade--2 { background: #f4e58a !important; }
.grade--3 { background: #efd060 !important; }
.grade--4 { background: #e5b83e !important; }
.grade--5 { background: #d89a28 !important; color: #fff; }
.grade--6 { background: #bf771f !important; color: #fff; }
.grade--7 { background: #96531c !important; color: #fff; }
.grade--8 { background: #6f391c !important; color: #fff; }
.grade-grid--five { grid-template-columns: repeat(5, 1fr); margin-bottom: 9px; }
.grade-grid--five span { min-height: 49px; }

.time-block { margin: 8px 0 16px; padding-top: 4px; border-top: 1px solid var(--line); }
.range { width: calc(100% - 52px); accent-color: var(--accent); vertical-align: middle; }
.range-output { display: inline-grid; width: 42px; height: 42px; place-items: center; border-radius: 50%; color: #fff; background: var(--accent); font-weight: 800; }

.button {
  min-height: 47px;
  padding: 10px 16px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}
.button:disabled { opacity: .6; cursor: wait; }
.button--primary { color: var(--cream); background: var(--pine-dark); }
.button--secondary { color: var(--ink); background: var(--accent-soft); }
.button--coral { color: var(--pine-dark); background: var(--coral); }
.button--full { width: 100%; }
.link-button, .close-button { border: 0; color: var(--accent); background: transparent; font-weight: 750; cursor: pointer; }
.close-button { width: 42px; height: 42px; padding: 0; color: var(--muted); font-size: 29px; line-height: 1; }

.records-list { display: grid; gap: 8px; }
.record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.record:last-child { border-bottom: 0; }
.record__kind { font-weight: 800; }
.record__time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.record__summary { grid-column: 1 / -1; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }

.offline-card { border-color: #f0d4a7; }
.entry-panel { scroll-margin-top: 86px; }
.entry-panel.is-saving { opacity: .75; pointer-events: none; }

body.panel-open { overflow: hidden; }
body.panel-open #global-error,
body.panel-open #global-message {
  position: fixed;
  z-index: 120;
  top: calc(76px + env(safe-area-inset-top));
  left: 50%;
  width: min(calc(100% - 28px), 580px);
  margin: 0;
  transform: translateX(-50%);
  box-shadow: 0 12px 36px rgba(8, 44, 39, .2);
  pointer-events: none;
}
.entry-panel:not([hidden]) {
  position: fixed;
  z-index: 80;
  inset: 0;
  overflow-y: auto;
  width: min(100%, 640px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(32px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
}
.entry-panel .panel-head {
  position: sticky;
  z-index: 4;
  top: calc(-18px - env(safe-area-inset-top));
  margin: calc(-18px - env(safe-area-inset-top)) -18px 18px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 13px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 241, 232, .94);
  backdrop-filter: blur(12px);
}
.entry-panel h3 { margin: 5px 0 8px; font-size: clamp(24px, 7vw, 34px); line-height: 1.05; }

.stair-step { max-width: 540px; margin: 0 auto; }
.stair-illustration {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  margin: 12px 0 18px;
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.stair-copy { margin: 0 2px 22px; }
.stair-copy p { margin: 0; color: var(--muted); font-size: 17px; }
.step-progress { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 4px 2px 16px; }
.step-progress span { height: 5px; border-radius: 999px; background: rgba(11, 48, 43, .14); }
.step-progress .is-active { background: var(--coral); }
.step-progress .is-done { background: var(--lime); }
.scale-labels { display: flex; justify-content: space-between; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.pain-scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 15px; }
.pain-scale label { cursor: pointer; }
.pain-scale input { position: absolute; opacity: 0; pointer-events: none; }
.pain-scale span {
  display: grid;
  min-height: 64px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--cream);
  font-size: 22px;
  font-weight: 900;
}
.pain-scale input:checked + span { border-color: var(--pine-dark); color: var(--cream); background: var(--pine-dark); box-shadow: 0 0 0 3px var(--lime); }
.handrail-choice { margin-top: 12px; }
.stair-summary { margin: 16px 0; padding: 14px 16px; border-radius: 16px; background: var(--lime); font-weight: 900; text-align: center; }

.selfie-studio { margin: 14px 0 20px; }
.selfie-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.selfie-heading h3 { margin: 3px 0 0; font-size: 23px; }
.selfie-badge { padding: 5px 9px; border-radius: 999px; color: var(--cream); background: var(--pine); font-size: 12px; font-weight: 900; }
.selfie-stage {
  position: relative;
  z-index: 0;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 420px);
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  border: 2px solid var(--pine-dark);
  border-radius: 28px;
  background: var(--pine-dark);
  box-shadow: var(--shadow);
}
.selfie-stage video, .selfie-stage > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.selfie-stage video { transform: scaleX(-1); }
.selfie-reference { z-index: 4; transform: scaleX(-1); opacity: .38; pointer-events: none; }
.selfie-preview { z-index: 3; transform: scaleX(-1); }
.selfie-empty { position: absolute; inset: 0; display: grid; place-content: center; gap: 8px; padding: 32px; color: rgba(255,255,255,.8); text-align: center; }
.selfie-empty__icon { color: var(--lime); font-size: 58px; line-height: 1; }
.selfie-empty span:last-child { max-width: 260px; font-size: 13px; }
.selfie-guide { position: absolute; z-index: 5; inset: 0; pointer-events: none; }
.selfie-guide__face {
  position: absolute;
  top: 12%;
  left: 50%;
  width: 57%;
  height: 52%;
  border: 3px solid var(--lime);
  border-radius: 48% 48% 44% 44%;
  transform: translateX(-50%);
  box-shadow: 0 0 0 999px rgba(8, 44, 39, .18);
}
.selfie-guide__eyes { position: absolute; top: 32%; left: 27%; width: 46%; border-top: 1px dashed rgba(216,244,123,.85); }
.selfie-guide__shoulders { position: absolute; left: 13%; bottom: 8%; width: 74%; height: 22%; border-top: 3px solid var(--lime); border-radius: 50% 50% 0 0; }
.selfie-controls { display: flex; justify-content: center; gap: 9px; margin: 14px 0 8px; }
.selfie-controls .button { min-width: 132px; }
.selfie-reference-controls { width: min(100%, 420px); margin: 13px auto 0; padding: 12px; border-radius: 16px; background: var(--cream); }
.upload-retry { margin: 14px 0; }
.upload-retry p { margin: 5px 0 11px; color: var(--muted); font-size: 13px; }
.upload-form.is-retry-locked > :not(.upload-retry):not(button[type="submit"]) { opacity: .62; }
.toggle-line { display: flex !important; align-items: center; gap: 9px; margin: 0 !important; }
.toggle-line input { width: 20px; height: 20px; accent-color: var(--pine); }
.opacity-control { display: grid !important; grid-template-columns: auto 1fr; align-items: center; gap: 12px; margin: 11px 0 0 !important; color: var(--muted); font-size: 13px; }
.opacity-control input { width: 100%; accent-color: var(--coral); }

.app-nav {
  position: fixed;
  z-index: 50;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(calc(100% - 24px), 560px);
  margin: 0 auto;
  padding: 7px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 22px;
  background: rgba(8, 44, 39, .96);
  box-shadow: 0 14px 38px rgba(8,44,39,.24);
  backdrop-filter: blur(12px);
}
.app-nav__item { display: grid; gap: 2px; min-height: 52px; place-content: center; border: 0; border-radius: 16px; color: rgba(255,255,255,.68); background: transparent; font-size: 11px; font-weight: 800; cursor: pointer; }
.app-nav__item span { font-size: 20px; line-height: 1; }
.app-nav__item.is-active { color: var(--pine-dark); background: var(--lime); }
.is-telegram-miniapp .topbar { position: static; }

.intervals-card {
  border-color: rgba(72, 122, 92, .32);
  background: linear-gradient(145deg, rgba(226, 242, 222, .9), rgba(255, 255, 255, .98));
}
.intervals-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.intervals-actions .button { width: auto; margin: 0; }
.intervals-disconnect { color: var(--danger); }
.policy-page { max-width: 850px; margin: 0 auto; }
.policy-page ul { padding-left: 22px; }
.policy-page li + li { margin-top: 8px; }

@media (min-width: 620px) {
  .page { padding: 24px 18px 48px; }
  .action-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .action { min-height: 105px; }
  .entry-panel:not([hidden]) { inset: 24px 0; border: 1px solid var(--line); border-radius: 26px; box-shadow: 0 28px 80px rgba(8,44,39,.2); }
}

@media (max-width: 390px) {
  .choice-grid--three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grade-grid { gap: 3px; }
  .grade-grid span { min-height: 39px; font-size: 14px; }
  .pain-scale { gap: 5px; }
  .pain-scale span { min-height: 55px; border-radius: 13px; }
}

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