:root {
  --bg: #f3f6f8;
  --ink: #122033;
  --muted: #5c6c7c;
  --line: #d5e0e6;
  --card: #ffffff;
  --teal: #0c6b66;
  --teal-dark: #084e4b;
  --soft: #e7f4f2;
  --hot: #9f1d1d;
  --warm: #9a4d00;
  --shadow: 0 10px 30px rgba(16, 32, 51, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 320px at 50% -120px, #d7eeeb 0%, transparent 70%),
    var(--bg);
}

button, input, textarea { font: inherit; }

button { touch-action: manipulation; }

.app {
  width: min(460px, 100%);
  margin: 0 auto;
  padding:
    calc(18px + env(safe-area-inset-top))
    16px
    calc(32px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: white;
  font-weight: 700;
  letter-spacing: -0.03em;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 28px;
  letter-spacing: -0.03em;
}

.top p, .muted, .disclaimer, .save-state, .trend {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.top p { margin-top: 2px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel + .panel,
.obs-head,
.switcher,
.trend,
#card,
.text-danger,
.disclaimer,
.save-state { margin-top: 12px; }

.field { display: block; }

.field-name {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.unit {
  font-weight: 600;
  color: var(--muted);
}

.field + .field,
.grid-2,
.flags,
.block { margin-top: 14px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfd;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
}

textarea { min-height: 88px; resize: vertical; }

input:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(12, 107, 102, 0.35);
  outline-offset: 1px;
  border-color: var(--teal);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.with-btn, .sats {
  display: flex;
  gap: 8px;
  align-items: end;
}

.grid-2 > .field,
.sats > .field,
.card-top .field { margin-top: 0; }

.card-top .with-btn { width: auto; }

.with-btn input, .sats input { flex: 1; min-width: 0; }

.flags { display: grid; gap: 10px; }

.flag {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.flag span { font-size: 14px; font-weight: 700; }

.pair, .seg, .nums { display: flex; gap: 6px; }

.pair button, .seg button, .nums button, .choice, .check {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 12px;
  min-height: 44px;
}

.pair button {
  min-width: 58px;
  padding: 8px 12px;
  font-weight: 700;
}

.seg { display: grid; grid-template-columns: repeat(5, 1fr); }

.seg button {
  padding: 8px 2px;
  font-weight: 800;
}

.seg button small, .gcs-word {
  display: block;
  font-weight: 600;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.15;
}

button[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

button[aria-pressed="true"] small { color: rgba(255, 255, 255, 0.86); }

.obs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h2 { font-size: 18px; letter-spacing: -0.02em; }

.switcher {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chip {
  flex: 0 0 auto;
  min-width: 76px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 14px;
  padding: 8px 10px;
  text-align: left;
}

.chip b, .chip small { display: block; }
.chip b { font-size: 14px; }
.chip small { color: var(--muted); font-size: 12px; }

.chip.is-on {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
}

.chip.is-on small { color: rgba(255, 255, 255, 0.75); }

.chip.add {
  min-width: 48px;
  font-size: 26px;
  line-height: 1;
  color: var(--teal);
}

.card-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.card-top h3 {
  margin: 0;
  font-size: 16px;
  flex: 1 1 150px;
}

.card-top .with-btn {
  flex: 1 1 190px;
  width: auto;
}

.gcs-head {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}

.seg.letters button {
  font-size: 18px;
  min-height: 48px;
}

.acvpu-key {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.gcs-total {
  font-size: 28px;
  letter-spacing: -0.04em;
}

.check-group { margin-top: 12px; }

.check-group .field-name { margin-bottom: 0; }

.check {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 12px;
  text-align: left;
  font-weight: 700;
  cursor: pointer;
}

.check b { width: 1.2em; font-size: 16px; }

.chart-wrap {
  overflow-x: auto;
  margin-top: 12px;
}

.chart {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 10px;
  line-height: 1.2;
}

.chart caption {
  caption-side: top;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  padding-bottom: 6px;
}

.chart th,
.chart td {
  border: 1px solid var(--line);
  padding: 4px 2px;
  text-align: center;
  background: white;
  overflow-wrap: anywhere;
}

.chart th:first-child,
.chart td:first-child {
  width: 62px;
  text-align: left;
  font-weight: 700;
  position: sticky;
  left: 0;
  z-index: 1;
}

.chart thead th { background: #f4f7f8; }

.chart small {
  display: block;
  font-weight: 600;
  color: var(--muted);
}

.chart td.is-hit {
  background: var(--teal);
  color: white;
  font-weight: 700;
}

.chart td.is-hit.is-3 { background: var(--hot); }

.gcs-row { margin-top: 8px; }

.gcs-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.gcs-word { font-weight: 600; }

.nums button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-weight: 700;
}

.pain { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }

.pain button { min-height: 42px; font-weight: 700; }

.news {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  background: #f2f5f7;
}

.news-total {
  min-width: 64px;
  font-size: 40px;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.news p { margin-top: 2px; color: var(--muted); font-size: 13px; }

.news[data-band="low"] { background: #e5f6f1; }
.news[data-band="low"] .news-total { color: var(--teal); }
.news[data-band="low-medium"] { background: #fff6d8; }
.news[data-band="low-medium"] .news-total { color: #8a6500; }
.news[data-band="medium"] { background: #ffedd9; }
.news[data-band="medium"] .news-total { color: var(--warm); }
.news[data-band="high"] { background: #fde4e4; }
.news[data-band="high"] .news-total { color: var(--hot); }

.score {
  margin-left: 4px;
  min-width: 1.2em;
  text-align: center;
  font-size: 12px;
  font-style: normal;
  color: var(--teal);
}

.score:empty { display: none; }
.score.warm { color: var(--warm); }
.score.hot { color: var(--hot); }

.actions, .dialog-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.actions { flex-direction: column; }

.btn, .text-danger {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn.primary {
  background: var(--teal);
  color: white;
}

.btn.primary:hover { background: var(--teal-dark); }

.btn.secondary, .btn.ghost, .btn.small {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.small { min-height: 48px; padding: 0 12px; white-space: nowrap; }

.btn:disabled { opacity: 0.45; }

.actions .btn { width: 100%; }

.linkish, .text-danger {
  background: transparent;
  color: var(--teal);
  width: 100%;
}

.text-danger { color: var(--hot); }

.preview { margin-top: 14px; }

.preview .field-name { margin-bottom: 6px; }

pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font-family: Consolas, ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.45;
  background: #f4f7f8;
  border-radius: 12px;
  padding: 12px;
}

.disclaimer, .save-state { text-align: center; }

dialog {
  border: 0;
  border-radius: 22px;
  padding: 20px;
  width: min(420px, calc(100% - 32px));
  box-shadow: 0 24px 70px rgba(16, 32, 51, 0.28);
}

dialog::backdrop { background: rgba(16, 32, 51, 0.46); }

dialog h2 { font-size: 22px; margin-bottom: 6px; }

.counter-taps {
  margin: 8px 0 0;
  text-align: center;
  font-size: 56px;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.counter-meta { text-align: center; margin: 0 0 8px; }

.tap {
  display: block;
  width: min(220px, 68vw);
  height: min(220px, 68vw);
  margin: 8px auto 4px;
  border: 0;
  border-radius: 50%;
  background: var(--teal);
  color: white;
  font-size: 28px;
  font-weight: 800;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 5;
  max-width: calc(100% - 32px);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 360px) {
  .grid-2 { grid-template-columns: 1fr; }
  .seg { grid-template-columns: repeat(3, 1fr); }
}
