:root {
  color-scheme: dark;
  --bg: #000;
  --card: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.1);
  --text: #fff;
  --muted: #8e8e93;
  --accent: #0a84ff;
  --warn: #ff9f0a;
  --bar-bg: rgba(0, 0, 0, 0.92);
  --box: #1c1c1e;
  --disabled: #48484a;
  --overlay: rgba(0, 0, 0, 0.45);
  --press: rgba(255, 255, 255, 0.05);
}

/* Светлая тема: явный выбор или системная настройка, если явного выбора нет */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f7;
  --card: #fff;
  --border: rgba(0, 0, 0, 0.1);
  --text: #000;
  --muted: #6c6c70;
  --accent: #007aff;
  --warn: #b25f00;
  --bar-bg: rgba(242, 242, 247, 0.92);
  --box: #fff;
  --disabled: #d1d1d6;
  --overlay: rgba(0, 0, 0, 0.3);
  --press: rgba(0, 0, 0, 0.05);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f2f2f7;
    --card: #fff;
    --border: rgba(0, 0, 0, 0.1);
    --text: #000;
    --muted: #6c6c70;
    --accent: #007aff;
    --warn: #b25f00;
    --bar-bg: rgba(242, 242, 247, 0.92);
    --box: #fff;
    --disabled: #d1d1d6;
    --overlay: rgba(0, 0, 0, 0.3);
    --press: rgba(0, 0, 0, 0.05);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; cursor: pointer; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  height: calc(48px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.bar[hidden] { display: none; }
.bar-title { margin: 0; font-size: 17px; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-btn { background: none; border: 0; font-size: 28px; line-height: 1; height: 48px; color: var(--text); }
.bar-btn:active { opacity: 0.5; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 40px; }

/* Home */
.hero { position: relative; text-align: center; padding: 40px 0 20px; }
.hero h2 { margin: 0 0 6px; font-size: 34px; font-weight: 700; }
.hero p { margin: 0; color: var(--muted); font-size: 15px; }
.gear { position: absolute; top: 12px; right: -8px; width: 44px; height: 44px; background: none; border: 0; font-size: 26px; color: var(--muted); }
.gear:active { opacity: 0.5; }

.cards { display: grid; gap: 14px; }
.card {
  display: block; width: 100%; text-align: left;
  padding: 20px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--border);
  transition: transform 0.1s ease;
}
.card:active { transform: scale(0.97); }
.card .icon { font-size: 40px; display: block; margin-bottom: 10px; }
.card .name { font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.card .desc { color: var(--muted); font-size: 15px; }

.home-sec { margin-top: 28px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; }
.sec { margin: 0 0 4px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.link { background: none; border: 0; padding: 4px; font-size: 13px; color: var(--accent); }

/* Input */
.input-screen { padding-top: 40px; text-align: center; }
.input-screen h2 { margin: 0 0 6px; font-size: 28px; }
.input-screen .sub { color: var(--muted); font-size: 15px; margin: 0 0 24px; }
.field {
  width: 100%; padding: 16px; font-size: 20px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 2px; text-align: center;
  color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.field:focus { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 4px 20px; }

.btn {
  display: block; width: 100%; padding: 15px;
  font-weight: 600; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff;
}
.btn:disabled { background: var(--disabled); color: var(--muted); cursor: not-allowed; }
.btn:active:not(:disabled) { opacity: 0.8; }
.btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }

.chips, .toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.chips { justify-content: center; margin-top: 24px; }
.chip {
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
}
.chip:active { opacity: 0.6; }

/* Lists */
.search { margin: 12px 0; text-transform: none; letter-spacing: 0; text-align: left; font-size: 16px; padding: 12px 14px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--border); }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 14px 4px; text-align: left; background: none; border: 0;
}
.row:active { background: var(--press); }
.row .t { font-weight: 600; }
.row .s { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.row .chev { color: var(--muted); font-size: 18px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Report */
.report { display: grid; gap: 14px; padding-top: 16px; }
.station { margin: 0; font-size: 20px; font-weight: 600; word-break: break-word; }
.status { margin: 0; font-size: 13px; color: var(--muted); }
.status.warn { color: var(--warn); }
.block { padding: 16px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.block + .block { margin-top: 14px; }
.block h3 { margin: 0 0 10px; font-size: 18px; color: var(--accent); }
pre.raw {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  user-select: text;
}
.msg + .msg { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.dec { display: grid; gap: 8px; }
.dec div { display: flex; gap: 8px; align-items: baseline; }
.dec .e { flex: none; width: 24px; text-align: center; }
.dec .lbl { margin-top: 6px; font-weight: 600; color: var(--accent); }
.dec .unk { color: var(--muted); font: 14px ui-monospace, Menlo, Consolas, monospace; }
.dec .head { color: var(--muted); font: 13px ui-monospace, Menlo, Consolas, monospace; margin-bottom: 4px; }
.note { margin: 14px 0 0; font-size: 12px; color: var(--muted); }

/* Settings */
.settings { display: grid; gap: 22px; padding-top: 20px; }
.setting-label { margin-bottom: 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.seg { display: flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); }
.seg-btn { flex: 1; padding: 9px 4px; font-size: 14px; background: none; border: 0; border-radius: 8px; }
.seg-btn.on { background: var(--accent); color: #fff; font-weight: 600; }
.btnrow { display: grid; gap: 10px; }

/* Overlays */
.loader { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--overlay); }
.loader[hidden], .modal[hidden], .toast[hidden] { display: none; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(128, 128, 128, 0.3); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--overlay); }
.modal-box { width: 100%; max-width: 320px; padding: 20px; border-radius: 16px; background: var(--box); text-align: center; }
.modal-box h2 { margin: 0 0 8px; font-size: 17px; }
.modal-box p { margin: 0 0 16px; color: var(--muted); font-size: 14px; word-break: break-word; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 70; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px;
  background: var(--box); color: var(--text); border: 1px solid var(--border); font-size: 14px; text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .card, .spinner { transition: none; animation-duration: 2s; }
}
