/* Layout: single-column bedside tool; sticky verdict bar, five scored criteria, 30-min reassessment alarm, dose */
:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --fg: #14232b;
  --muted: #5b6f78;
  --line: #d8e2e6;
  --accent: #0f6f7c;
  --accent-soft: #e1f0f2;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --warn: #a86400;
  --warn-soft: #fbf0dc;
  --crit: #b3261e;
  --crit-soft: #fbe5e3;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1619;
    --surface: #162226;
    --fg: #e4eef1;
    --muted: #93a9b1;
    --line: #27373d;
    --accent: #4fb8c6;
    --accent-soft: #173a40;
    --ok: #5cc98f;
    --ok-soft: #163327;
    --warn: #e8a947;
    --warn-soft: #3a2a12;
    --crit: #f07b72;
    --crit-soft: #3d1a18;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1619;
  --surface: #162226;
  --fg: #e4eef1;
  --muted: #93a9b1;
  --line: #27373d;
  --accent: #4fb8c6;
  --accent-soft: #173a40;
  --ok: #5cc98f;
  --ok-soft: #163327;
  --warn: #e8a947;
  --warn-soft: #3a2a12;
  --crit: #f07b72;
  --crit-soft: #3d1a18;
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--bg);
}

.wrap {
  max-width: 620px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 32px;
}

header {
  padding-block: 18px 6px;
}

h1 {
  font-size: 1.4rem;
  margin: 0;
  letter-spacing: -0.01em;
}

h1 em {
  font-style: normal;
  color: var(--accent);
}

h1 .alt {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.78em;
  white-space: nowrap;
}

.sub {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 0.9rem;
}

.result {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-block: 10px 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  align-items: center;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.06);
}

.total {
  font-family: var(--mono);
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1;
  grid-row: span 2;
  font-variant-numeric: tabular-nums;
}

.total small {
  font-size: 0.9rem;
  color: var(--muted);
}

.verdict {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 3px 10px;
  border-radius: 999px;
  justify-self: start;
}

.verdict.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.verdict.crit {
  background: var(--crit-soft);
  color: var(--crit);
}

.verdict.neutral {
  background: var(--accent-soft);
  color: var(--accent);
}

.why {
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 0;
}

.scale {
  grid-column: 1 / -1;
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  margin-top: 8px;
}

.scale i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 3px;
  width: 0;
  transition: width 0.2s, background 0.2s;
}

.scale b {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 14px;
  background: var(--fg);
  border-radius: 1px;
}

.note {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 8px;
  padding: 6px 9px;
  margin-top: 6px;
}

.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
}

.item-head b {
  font-weight: 600;
}

.hint {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
}

.pts {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.seg {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 6px;
}

.seg button {
  font: inherit;
  font-size: 0.86rem;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  border-radius: 9px;
  padding: 8px 4px;
  cursor: pointer;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1.2;
  text-align: center;
}

.seg button span {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.seg button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.seg button[aria-pressed="true"] span {
  color: #fff;
  opacity: 0.85;
}

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

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

.brand img {
  width: 56px;
  height: 56px;
  flex: none;
}

.by {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.brand {
  justify-content: space-between;
}

.brand > div:first-of-type {
  flex: 1;
}

.qrbtn {
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: var(--surface);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.qrbtn svg {
  width: 18px;
  height: 18px;
}

.qrpanel {
  background: #fff;
  color: #14232b;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-top: 12px;
  text-align: center;
}

.qrpanel.hidden {
  display: none;
}

.qrpanel #qr {
  display: flex;
  justify-content: center;
}

.qrpanel #qr img,
.qrpanel #qr canvas {
  width: 100%;
  max-width: 240px;
  height: auto;
}

.qrpanel p {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: #5b6f78;
}

.qrpanel b {
  color: #0f6f7c;
}

.ltr {
  display: inline-grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  margin-right: 8px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.85rem;
  vertical-align: 1px;
}

.timer {
  border-color: var(--accent);
}

.timer.ringing {
  animation: ring 1s infinite;
  border-color: var(--crit);
}

@keyframes ring {
  50% {
    background: var(--crit-soft);
  }
}

.clock {
  font-family: var(--mono);
  font-size: 2.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.tline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.round {
  font-size: 0.85rem;
  color: var(--muted);
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
}

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

.btn.stop {
  background: var(--crit);
  border-color: var(--crit);
  color: #fff;
}

.log {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.log li {
  display: grid;
  grid-template-columns: 4.5em 3em 1fr;
  gap: 8px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.log .t {
  font-family: var(--mono);
  color: var(--muted);
}

.log .s {
  font-family: var(--mono);
  font-weight: 600;
}

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

.row label {
  font-weight: 600;
}

.row input {
  font: inherit;
  font-family: var(--mono);
  width: 96px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--fg);
}

.row output {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--accent);
}

.sublbl {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 12px 0 6px;
}

#sType {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.seg button .trade {
  font-weight: 600;
  font-size: 0.8rem;
}

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

.stat {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}

.stat .k {
  font-size: 0.78rem;
  color: var(--muted);
}

.stat .v {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat .d {
  font-size: 0.78rem;
  color: var(--muted);
}

.xray {
  margin-top: 10px;
  font-size: 0.85rem;
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 12px;
}

.legend {
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 6px;
}

.legend p {
  margin: 0 0 6px;
}

.legend strong {
  color: var(--fg);
}

.about {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--muted);
}

.about b {
  color: var(--fg);
}

.mt10 {
  margin-top: 10px;
}

@media (prefers-reduced-motion: reduce) {
  .scale i {
    transition: none;
  }
  .timer.ringing {
    animation: none;
    background: var(--crit-soft);
  }
}
