:root {
  --bg: #070d1a;
  --card-bg: #0f172a;
  --input-bg: #0b1324;
  --border: #22324a;
  --border-light: #304766;
  --text: #e7edf9;
  --text-muted: #91a3bd;
  --text-heading: #c6d5ea;
  --btn-bg: #16243a;
  --btn-border: #3a5274;
  --accent-green: #c24b1a;
  --accent-yellow: #f0ad4e;
  --accent-red: #e55353;
  --control-height: 2.6rem;
  --jog-hi: #243a5b;
  --jog-lo: #14233a;
  --jog-shadow: rgba(0,0,0,0.3);
  --jog-inset: rgba(255,255,255,0.05);
  --audio-level-bg: #14263f;
  --audio-level-border: #304766;
  --audio-level-fill-start: #c24b1a;
  --audio-level-fill-end: #f0ad4e;
  --filter-bg: #13253e;
  --filter-fg: #e7edf9;
  --filter-border: #385577;
  --wavelength-fg: #8da3be;
  --jog-wheel-size: 83.2px;
}

[data-theme="light"] {
  --bg: #edf2f7;
  --card-bg: #ffffff;
  --input-bg: #f7fafc;
  --border: #d6deea;
  --border-light: #bcc8da;
  --text: #1a202c;
  --text-muted: #4a5568;
  --text-heading: #2d3748;
  --btn-bg: #e6edf8;
  --btn-border: #a9b8cf;
  --accent-green: #b04317;
  --accent-yellow: #b57600;
  --accent-red: #cf3f3f;
  --jog-hi: #e6edf8;
  --jog-lo: #cdd9eb;
  --jog-shadow: rgba(58, 79, 110, 0.18);
  --jog-inset: rgba(255,255,255,0.75);
  --audio-level-bg: #edf2fb;
  --audio-level-border: #b8c5da;
  --audio-level-fill-start: #b04317;
  --audio-level-fill-end: #b57600;
  --filter-bg: #eef3fb;
  --filter-fg: #1f2937;
  --filter-border: #b8c5da;
  --wavelength-fg: #6b7280;
}

body { font-family: sans-serif; margin: 0; min-height: 100vh; box-sizing: border-box; display: flex; align-items: flex-start; justify-content: center; padding-top: 2em; background: var(--bg); color: var(--text); }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem 1.75rem; width: 60vw; box-shadow: 0 12px 40px rgba(0,0,0,0.35); background: var(--card-bg); }
.label { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 6px; display: block; }
#tab-main .label > span {
  display: inline-block;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border-light) 68%, transparent);
  background: color-mix(in srgb, var(--btn-bg) 58%, transparent);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.status { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.1rem 1rem; }
input.status-input, select.status-input { width: 100%; padding: 0.45rem 0.5rem; font-size: 1rem; border: 1px solid var(--border-light); border-radius: 6px; background: var(--input-bg); color: var(--text); }
#mode { height: var(--control-height); }
#freq { font-family: 'DSEG14 Classic', monospace; font-size: 2rem; padding: 0.5rem 0.6rem; letter-spacing: 0.05em; text-align: center; }
.controls-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: start;
}
.controls-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.controls-col.label-below-col {
  align-items: stretch;
}
.controls-col.label-below-col .label {
  order: 2;
  margin-top: 0.3rem;
  margin-bottom: 0;
}
.controls-col-power.label-below-col .label {
  justify-content: flex-end;
}
.controls-col.label-below-col > :not(.label) {
  order: 1;
}
.controls-col.label-below-col .inline,
.controls-col.label-below-col .btn-grid {
  align-self: stretch;
  width: 100%;
  margin-top: calc((var(--jog-wheel-size) - var(--control-height)) / 2);
}
.controls-col-center {
  justify-self: center;
  width: auto;
  align-items: center;
}
.controls-col-center::after {
  content: "";
  display: block;
  min-height: 1.2rem;
  margin-top: 0.3rem;
}
.controls-row .label {
  margin-bottom: 6px;
  margin-top: 0;
  min-height: 1.2rem;
  display: flex;
  align-items: center;
  white-space: nowrap;
}
.controls-col .inline,
.controls-col .btn-grid {
  align-self: stretch;
}
.controls-col .jog-container { align-self: center; }
.btn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}
.btn-grid button { width: 100%; height: var(--control-height); }
.jog-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.jog-wheel {
  width: var(--jog-wheel-size);
  height: var(--jog-wheel-size);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--jog-hi), var(--jog-lo));
  border: 2px solid var(--border-light);
  position: relative;
  cursor: grab;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--jog-shadow), inset 0 1px 0 var(--jog-inset);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.jog-indicator {
  position: absolute;
  width: 6.4px;
  height: 16px;
  background: var(--accent-green);
  border-radius: 2px;
  top: 6.4px;
  left: 50%;
  transform-origin: 50% 35.2px;
  transform: translateX(-50%);
  pointer-events: none;
}
.jog-btn {
  width: 3.3rem;
  height: 3.3rem;
  font-size: 1.8rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.jog-step {
  display: flex;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow: hidden;
  height: 3.35rem;
  flex-shrink: 0;
}
.jog-step button {
  border: none;
  border-right: 1px solid var(--border-light);
  border-radius: 0;
  height: 100%;
  padding: 0 0.8rem;
  font-size: 0.92rem;
  background: var(--input-bg);
  color: var(--text-muted);
  cursor: pointer;
}
.jog-step button:last-child { border-right: none; }
.jog-step button.active {
  background: var(--btn-bg);
  color: var(--accent-green);
  font-weight: 600;
}
.vfo-picker {
  display: flex;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  overflow: hidden;
}
.vfo-picker button {
  flex: 1;
  border: none;
  border-right: 1px solid var(--border-light);
  border-radius: 0;
  height: var(--control-height);
  background: var(--input-bg);
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
}
.vfo-picker button:last-child { border-right: none; }
.vfo-picker button.active {
  background: var(--btn-bg);
  font-weight: 600;
}
.signal-measure {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.4rem;
}
button { padding: 0.5rem 0.9rem; border-radius: 6px; border: 1px solid var(--btn-border); background: var(--btn-bg); color: var(--text); cursor: pointer; height: var(--control-height); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
.hint { color: var(--text-muted); font-size: 0.85rem; }
.inline { display: flex; gap: 0.5rem; align-items: center; }
.freq-inline {
  align-items: flex-start;
}
.freq-field {
  display: grid;
  grid-template-rows: 3.35rem auto;
  align-items: start;
}
.freq-field .label {
  margin-top: 0.45rem;
  margin-bottom: 0;
}
.frequency-col {
  flex: 1 1 auto;
  min-width: 0;
}
.frequency-col #freq {
  width: 100%;
  height: 3.35rem;
  box-sizing: border-box;
}
.wavelength-col {
  flex: 0 0 auto;
}
.unit-col {
  flex: 0 0 auto;
}
.unit-col .label {
  display: flex;
  justify-content: flex-end;
}
.label-below-row {
  display: flex;
  flex-direction: column;
}
#tab-main .label > span {
  text-align: center;
}
.label-below-row > .label {
  order: 2;
  margin-top: 0.45rem;
  margin-bottom: 0;
}
.label-below-row > :not(.label) {
  order: 1;
}
.wavelength-display {
  min-width: 6.2rem;
  height: 3.35rem;
  padding: 0 0.7rem;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--wavelength-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'DSEG14 Classic', monospace;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
}
small { color: var(--text-muted); }
.header {
  display: grid;
  grid-template-columns: 16em 1fr auto;
  align-items: center;
  column-gap: 1.5em;
  margin-bottom: 0.25rem;
}
.header-text {
  width: 16em;
  min-width: 16em;
  flex: 0 0 16em;
}
.title { font-size: 1.4rem; font-weight: 700; display: inline-flex; align-items: center; gap: 0.35rem; }
.header-signal-wrap {
  width: 100%;
  min-width: 160px;
  height: clamp(2.6rem, 8vh, 4.5rem);
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--border-light) 55%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--input-bg) 72%, transparent);
  opacity: 0.45;
  overflow: hidden;
}
#header-sig-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.header-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.header-logo { height: 6em; width: auto; flex-shrink: 0; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.35)); }
.button-group {
  display: flex;
  gap: 0;
  align-items: center;
}

.button-group .theme-toggle-btn {
  border-radius: 0;
  margin-left: -1px;
}

.button-group .theme-toggle-btn:first-child {
  border-radius: 999px 0 0 999px;
  margin-left: 0;
}

.button-group .theme-toggle-btn:last-child:not(:first-child) {
  border-radius: 0 999px 999px 0;
}

.theme-toggle-btn {
  height: 1.7rem;
  min-height: 1.7rem;
  padding: 0 0.65rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 999px;
  border: 1px solid var(--btn-border);
  background: linear-gradient(135deg, color-mix(in srgb, var(--btn-bg) 82%, #ffffff), var(--btn-bg));
  color: var(--text);
  cursor: pointer;
  transition: all 150ms ease;
}

.theme-toggle-btn:hover {
  opacity: 0.9;
}
[data-theme="light"] .theme-toggle-btn {
  background: linear-gradient(135deg, #0f172a, #334155);
  border-color: #334155;
  color: #f8fafc;
}
.subtitle { color: var(--text-muted); font-size: 0.95rem; }
.subtitle a { color: var(--accent-green); text-decoration: none; }
.subtitle a:hover { text-decoration: underline; }
.band-tag { display: inline-block; padding: 2px 6px; border-radius: 6px; background: var(--btn-bg); color: var(--text); font-size: 0.82rem; border: 1px solid var(--border-light); margin-left: 6px; }
.signal { display: flex; gap: 0.6rem; align-items: center; }
.signal-bar { flex: 1 1 auto; height: 12px; border-radius: 999px; background: var(--btn-bg); border: 1px solid var(--border-light); overflow: hidden; }
.signal-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-green), var(--accent-yellow), var(--accent-red)); transition: width 150ms ease; }
.signal-value { font-size: 0.95rem; color: var(--text-heading); min-width: 48px; text-align: right; }
.meter { display: flex; gap: 0.6rem; align-items: center; }
.meter-bar { flex: 1 1 auto; height: 12px; border-radius: 999px; background: var(--btn-bg); border: 1px solid var(--border-light); overflow: hidden; }
.meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-green), var(--accent-yellow), var(--accent-red)); transition: width 150ms ease; }
.meter-value { font-size: 0.95rem; color: var(--text-heading); min-width: 64px; text-align: right; }
#content { display: flex; flex-direction: column; gap: 1.1rem; }
.tab-bar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1rem; position: relative; z-index: 2; }
.tab { background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 0.5rem 1rem; color: var(--text-muted); cursor: pointer; font-size: 0.95rem; height: auto; }
.tab.active { border-bottom-color: var(--accent-green); color: var(--accent-green); font-weight: 600; }
.tab:hover:not(.active) { color: var(--text); }
.about-table { width: 100%; border-collapse: collapse; }
.about-table td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.about-table tr:last-child td { border-bottom: none; }
.about-table td:first-child { color: var(--text-muted); width: 40%; }
.plugin-item { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); color: var(--text); }
.plugin-item:last-child { border-bottom: none; }
.footer { display: flex; justify-content: space-between; align-items: baseline; margin-top: 1.1rem; }
.full-row { grid-column: 1 / -1; }
.copyright { color: var(--text-muted); font-size: 0.75rem; opacity: 0.7; }
.copyright a { color: var(--accent-green); text-decoration: none; }
.copyright a:hover { text-decoration: underline; }

.vol-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}
.vol-pct {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1;
}
.vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 6px;
  border-radius: 3px;
  background: var(--btn-bg);
  border: 1px solid var(--border-light);
  outline: none;
  cursor: pointer;
}
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-green);
  border: none;
  cursor: pointer;
}
.vol-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-green);
  border: none;
  cursor: pointer;
}
#audio-level {
  flex: 1 1 auto;
  height: 12px;
  border-radius: 999px;
  background: var(--audio-level-bg);
  border: 1px solid var(--audio-level-border);
  overflow: hidden;
  min-width: 80px;
}
#audio-level-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--audio-level-fill-start), var(--audio-level-fill-end));
  transition: width 100ms ease;
}

.sub-tab-bar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 0.75rem; }
.sub-tab { background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 0.35rem 0.75rem; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; height: auto; }
.sub-tab.active { border-bottom-color: var(--accent-green); color: var(--accent-green); font-weight: 600; }
.sub-tab:hover:not(.active) { color: var(--text); }
#aprs-map { min-height: 150px; border-radius: 6px; }
.aprs-controls { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.75rem; }
#aprs-packets { max-height: 360px; overflow-y: auto; border: 1px solid var(--border-light); border-radius: 6px; background: var(--input-bg); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.aprs-packet { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.82rem; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); line-height: 1.4; }
.aprs-packet:last-child { border-bottom: none; }
.aprs-call { color: var(--accent-green); font-weight: 600; }
.aprs-time { color: var(--text-muted); margin-right: 0.5rem; }
.aprs-symbol { display: inline-block; width: 24px; height: 24px; background-size: 384px 192px; vertical-align: middle; margin-right: 0.3rem; }
.aprs-pos { color: var(--accent-green); text-decoration: none; margin-left: 0.3rem; font-size: 0.8rem; }
.aprs-pos:hover { text-decoration: underline; }
.aprs-byte { color: var(--accent-yellow); background: rgba(255, 214, 0, 0.12); border: 1px solid rgba(255, 214, 0, 0.25); border-radius: 4px; padding: 0 0.2rem; margin: 0 0.1rem; font-size: 0.78em; }
.ft8-controls { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.75rem; }
.ft8-filter {
  flex: 1;
  min-width: 10rem;
  height: var(--control-height);
  box-sizing: border-box;
  background: var(--filter-bg);
  color: var(--filter-fg);
  border: 1px solid var(--filter-border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}
.ft8-filter::placeholder { color: color-mix(in srgb, var(--filter-fg) 55%, transparent); }
.ft8-header { display: flex; gap: 0.6rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); border-bottom: 1px solid var(--border); padding: 0 0 0.35rem 0; margin-bottom: 0.35rem; }
#ft8-messages { max-height: 360px; overflow-y: auto; border: 1px solid var(--border-light); border-radius: 6px; background: var(--input-bg); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.85rem; padding: 0.35rem 0.5rem; }
.ft8-row { display: flex; gap: 0.6rem; line-height: 1.4; border-bottom: 1px solid var(--border); padding: 0.25rem 0; }
.ft8-row:last-child { border-bottom: none; }
.ft8-time { color: var(--text-muted); min-width: 4.6rem; }
.ft8-snr { color: var(--accent-yellow); min-width: 3.6rem; text-align: right; }
.ft8-dt { color: var(--text-muted); min-width: 3.6rem; text-align: right; }
.ft8-freq { color: var(--accent-green); min-width: 4.6rem; text-align: right; }
.ft8-msg { flex: 1; }
.ft8-locator { color: var(--accent-green); background: rgba(0, 209, 127, 0.12); border: 1px solid rgba(0, 209, 127, 0.25); border-radius: 4px; padding: 0 0.2rem; margin: 0 0.1rem; font-weight: 600; }
.map-controls { display: flex; gap: 1rem; align-items: center; margin-bottom: 0.6rem; color: var(--text-muted); font-size: 0.82rem; }
.map-controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--filter-border);
  background: var(--filter-bg);
  color: var(--filter-fg);
}
.map-controls input[type="checkbox"] { margin-right: 0.3rem; }

.cw-controls { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.75rem; }
.cw-config { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.cw-config label { display: flex; flex-direction: column; gap: 0.2rem; color: var(--text-muted); font-size: 0.82rem; }
.cw-config input[type="number"] { width: 5rem; padding: 0.3rem 0.4rem; font-size: 0.9rem; border: 1px solid var(--border-light); border-radius: 6px; background: var(--input-bg); color: var(--text); }
#cw-output { max-height: 360px; overflow-y: auto; border: 1px solid var(--border-light); border-radius: 6px; background: var(--input-bg); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 0.85rem; padding: 0.4rem 0.5rem; min-height: 60px; white-space: pre-wrap; word-break: break-all; }
.cw-line { line-height: 1.5; }
.cw-signal-on { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); flex-shrink: 0; }
.cw-signal-off { width: 10px; height: 10px; border-radius: 50%; background: var(--border-light); flex-shrink: 0; }
.cw-config .cw-auto-label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; color: var(--text-muted); cursor: pointer; flex-direction: row; }
.cw-auto-label input[type="checkbox"] { margin: 0; cursor: pointer; }
.cw-config input[type="number"][readonly] { opacity: 0.6; }

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

@media (max-width: 900px) {
  .card { width: 90vw; }
}

@media (max-width: 760px) {
  .card { padding: 1rem; }
  button { min-height: 2.8rem; font-size: 0.95rem; }
  input.status-input, select.status-input { font-size: 1.1rem; }
  .header-text { width: auto; min-width: 0; flex: 0 1 auto; }
  .header-signal-wrap { display: none; }
  .header-right { align-items: flex-end; }
  .controls-row { grid-template-columns: 1fr auto; }
  .controls-col-power { grid-column: 1 / -1; }
  .controls-col.label-below-col .inline,
  .controls-col.label-below-col .btn-grid { margin-top: 0; }
  .ft8-controls { flex-wrap: wrap; }
  #ft8-decode-toggle-btn, #wspr-decode-toggle-btn { white-space: nowrap; }
  .jog-container { flex-wrap: wrap; }
  .vfo-picker { flex-direction: column; }
  .vfo-picker button { border-right: none; border-bottom: 1px solid var(--border-light); }
  .vfo-picker button:last-child { border-bottom: none; }
}
