:root {
  --bg: #0b0f1a;
  --bg-2: #111827;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --text-dim: #8b94a7;
  --accent: #ffc864;
  --accent-soft: rgba(255, 200, 100, 0.18);
  --accent-2: #5eead4;
  --danger: #fb7185;
  --radius: 18px;
  --knob-size: min(42vw, 190px);
  --knob-vol-size: min(30vw, 130px);
}

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

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 50% -10%, #16213a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100%;
  overscroll-behavior: none;
}

body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, transparent 38%, var(--accent) 40%, transparent 44%),
    radial-gradient(circle at 50% 50%, transparent 18%, var(--accent) 20%, transparent 24%),
    var(--bg-2);
  box-shadow: 0 0 14px var(--accent-soft);
}

.brand h1 { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: 0.04em; }
.brand h1 span { color: var(--accent); font-weight: 300; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-pill .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s, box-shadow 0.3s;
}

.status-pill.live .dot { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.status-pill.live { color: var(--accent-2); }

.icon-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 12px;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.2s, transform 0.2s;
}
.icon-btn:active { transform: scale(0.92); color: var(--accent); }

/* ---------- Plate visualization ---------- */
.plate-wrap {
  position: relative;
  width: min(100%, 42vh);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.plate-wrap.circle #plate { border-radius: 50%; }
.plate-wrap.circle .res-chip {
  inset-inline-start: auto;
  left: 50%;
  transform: translateX(-50%);
}
.plate-wrap.circle .res-chip:active { transform: translateX(-50%) scale(0.95); }
.plate-wrap.circle .mode-label {
  bottom: auto;
  top: 12px;
  inset-inline-end: auto;
  left: 50%;
  transform: translateX(-50%);
}

#plate {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #141a2b, #0d1220);
  border: 1px solid var(--panel-border);
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.6),
    0 10px 40px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.mode-label {
  position: absolute;
  bottom: 10px;
  inset-inline-end: 14px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0.7;
  pointer-events: none;
}

.res-chip {
  position: absolute;
  bottom: 10px;
  inset-inline-start: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  direction: ltr;
  background: rgba(11, 15, 26, 0.75);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: color 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.res-chip .res-icon { font-size: 14px; line-height: 1; }
.res-chip:active { transform: scale(0.95); }
.res-chip.locked {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 14px var(--accent-soft);
}

/* numeric rows keep LTR order even in RTL languages */
.readout, .fine-row, .presets-row, .sweep-speed { direction: ltr; }

/* ---------- Frequency readout ---------- */
.readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  padding: 2px 0;
}

.freq-value {
  font-size: clamp(44px, 13vw, 64px);
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--text);
  text-shadow: 0 0 30px var(--accent-soft);
  line-height: 1;
}

.freq-unit { font-size: 20px; color: var(--accent); font-weight: 600; }
.readout:has(.freq-input:not([hidden])) .freq-unit { display: none; }

.freq-input {
  font-size: 44px;
  font-weight: 200;
  width: 220px;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
  text-align: center;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.freq-input::-webkit-outer-spin-button,
.freq-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ---------- Fine tune ---------- */
.fine-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.fine-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.fine-btn:active { background: var(--accent-soft); color: var(--accent); transform: scale(0.94); }

/* ---------- Knobs ---------- */
.knobs {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  gap: 10px;
  padding: 6px 0;
}

.knob-block { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.knob-block label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.knob {
  position: relative;
  border-radius: 50%;
  touch-action: none;
  cursor: grab;
  outline: none;
}
.knob:active { cursor: grabbing; }
.knob:focus-visible .knob-face { box-shadow: 0 0 0 2px var(--accent), 0 14px 30px rgba(0,0,0,0.5); }

.knob-freq { width: var(--knob-size); height: var(--knob-size); }
.knob-vol  { width: var(--knob-vol-size); height: var(--knob-vol-size); }

.knob-face {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #2a3450 0%, #1a2138 45%, #101526 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.08),
    inset 0 -8px 18px rgba(0, 0, 0, 0.5),
    0 14px 30px rgba(0, 0, 0, 0.5);
  transition: transform 0.05s linear;
}

.knob-ticks {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255,255,255,0.14) 0deg 1.6deg,
    transparent 1.6deg 30deg
  );
  -webkit-mask: radial-gradient(circle, transparent 62%, black 64%, black 78%, transparent 80%);
  mask: radial-gradient(circle, transparent 62%, black 64%, black 78%, transparent 80%);
}

.knob-pointer {
  position: absolute;
  top: 7%;
  left: 50%;
  width: 4px;
  height: 17%;
  margin-left: -2px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.knob-vol .knob-pointer { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }

.knob-center {
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 40% 35%, #1d2540, #0e1322);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.knob-center span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}
.knob-vol .knob-center span { font-size: 17px; color: var(--accent-2); letter-spacing: 0.02em; }

.knob-ring { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }
.ring-bg { fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 2.5; }
.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 295.3;  /* 2πr, r=47 */
  stroke-dashoffset: 295.3;
  filter: drop-shadow(0 0 4px var(--accent));
  transition: stroke-dashoffset 0.08s linear;
}
#volRingFg { stroke: var(--accent-2); filter: drop-shadow(0 0 4px var(--accent-2)); }

/* ---------- Transport ---------- */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 86px;
}

.play-btn {
  width: 82px; height: 82px;
  border-radius: 50%;
  border: 1px solid rgba(255, 200, 100, 0.35);
  background: radial-gradient(circle at 35% 30%, rgba(255,200,100,0.22), rgba(255,200,100,0.06));
  color: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.3s;
  box-shadow: 0 0 0 rgba(255,200,100,0);
}
.play-btn:active { transform: scale(0.92); }
.play-btn.playing {
  box-shadow: 0 0 34px rgba(255, 200, 100, 0.35);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 22px rgba(255, 200, 100, 0.25); }
  50% { box-shadow: 0 0 44px rgba(255, 200, 100, 0.5); }
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.pill-btn.active { color: var(--accent-2); border-color: var(--accent-2); box-shadow: 0 0 14px rgba(94, 234, 212, 0.2); }

.sweep-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 110px;
}
.sweep-speed input { width: 100%; accent-color: var(--accent-2); }
.sweep-speed span { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 34px; }

/* ---------- Presets ---------- */
.presets-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.preset-btn {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  color: var(--text);
  padding: 10px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
  overflow: hidden;
}
.preset-btn:active { transform: scale(0.94); }
.preset-btn .p-num {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--text-dim);
}
.preset-btn .p-val {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.preset-btn .p-val small { font-size: 9px; font-weight: 400; color: var(--text-dim); }
.preset-btn .p-vol { font-size: 9px; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.preset-btn.empty .p-val { color: var(--text-dim); font-weight: 300; }
.preset-btn.current { border-color: var(--accent); background: var(--accent-soft); }
.preset-btn.current .p-num { color: var(--accent); }

.preset-btn .hold-fill {
  position: absolute;
  inset: 0;
  background: var(--accent-soft);
  transform: scaleX(0);
  transform-origin: left;
  pointer-events: none;
}
.preset-btn.holding .hold-fill {
  transform: scaleX(1);
  transition: transform 0.65s linear;
}

.presets-hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
}

/* ---------- Footer ---------- */
.hint { text-align: center; }
.hint p { font-size: 12px; color: var(--text-dim); margin: 4px 0; }
.hint strong { color: var(--text); }
.credit {
  direction: ltr;
  font-size: 11px;
  opacity: 0.75;
  margin-top: 10px;
}

/* ---------- Settings dialog ---------- */
dialog {
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--bg-2);
  color: var(--text);
  padding: 22px;
  width: min(92vw, 420px);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}
dialog::backdrop { background: rgba(5, 8, 15, 0.7); backdrop-filter: blur(4px); }

.settings-form h2 { margin: 0 0 18px; font-size: 20px; font-weight: 600; }

.settings-section {
  margin: 22px 0 14px;
  padding-top: 16px;
  border-top: 1px solid var(--panel-border);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.field-note { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); line-height: 1.5; }

.field.disabled { opacity: 0.4; pointer-events: none; }

/* toggle switch */
.field-toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.field-toggle > label:first-child { font-size: 14px; color: var(--text); }

.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.switch-track::before {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  top: 3px;
  inset-inline-start: 4px;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + .switch-track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(20px); background: var(--accent); }
html[dir="rtl"] .switch input:checked + .switch-track::before { transform: translateX(-20px); }

/* ---------- Info dialog ---------- */
.info-content { position: relative; }
.info-content h2 { margin: 0 0 14px; font-size: 20px; font-weight: 600; padding-inline-end: 44px; }
.info-content p { font-size: 14px; line-height: 1.65; color: var(--text); margin: 0 0 12px; }
.info-content strong { color: var(--accent); font-weight: 600; }
.info-content em { color: var(--accent-2); font-style: normal; }
.info-close {
  position: absolute;
  top: -4px;
  inset-inline-end: -4px;
  font-size: 16px;
}

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.field label { font-size: 12px; color: var(--text-dim); letter-spacing: 0.04em; }
.field label strong { color: var(--accent); }

.field input[type="number"], .field select {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 16px;
  outline: none;
  width: 100%;
}
.field input[type="number"]:focus, .field select:focus { border-color: var(--accent); }
.field input[type="range"] { accent-color: var(--accent); }
.field select option { background: var(--bg-2); }

.dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.dialog-actions-end { display: flex; gap: 10px; }

.primary-btn {
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: 12px;
  padding: 12px 26px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.ghost-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: rgba(20, 26, 43, 0.95);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .app { max-width: 520px; }
}
