/* ISS SSTV Decoder — site styles */
:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --bg-2: #eaeef5;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #0d1526;
  --muted: #4b5a72;
  --faint: #7a8699;
  --border: #dfe5ee;
  --border-strong: #c9d2df;
  --accent: #0b74c9;
  --accent-strong: #075a9e;
  --accent-soft: #e3f1fd;
  --on-accent: #ffffff;
  --live: #d9342b;
  --ok: #0f8a5f;
  --ok-soft: #e1f5ec;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --stage: #04070e;
  --stage-grid: rgba(120, 160, 220, 0.07);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px -12px rgba(16, 24, 40, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #070b13;
    --bg-2: #0b111d;
    --surface: #0f1624;
    --surface-2: #131c2d;
    --text: #e6edf7;
    --muted: #a3b1c6;
    --faint: #75839a;
    --border: #1f2a3d;
    --border-strong: #2c3a52;
    --accent: #4cb2ff;
    --accent-strong: #8ccdff;
    --accent-soft: #10263d;
    --on-accent: #04111f;
    --live: #ff5a4f;
    --ok: #35c98f;
    --ok-soft: #0e2a21;
    --warn: #f0b04b;
    --warn-soft: #2b2112;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #070b13;
  --bg-2: #0b111d;
  --surface: #0f1624;
  --surface-2: #131c2d;
  --text: #e6edf7;
  --muted: #a3b1c6;
  --faint: #75839a;
  --border: #1f2a3d;
  --border-strong: #2c3a52;
  --accent: #4cb2ff;
  --accent-strong: #8ccdff;
  --accent-soft: #10263d;
  --on-accent: #04111f;
  --live: #ff5a4f;
  --ok: #35c98f;
  --ok-soft: #0e2a21;
  --warn: #f0b04b;
  --warn-soft: #2b2112;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -14px rgba(0, 0, 0, 0.7);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font: 16px/1.6 var(--sans);
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}
img, svg, canvas { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.9rem, 4.2vw, 2.9rem); font-weight: 800; }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); font-weight: 750; }
h3 { font-size: 1.12rem; font-weight: 700; }
p { margin: 0 0 1em; }
code, kbd, .mono { font-family: var(--mono); font-size: 0.92em; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }

.wrap { width: min(1200px, 100% - 32px); margin-inline: auto; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand small { display: block; font-weight: 600; color: var(--faint); font-size: 0.72rem; letter-spacing: 0.02em; }
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.nav a {
  color: var(--muted); text-decoration: none; padding: 7px 11px; border-radius: 9px;
  font-weight: 600; font-size: 0.94rem; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--bg-2); }
.nav a[aria-current='page'] { color: var(--accent); background: var(--accent-soft); }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.theme-toggle svg { width: 18px; height: 18px; }
.menu-toggle { display: none; }
@media (max-width: 860px) {
  .menu-toggle {
    display: grid; place-items: center; margin-left: auto; width: 40px; height: 40px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; cursor: pointer;
  }
  .nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; align-items: stretch; padding: 8px 16px 16px; gap: 2px;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .nav.open { display: flex; }
  .nav a { padding: 10px 12px; }
  .site-header .theme-toggle { margin-left: 0; }
}

/* Buttons & form controls */
.btn {
  --b: var(--surface); --c: var(--text); --bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--bd); background: var(--b); color: var(--c);
  font: 650 0.95rem/1 var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); color: var(--c); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { --b: var(--accent); --c: var(--on-accent); --bd: var(--accent); }
.btn-primary:hover { --b: var(--accent-strong); --bd: var(--accent-strong); }
.btn-live { --b: var(--live); --c: #fff; --bd: var(--live); }
.btn-live:hover { --bd: var(--live); filter: brightness(1.08); }
.btn-ghost { --b: transparent; --bd: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg-2); border-color: transparent; }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 0.87rem; border-radius: 9px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
select, input[type='text'], input[type='number'], input[type='search'] {
  font: 500 0.95rem var(--sans); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); min-height: 40px; padding: 0 10px; max-width: 100%;
}
input[type='range'] { width: 100%; accent-color: var(--accent); }
label { font-weight: 600; font-size: 0.9rem; }
.field { display: grid; gap: 6px; }
.field small { color: var(--faint); font-weight: 500; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; font-size: 0.92rem; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 40px; height: 24px; border-radius: 99px; background: var(--border-strong); position: relative; cursor: pointer; flex: none; transition: background 0.15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch span small { display: block; color: var(--faint); font-weight: 500; font-size: 0.8rem; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.chip svg { width: 14px; height: 14px; color: var(--ok); }

/* Hero */
.hero { padding: 36px 0 18px; }
.hero p.lead { font-size: 1.1rem; color: var(--muted); max-width: 760px; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Decoder app */
.app { padding: 16px; display: grid; gap: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .spacer { flex: 1; }
.device-select { min-width: 0; max-width: 260px; }
.app-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .app-grid { grid-template-columns: minmax(0, 1fr); } }

.stage {
  position: relative; background: var(--stage); border-radius: 12px; overflow: hidden;
  aspect-ratio: 640 / 496; display: grid; place-items: center;
  background-image: linear-gradient(var(--stage-grid) 1px, transparent 1px), linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  border: 1px solid #111a2b;
}
.stage canvas { width: 100%; height: 100%; object-fit: contain; display: block; image-rendering: auto; }
.stage canvas.crisp { image-rendering: pixelated; }
.stage .overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px;
  color: #c7d4e8; pointer-events: none;
}
.stage .overlay[hidden] { display: none; }
.stage .overlay strong { display: block; font-size: 1.15rem; color: #fff; margin-bottom: 4px; }
.stage .overlay p { margin: 0; color: #93a4bd; font-size: 0.95rem; }
.stage .scanline { position: absolute; left: 0; right: 0; height: 2px; background: rgba(76, 178, 255, 0.85); box-shadow: 0 0 10px rgba(76,178,255,0.9); pointer-events: none; display: none; }
.stage.dragover { outline: 3px dashed var(--accent); outline-offset: -8px; }
.stage-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; margin-top: 10px; }
.stage-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.status-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 0.9rem; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 99px; font-weight: 700; font-size: 0.85rem; background: var(--bg-2); color: var(--muted); border: 1px solid var(--border); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.live { color: var(--live); background: color-mix(in srgb, var(--live) 10%, transparent); border-color: color-mix(in srgb, var(--live) 30%, transparent); }
.pill.live .dot { animation: pulse 1.2s infinite; }
.pill.ok { color: var(--ok); background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.pill.busy { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .pill.live .dot { animation: none; } html { scroll-behavior: auto; } }

.progress { height: 6px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 0.2s; }

.side { display: grid; gap: 14px; }
.panel { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface-2); }
.panel h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 0 0 10px; font-weight: 750; }
.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.readout { min-width: 0; }
.readout span { display: block; font-size: 0.75rem; color: var(--faint); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; }
.readout b { display: block; font: 700 1.02rem/1.3 var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; position: relative; margin-top: 4px; }
.meter > i { position: absolute; inset: 0 auto 0 0; width: 0%; background: linear-gradient(90deg, var(--ok), #c9c240 70%, var(--live)); border-radius: 99px; transition: width 0.08s; }
.waterfall { width: 100%; height: 150px; display: block; border-radius: 8px; background: #000; }
.wf-scale { position: relative; height: 18px; font: 600 0.7rem var(--mono); color: var(--faint); }
.wf-scale span { position: absolute; transform: translateX(-50%); top: 2px; }
.settings { display: grid; gap: 12px; }
.settings .field select { width: 100%; }

.adjust { display: grid; gap: 12px; }
.adjust[hidden] { display: none; }
.adjust .row { display: grid; grid-template-columns: 70px 1fr 56px; gap: 10px; align-items: center; font-size: 0.88rem; }
.adjust output { font: 600 0.82rem var(--mono); color: var(--muted); text-align: right; }

/* Gallery */
.gallery-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.gallery .empty { grid-column: 1 / -1; color: var(--faint); padding: 18px; border: 1px dashed var(--border-strong); border-radius: 12px; text-align: center; }
.thumb { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); cursor: pointer; padding: 0; text-align: left; color: var(--text); font: inherit; display: flex; flex-direction: column; }
.thumb:hover { border-color: var(--accent); }
.thumb img { width: 100%; aspect-ratio: 4/3; object-fit: contain; background: var(--stage); display: block; }
.thumb span { padding: 8px 10px; font-size: 0.8rem; display: flex; justify-content: space-between; gap: 6px; color: var(--muted); }
.thumb span b { color: var(--text); font-weight: 700; }

dialog.viewer { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); width: min(980px, calc(100% - 24px)); max-height: calc(100% - 24px); box-shadow: var(--shadow); }
dialog.viewer::backdrop { background: rgba(3, 6, 12, 0.7); }
.viewer .vbody { padding: 14px; display: grid; gap: 12px; }
.viewer img { width: 100%; border-radius: 10px; background: var(--stage); display: block; }
.viewer .vmeta { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 0.9rem; }
.viewer .vactions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Content */
.section { padding: 44px 0; }
.section-alt { background: var(--surface); border-block: 1px solid var(--border); }
.section .intro { color: var(--muted); max-width: 760px; }
.steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; counter-reset: step; margin-top: 18px; }
.step { padding: 18px; }
.step::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 800; margin-bottom: 10px; }
.features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 18px; }
.feature { padding: 18px; }
.feature svg { width: 26px; height: 26px; color: var(--accent); margin-bottom: 8px; }
.feature p, .step p { color: var(--muted); margin: 0; font-size: 0.95rem; }
@media (max-width: 860px) { .steps, .features { grid-template-columns: minmax(0, 1fr); } }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.fact { padding: 14px 16px; }
.fact span { display: block; font-size: 0.78rem; color: var(--faint); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.fact b { display: block; font-size: 1.15rem; margin-top: 2px; }
@media (max-width: 860px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tr.highlight td { background: var(--accent-soft); }

.faq { display: grid; gap: 10px; margin-top: 16px; }
.faq details { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 0 16px; }
.faq summary { cursor: pointer; font-weight: 700; padding: 14px 0; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '+'; color: var(--accent); font-size: 1.3rem; line-height: 1; }
.faq details[open] summary::after { content: '–'; }
.faq details > div { padding: 0 0 14px; color: var(--muted); }
.faq details > div p:last-child { margin-bottom: 0; }

.prose { max-width: 780px; }
.prose h2 { margin-top: 1.8em; }
.prose h3 { margin-top: 1.4em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin-bottom: 0.35em; }
.prose .note { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 12px 14px; border-radius: 0 10px 10px 0; color: var(--text); }
.toc { border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; background: var(--surface); margin: 18px 0; }
.toc ol { margin: 6px 0 0; padding-left: 1.2em; }
.breadcrumb { font-size: 0.88rem; color: var(--faint); margin-bottom: 10px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0 40px; color: var(--muted); font-size: 0.92rem; margin-top: 24px; }
.site-footer .cols { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; }
.site-footer h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
.site-footer ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
@media (max-width: 760px) { .site-footer .cols { grid-template-columns: 1fr; } }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; max-width: min(380px, calc(100% - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 11px 14px; border-radius: 10px; font-weight: 600; font-size: 0.92rem; box-shadow: var(--shadow); animation: toast-in 0.18s ease-out; }
.toast.error { background: var(--live); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* Pass predictor */
.pass-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .pass-grid { grid-template-columns: minmax(0, 1fr); } }
.skyplot { width: 100%; aspect-ratio: 1; display: block; }
.big-count { font: 800 clamp(1.6rem, 4vw, 2.3rem)/1.1 var(--mono); letter-spacing: -0.02em; }
.loc-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.loc-form .field { flex: 1 1 130px; }
.loc-form input { width: 100%; }

/* Encoder */
.enc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .enc-grid { grid-template-columns: minmax(0, 1fr); } }

/* Small screens */
.menu-toggle, .theme-toggle { flex: none; }
.brand { min-width: 0; }
.brand span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) {
  .brand small { display: none; }
  .hero { padding: 20px 0 12px; }
  .hero p.lead { font-size: 1rem; }
  .hero .chips { gap: 6px; }
  .chip { font-size: 0.76rem; padding: 3px 9px; }
  .app { padding: 12px; }
  .toolbar .btn { flex: 1 1 auto; }
  .toolbar .spacer { display: none; }
  .readout b { font-size: 0.95rem; }
}
