/* OncoSense Monitor
   One family (Geist; Geist Mono only for the raw device log), one accent,
   surfaces separated by tone steps rather than lines or shadows. */

:root {
  color-scheme: light dark;

  --ground: #f3f5f4;
  --raised: #fbfcfc;
  --sunken: #e6ebe9;
  --ink: #121816;
  --ink-soft: #4a5551;
  --accent: #0e6f68;
  --accent-strong: #0a5651;
  --accent-ink: #ffffff;
  --accent-wash: #d9ece9;
  --warn: #8a5300;
  --warn-wash: #f6e7cf;
  --alert: #b42318;
  --alert-wash: #f8dcd8;
  --alert-ink: #ffffff;

  /* Data colours: dry (sand) to hydrated (teal); occlusive film is slate. */
  --c-very_dry: #b88a4a;
  --c-dry: #cfae74;
  --c-normal: #7fa99b;
  --c-well_hydrated: #2f8a80;
  --c-occlusive: #5d6b78;
  --c-line: var(--accent);

  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius-s: 6px;
  --radius-m: 10px;
  --gutter: clamp(16px, 2.4vw, 32px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --z-topbar: 10;
  --z-toast: 20;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0f1312;
    --raised: #161c1b;
    --sunken: #1f2725;
    --ink: #e8eeec;
    --ink-soft: #a3b0ab;
    --accent: #5cc2b6;
    --accent-strong: #7fd3c8;
    --accent-ink: #06201d;
    --accent-wash: #173633;
    --warn: #f0b45c;
    --warn-wash: #3a2a12;
    --alert: #ff8a7a;
    --alert-wash: #3d1a16;
    --alert-ink: #2a0b07;
    --c-very_dry: #c79a5a;
    --c-dry: #d9bd88;
    --c-normal: #8fbcad;
    --c-well_hydrated: #4fb3a6;
    --c-occlusive: #8796a3;
  }
}

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

[hidden] {
  display: none !important;
}

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

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

@media (pointer: fine) {
  html {
    overscroll-behavior: none;
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

h1, h2, h3 {
  margin: 0;
  text-wrap: balance;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-strong);
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--sunken);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

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

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: var(--z-toast);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: var(--radius-s);
  font-weight: 600;
}

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

main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--gutter) 64px;
}

main:focus {
  outline: none;
}

/* ------------------------------------------------------------- Top bar -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px var(--gutter);
  background: var(--ground);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.wordmark:hover {
  color: var(--ink);
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 15px;
  min-width: 0;
}

.connection span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection .dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-soft);
}

.connection[data-state="live"] {
  color: var(--ink);
}

.connection[data-state="live"] .dot {
  background: var(--accent);
}

.connection[data-state="error"] .dot {
  background: var(--alert);
}

.topbar-actions {
  margin-left: auto;
}

/* ------------------------------------------------------------- Buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-s);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

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

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-wash);
}

.btn-quiet {
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
}

.btn-quiet:hover:not(:disabled) {
  background: var(--sunken);
}

.btn-danger {
  background: transparent;
  color: var(--alert);
  padding: 0 12px;
}

.btn-danger:hover:not(:disabled),
.btn-danger[data-armed="true"],
.btn-quiet[data-armed="true"] {
  background: var(--alert-wash);
}

.btn-small {
  min-height: 40px;
  font-size: 14px;
}

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

.btn-record:hover {
  background: var(--alert-wash);
}

.btn-record .rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--alert);
}

.btn-record[aria-pressed="true"] {
  background: var(--alert);
  color: var(--alert-ink);
}

.btn-record[aria-pressed="true"] .rec-dot {
  background: var(--alert-ink);
  animation: pulse 1.6s var(--ease) infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* ------------------------------------------------------------- Welcome -- */

.welcome {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: clamp(32px, 6vw, 96px);
  align-items: center;
  padding-top: clamp(24px, 6vh, 80px);
}

.welcome h1 {
  font-size: clamp(40px, 5.2vw, 76px);
  line-height: 0.98;
  letter-spacing: -0.035em;
  font-weight: 700;
  max-width: 12ch;
}

.lede {
  margin-top: 24px;
  font-size: 19px;
  max-width: 44ch;
}

.steps {
  margin: 32px 0 0;
  padding: 0 0 0 1.4em;
  display: grid;
  gap: 12px;
  max-width: 52ch;
}

.steps li::marker {
  color: var(--accent);
  font-weight: 700;
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 36px;
}

.support {
  margin-top: 16px;
  font-size: 15px;
  color: var(--ink-soft);
  max-width: 52ch;
}

.support:empty {
  display: none;
}

.support[data-tone="warn"] {
  color: var(--warn);
}

.welcome-figure {
  margin: 0;
}

.welcome-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-m);
  background: var(--sunken);
}

.welcome-figure figcaption {
  margin-top: 12px;
  font-size: 14px;
  color: var(--ink-soft);
}

/* ----------------------------------------------------------- Dashboard -- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 24px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-m);
  background: var(--sunken);
  max-width: 100%;
  overflow-x: auto;
}

.tabs button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}

.tabs button:hover {
  color: var(--ink);
}

.tabs button[aria-selected="true"] {
  background: var(--raised);
  color: var(--ink);
}

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

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 24px;
  align-items: start;
}

.primary {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.reading,
.chart-block,
.side-block {
  background: var(--raised);
  border-radius: var(--radius-m);
  padding: clamp(20px, 2.4vw, 32px);
}

.reading-state {
  font-size: clamp(40px, 5vw, 72px);
  line-height: 1;
  letter-spacing: -0.035em;
  font-weight: 700;
}

.reading-state[data-tone="muted"] {
  font-size: clamp(28px, 3vw, 40px);
  color: var(--ink-soft);
}

.reading-detail {
  margin-top: 14px;
  font-size: 18px;
  max-width: 60ch;
}

.reading-action {
  margin-top: 24px;
}

.reading-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 40px;
  margin-top: 28px;
}

.meter {
  display: grid;
  gap: 2px;
}

.meter-label {
  font-size: 14px;
  color: var(--ink-soft);
}

.meter-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.meter-value[data-tone="warn"] {
  color: var(--warn);
}

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.flags:empty {
  display: none;
}

.flags li {
  padding: 6px 12px;
  border-radius: var(--radius-s);
  font-size: 14px;
  font-weight: 500;
  background: var(--warn-wash);
  color: var(--warn);
}

.flags li[data-tone="alert"] {
  background: var(--alert-wash);
  color: var(--alert);
}

.chart-block h3,
.side-block h3 {
  font-size: 18px;
  font-weight: 600;
}

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}

.chart-note {
  font-size: 14px;
  color: var(--ink-soft);
}

/* Probability bars */

.probs {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.prob {
  display: grid;
  grid-template-columns: 9.5em minmax(0, 1fr) 4em;
  align-items: center;
  gap: 14px;
  font-size: 15px;
}

.prob-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prob[data-top="true"] .prob-name {
  font-weight: 600;
}

.prob-track {
  display: block;
  height: 14px;
  border-radius: 4px;
  background: var(--sunken);
  overflow: hidden;
}

.prob-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 450ms var(--ease);
}

.prob-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.prob[data-top="true"] .prob-value {
  color: var(--ink);
  font-weight: 600;
}

/* SVG charts */

.history,
.spectrum {
  display: block;
  width: 100%;
  margin-top: 16px;
  overflow: visible;
}

.history {
  height: auto;
  aspect-ratio: 640 / 200;
}

.spectrum {
  height: auto;
  aspect-ratio: 640 / 220;
}

.history .area {
  fill: var(--accent-wash);
}

.history .line {
  fill: none;
  stroke: var(--c-line);
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
}

.history .band {
  fill: var(--sunken);
}

.chart-text {
  fill: var(--ink-soft);
  font-family: var(--font);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-empty {
  fill: var(--ink-soft);
  font-family: var(--font);
  font-size: 15px;
}

.spectrum .bar {
  transition: transform 450ms var(--ease);
  transform-box: fill-box;
  transform-origin: bottom center;
}

.spectrum .baseline-tick {
  fill: var(--ink);
}

/* ---------------------------------------------------------------- Side -- */

.side {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.side-block {
  padding: 22px;
}

.side-note {
  margin-top: 8px;
  font-size: 15px;
  color: var(--ink-soft);
}

.side-note:empty {
  display: none;
}

.cal-steps {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.cal-step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 4px 12px;
  align-items: start;
  padding: 14px;
  border-radius: var(--radius-s);
  background: var(--ground);
}

.cal-step .tick {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sunken);
  display: grid;
  place-items: center;
  color: var(--accent-ink);
}

.cal-step[data-done="true"] .tick {
  background: var(--accent);
}

.cal-step .tick svg {
  display: none;
}

.cal-step[data-done="true"] .tick svg {
  display: block;
}

.cal-step-title {
  font-weight: 600;
}

.cal-step-how {
  grid-column: 2;
  font-size: 14px;
  color: var(--ink-soft);
}

.cal-step .btn {
  grid-column: 2;
  justify-self: start;
  margin-top: 6px;
}

.teach {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.teach .btn {
  justify-content: flex-start;
  min-height: 44px;
  padding: 0 12px;
  background: var(--ground);
  color: var(--ink);
  font-weight: 500;
}

.teach .btn:hover:not(:disabled) {
  background: var(--accent-wash);
}

.teach .swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

#teach-status {
  margin-top: 12px;
}

#reset-net {
  margin-top: 8px;
  margin-left: -12px;
}

.slider {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  font-size: 15px;
}

.slider span {
  display: flex;
  justify-content: space-between;
}

.slider output {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.slider input {
  width: 100%;
  accent-color: var(--accent);
  min-height: 28px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  min-height: 44px;
  font-size: 15px;
  cursor: pointer;
}

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

.export {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

#clear-cal {
  margin-top: 12px;
  margin-left: -12px;
}

.log summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 18px;
  min-height: 28px;
}

.log summary:hover {
  color: var(--accent);
}

.log pre {
  margin: 14px 0 0;
  max-height: 260px;
  overflow: auto;
  overscroll-behavior: contain;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------- Toast -- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  max-width: min(560px, calc(100vw - 32px));
  padding: 14px 20px;
  border-radius: var(--radius-m);
  background: var(--ink);
  color: var(--ground);
  font-size: 15px;
  box-shadow: 0 12px 32px rgb(15 19 18 / 0.25);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms var(--ease), opacity 220ms var(--ease);
}

.toast[data-show="true"] {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* -------------------------------------------------------------- Footer -- */

.footer {
  display: grid;
  gap: 6px;
  padding: 32px var(--gutter) calc(32px + env(safe-area-inset-bottom));
  background: var(--sunken);
  font-size: 14px;
  color: var(--ink-soft);
}

.footer p {
  max-width: 1440px;
}

/* ---------------------------------------------------------- Responsive -- */

@media (max-width: 1080px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

@media (max-width: 860px) {
  .welcome {
    grid-template-columns: minmax(0, 1fr);
  }

  .welcome-figure {
    order: -1;
  }

  .topbar {
    gap: 12px;
  }
}

@media (max-width: 520px) {
  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .prob {
    grid-template-columns: 7.5em minmax(0, 1fr) 3.4em;
    gap: 10px;
  }

  .reading-meta {
    gap: 12px 28px;
  }

  .session {
    width: 100%;
  }

  .session .btn-record {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
