:root {
  /* Wada Sanzo -- electric pastels (diluted pigments on cold ground) */
  --bg: #0c0f14;
  --bg-elevated: #141820;
  --bg-recessed: #080a0e;
  --fg: #aeb6c2;           /* Blue Gray */
  --fg-muted: #6a7380;     /* Slate */
  --fg-bright: #dce0ea;    /* Pale Lavender */
  --accent: #8aacc6;       /* Forget-me-not */
  --accent-dim: #5a7a94;   /* deep forget-me-not */
  --green: #7ee8a8;        /* Electric Mint */
  --orchid: #ba85e0;       /* Electric Orchid */
  --red: #e870a8;          /* Electric Rose */
  --border: #1c2028;

  /* Glass */
  --glass-bg: rgba(20, 24, 32, 0.55);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-shine: rgba(255, 255, 255, 0.09);
  --glass-shadow: rgba(0, 0, 0, 0.3);
  --viz-rgb: 138, 172, 198;

  /* Noise texture -- tiny SVG for grain overlay */
  --noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
}

/* --- Themes --- */

[data-theme="phosphor"] {
  --bg: #080c08;
  --bg-elevated: #0c120c;
  --bg-recessed: #060806;
  --fg: #8ab88a;
  --fg-muted: #4a6a4a;
  --fg-bright: #c0e8c0;
  --accent: #40c040;
  --accent-dim: #2a8a2a;
  --green: #60e880;
  --orchid: #50c8c8;
  --red: #e06850;
  --border: #1a261a;
  --glass-bg: rgba(12, 18, 12, 0.55);
  --glass-border: rgba(64, 192, 64, 0.08);
  --glass-shine: rgba(64, 192, 64, 0.12);
  --glass-shadow: rgba(0, 0, 0, 0.4);
  --viz-rgb: 64, 192, 64;
}

[data-theme="void"] {
  --bg: #0a0a0c;
  --bg-elevated: #121214;
  --bg-recessed: #060608;
  --fg: #8a8a90;
  --fg-muted: #505058;
  --fg-bright: #c8c8d0;
  --accent: #9090a0;
  --accent-dim: #606070;
  --green: #90a890;
  --orchid: #a090b0;
  --red: #b08090;
  --border: #1a1a1e;
  --glass-bg: rgba(18, 18, 20, 0.55);
  --glass-border: rgba(144, 144, 160, 0.06);
  --glass-shine: rgba(144, 144, 160, 0.09);
  --glass-shadow: rgba(0, 0, 0, 0.35);
  --viz-rgb: 144, 144, 160;
}

[data-theme="sakura"] {
  --bg: #120c10;
  --bg-elevated: #1c1418;
  --bg-recessed: #0a0608;
  --fg: #c0a8b8;
  --fg-muted: #7a6878;
  --fg-bright: #e8d8e4;
  --accent: #e090c0;
  --accent-dim: #a06888;
  --green: #80d8b0;
  --orchid: #c888e0;
  --red: #e87090;
  --border: #241c22;
  --glass-bg: rgba(28, 20, 24, 0.55);
  --glass-border: rgba(224, 144, 192, 0.08);
  --glass-shine: rgba(224, 144, 192, 0.12);
  --glass-shadow: rgba(0, 0, 0, 0.35);
  --viz-rgb: 224, 144, 192;
}

@font-face {
  font-family: 'Departure Mono';
  src: local('Departure Mono');
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'New York', 'Iowan Old Style', ui-serif, Georgia, serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: background-color 0.5s ease, color 0.5s ease;
}

/* Grain overlay on entire page */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--noise);
  background-repeat: repeat;
  background-size: 256px 256px;
  pointer-events: none;
  z-index: 999;
  mix-blend-mode: overlay;
}

header {
  padding: 2rem 2rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.5s ease;
}

header h1 {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.2em;
  color: var(--fg-bright);
}

.subtitle {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--fg-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.25rem;
}

main {
  flex: 1;
  padding: 2rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* --- Station Display --- */

.station-display {
  border: 1px solid var(--glass-border);
  border-top-color: var(--glass-shine);
  background: var(--glass-bg);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 2px 8px var(--glass-shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  height: 9rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.station-display > * {
  display: block;
  width: 100%;
  text-align: center;
}

.station-display .display-status {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 0.35rem;
}

.station-display .display-status.on-air {
  color: var(--green);
}

.station-display .display-name {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  color: var(--fg-bright);
}

.station-display .display-format {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-top: 0.2rem;
}

.station-display .display-track {
  font-size: 0.8rem;
  color: var(--fg);
  margin-top: 0.5rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.static-indicator {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 1.1rem;
  letter-spacing: 0.3em;
  color: var(--fg-muted);
  animation: static-pulse 1.2s ease-in-out infinite;
}

@keyframes static-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.tune-prompt {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  color: var(--accent-dim);
}

/* --- Frequency Band --- */

.freq-band {
  border: 1px solid var(--glass-border);
  border-top-color: var(--glass-shine);
  background: var(--glass-bg);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: inset 0 1px 0 var(--glass-shine), 0 2px 8px var(--glass-shadow);
  padding: 1rem 1.5rem 0.75rem;
  margin-bottom: 1.5rem;
  position: relative;
}

.freq-band-label {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 0.75rem;
}

.freq-band-stations {
  position: relative;
  height: 1.25rem;
  margin-bottom: 0.35rem;
}

.freq-band-stations .station-label {
  position: absolute;
  transform: translateX(-50%);
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-muted);
  white-space: nowrap;
}

.freq-band-stations .station-label.active {
  color: var(--orchid);
}

.freq-band-track {
  position: relative;
  height: 6px;
  background: var(--border);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
  margin-bottom: 0.25rem;
}

.freq-band-track .station-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--orchid);
  transform: translateX(-50%);
}

.freq-band-track .tuning-indicator {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 4px;
  background: var(--accent);
  transform: translateX(-50%);
  transition: box-shadow 0.15s;
}

.freq-band-track .tuning-indicator.locked {
  box-shadow: 0 0 8px var(--accent);
}

/* --- Controls Row --- */

.controls-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  margin-bottom: 1.5rem;
  padding: 1.5rem 0;
}

/* --- Rotary Dials --- */

.dial-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.dial-label {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.dial-value {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.55rem;
  color: var(--fg-muted);
}

.tuning-dial,
.volume-dial {
  position: relative;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.tuning-dial {
  width: 140px;
  height: 140px;
}

.volume-dial {
  width: 100px;
  height: 100px;
}

.tuning-dial:active,
.volume-dial:active {
  cursor: grabbing;
}

.tuning-dial svg,
.volume-dial svg {
  width: 100%;
  height: 100%;
  display: block;
}

.dial-knob-ring {
  stroke: var(--fg-muted);
  stroke-width: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.dial-knob-inner {
  fill: none;
  stroke: var(--fg-muted);
  stroke-width: 0.5;
  opacity: 0.4;
}

.dial-tick {
  stroke: var(--fg-muted);
  stroke-width: 0.7;
  opacity: 0.45;
}

.dial-indicator {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: butt;
}

.volume-dial .dial-indicator {
  stroke: var(--green);
}

/* --- Power Toggle --- */

.power-toggle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.power-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.power-toggle span {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
  transition: color 0.15s;
}

.power-toggle span.active {
  color: var(--fg-bright);
}

.power-switch {
  position: relative;
  width: 40px;
  height: 20px;
  border: 1px solid var(--border);
  background: var(--bg-recessed);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

.power-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 14px;
  background: var(--fg-muted);
  transition: left 0.2s, background 0.2s;
}

.power-switch:checked::before {
  left: 20px;
  background: var(--green);
}

.power-switch:checked {
  border-color: var(--green);
}

/* --- Call-in Button --- */

.call-in-btn {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  background: transparent;
  color: var(--orchid);
  border: 1px solid var(--orchid);
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.call-in-btn:hover {
  background: color-mix(in srgb, var(--orchid) 12%, transparent);
}

.call-in-btn.recording {
  background: var(--red);
  border-color: var(--red);
  color: var(--bg);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Utility Row (call-in below controls) --- */

.utility-row {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

/* --- History --- */

.history {
  border: 1px solid var(--glass-border);
  border-top-color: var(--glass-shine);
  padding: 1.5rem;
  margin-bottom: 2rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  box-shadow:
    inset 0 1px 0 var(--glass-shine),
    0 2px 8px var(--glass-shadow),
    0 0 calc(var(--e, 0) * 25px) color-mix(in srgb, var(--accent) 30%, transparent);
  position: relative;
  overflow: hidden;
}

.history h2 {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 1rem;
}

.history-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.history-row:last-child {
  border-bottom: none;
}

.history-time {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.65rem;
  color: var(--fg-muted);
  flex-shrink: 0;
  width: 3.5rem;
}

.history-track {
  flex: 1;
  color: var(--fg);
}

.history-meta {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.6rem;
  color: var(--accent-dim);
  flex-shrink: 0;
}

.history-empty {
  font-size: 0.8rem;
  color: var(--fg-muted);
  font-style: italic;
}

/* --- Transcript --- */

.transcript {
  border: 1px solid var(--glass-border);
  border-top-color: var(--glass-shine);
  padding: 1.5rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  box-shadow:
    inset 0 1px 0 var(--glass-shine),
    0 2px 8px var(--glass-shadow),
    0 0 calc(var(--e, 0) * 25px) color-mix(in srgb, var(--accent) 30%, transparent);
  position: relative;
  overflow: hidden;
}

.transcript h2 {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 1rem;
}

.transcript-lines {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--fg);
}

/* --- Footer --- */

footer {
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 0.65rem;
  color: var(--fg-muted);
  letter-spacing: 0.05em;
  transition: border-color 0.5s ease, color 0.5s ease;
}

/* --- Unmute Overlay --- */

.unmute-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.unmute-overlay.hidden {
  display: none;
}

.unmute-btn {
  font-family: 'Departure Mono', ui-monospace, monospace;
  font-size: 1.2rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1.25rem 3rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.unmute-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

/* --- Theme Picker --- */

.theme-picker {
  position: absolute;
  top: 2rem;
  right: 2rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.theme-dot {
  width: 10px;
  height: 10px;
  padding: 0;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: box-shadow 0.2s, border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.theme-dot[data-theme="midnight"]  { background: #8aacc6; }
.theme-dot[data-theme="phosphor"]  { background: #40c040; }
.theme-dot[data-theme="void"]      { background: #9090a0; }
.theme-dot[data-theme="sakura"]    { background: #e090c0; }

.theme-dot.active {
  border-color: var(--fg-muted);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--fg-muted);
}

.theme-dot:hover:not(.active) {
  border-color: var(--fg-muted);
}

/* --- Glass Panel Motion --- */

.station-display,
.freq-band,
.history,
.transcript {
  transition:
    background 0.5s ease,
    border-color 0.5s ease,
    box-shadow 0.15s ease;
}

.station-display:hover,
.freq-band:hover,
.history:hover,
.transcript:hover {
  border-color: var(--glass-shine);
  box-shadow:
    inset 0 1px 0 var(--glass-shine),
    0 4px 20px var(--glass-shadow),
    0 0 calc(var(--e, 0) * 35px + 4px) color-mix(in srgb, var(--accent) 40%, transparent);
}

/* Shimmer gradient overlay (liquid refraction) */
.station-display::before,
.history::before,
.transcript::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    transparent 0%,
    color-mix(in srgb, var(--accent) 4%, transparent) 40%,
    color-mix(in srgb, var(--accent) 8%, transparent) 50%,
    color-mix(in srgb, var(--accent) 4%, transparent) 60%,
    transparent 100%
  );
  background-size: 250% 250%;
  animation: glass-shimmer 6s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

.station-display > *,
.history > *,
.transcript > * {
  position: relative;
  z-index: 1;
}

@keyframes glass-shimmer {
  0%, 100% { background-position: 200% 200%; }
  50% { background-position: 0% 0%; }
}

@keyframes glass-enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.station-display { animation: glass-enter 0.5s ease 0.05s both; }
.freq-band { animation: glass-enter 0.5s ease 0.1s both; }
.history { animation: glass-enter 0.5s ease 0.15s both; }
.transcript { animation: glass-enter 0.5s ease 0.2s both; }

/* --- ASCII Visualizer --- */

#ascii-viz {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.14;
}

header, main, footer {
  position: relative;
  z-index: 2;
}

/* --- Responsive --- */

@media (max-width: 600px) {
  .controls-row {
    gap: 1rem;
  }

  .tuning-dial {
    width: 110px;
    height: 110px;
  }

  .volume-dial {
    width: 80px;
    height: 80px;
  }

  .freq-band-stations .station-label {
    font-size: 0.4rem;
  }

  footer {
    flex-direction: column;
    gap: 0.25rem;
  }
}
