/*
 * RADIO DECK — futuristic control-deck theme
 *
 * 配色トークンは :root にまとめてある。差し替えはここだけで済む。
 */
:root {
  --bg-0: #04060c;
  --bg-1: #0a1120;
  --panel: rgba(12, 19, 34, 0.86);
  --panel-bright: rgba(20, 30, 52, 0.9);
  --line: rgba(79, 242, 255, 0.2);
  --line-strong: rgba(79, 242, 255, 0.5);
  --cyan: #4ff2ff;
  --cyan-soft: rgba(79, 242, 255, 0.14);
  --amber: #ffb35f;
  --ink: #dce8f7;
  --muted: #7d90ac;
  --ok: #3dff9c;
  --warn: #ffd166;
  --dead: #ff5364;
  --font-display: "Orbitron", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Share Tech Mono", ui-monospace, "Cascadia Mono", "Osaka-Mono", monospace;
  --font-body: "Segoe UI", system-ui, -apple-system, "Hiragino Kaku Gothic ProN", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg-0);
}

body {
  min-height: 100vh;
  margin: 0;
  padding: clamp(14px, 3vw, 34px) 16px 170px;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 620px at 78% -10%, rgba(66, 108, 255, 0.16), transparent 62%),
    radial-gradient(900px 520px at 8% 8%, rgba(79, 242, 255, 0.1), transparent 58%),
    radial-gradient(760px 560px at 55% 118%, rgba(255, 138, 61, 0.1), transparent 60%),
    linear-gradient(165deg, var(--bg-1) 0%, var(--bg-0) 55%, #060911 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ---- 背景レイヤー: グリッド + スキャンライン ---- */
.deck-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(79, 242, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 242, 255, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 80% at 50% 20%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 90% 80% at 50% 20%, #000 30%, transparent 100%);
}

.deck-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0 3px,
    rgba(0, 0, 0, 0.16) 3px 4px
  );
  animation: scan-drift 9s linear infinite;
  opacity: 0.5;
}

@keyframes scan-drift {
  from { transform: translateY(0); }
  to   { transform: translateY(4px); }
}

button {
  font: inherit;
  color: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
  width: min(1160px, 100%);
  margin: 0 auto;
}

/* ---- 共通パネル ---- */
.panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(160deg, rgba(79, 242, 255, 0.05), transparent 34%),
    var(--panel);
  box-shadow:
    0 0 0 1px rgba(4, 8, 16, 0.8),
    0 18px 44px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(79, 242, 255, 0.1);
  backdrop-filter: blur(9px);
}

/* パネル四隅のブラケット装飾 */
.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line-strong);
  pointer-events: none;
}

.panel::before {
  top: -1px;
  left: -1px;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 10px;
}

.panel::after {
  right: -1px;
  bottom: -1px;
  border-top: 0;
  border-left: 0;
  border-bottom-right-radius: 10px;
}

/* ---- ヘッダー ---- */
.deck-header {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(16px, 3vw, 28px);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 3.4vw, 1.9rem);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(79, 242, 255, 0.4);
}

.brand h1 span {
  color: var(--cyan);
}

.brand .tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
}

/* ---- 時計ウィジェット ---- */
.clock-widget {
  text-align: right;
}

.clock-time {
  font-family: var(--font-mono);
  font-size: clamp(1.7rem, 4.4vw, 2.5rem);
  line-height: 1;
  color: var(--cyan);
  letter-spacing: 0.08em;
  text-shadow:
    0 0 10px rgba(79, 242, 255, 0.75),
    0 0 34px rgba(79, 242, 255, 0.35);
  font-variant-numeric: tabular-nums;
}

.clock-time .colon {
  animation: colon-blink 1s steps(1) infinite;
}

@keyframes colon-blink {
  50% { opacity: 0.15; }
}

.clock-sub {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
}

.clock-sub .clock-zone {
  color: var(--amber);
}

/* ---- NOW PLAYING ---- */
.now-panel {
  padding: 12px clamp(14px, 3vw, 24px);
}

.now-playing {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 14px;
  align-items: center;
  font-family: var(--font-mono);
}

.signal-led {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #223047;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.7);
  transition: background 0.3s, box-shadow 0.3s;
}

.signal-led.is-live {
  background: var(--ok);
  box-shadow: 0 0 14px rgba(61, 255, 156, 0.8);
  animation: led-pulse 1.6s ease-in-out infinite;
}

.signal-led.is-error {
  background: var(--dead);
  box-shadow: 0 0 12px rgba(255, 83, 100, 0.8);
}

@keyframes led-pulse {
  50% { box-shadow: 0 0 4px rgba(61, 255, 156, 0.35); }
}

.now-ch {
  color: var(--amber);
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-shadow: 0 0 12px rgba(255, 179, 95, 0.5);
}

.now-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.now-genre {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--cyan);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
}

.now-genre:empty {
  display: none;
}

.now-status {
  min-width: 74px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-align: right;
}

.now-status.is-live {
  color: var(--ok);
}

.now-status.is-error {
  color: var(--dead);
}

/* ---- チャンネルマトリクス ---- */
.grid-panel {
  padding: clamp(14px, 3vw, 24px);
}

.grid-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin-bottom: 16px;
}

.grid-head h2 {
  margin: 0;
  flex: 1;
  font-family: var(--font-display);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--muted);
}

.health {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
}

.health b {
  font-weight: 400;
}

.health .ok { color: var(--ok); }
.health .ng { color: var(--dead); }

.channel-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 14px);
}

/* ---- スイッチ (生成SVG画像ボタン) ---- */
.channel-switch {
  position: relative;
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 6px 4px 7px;
  border: 1px solid rgba(79, 242, 255, 0.12);
  border-radius: 9px;
  background: linear-gradient(170deg, rgba(28, 40, 64, 0.55), rgba(8, 12, 22, 0.8));
  cursor: pointer;
  transition:
    transform 0.25s ease,
    border-color 0.25s ease,
    box-shadow 0.35s ease;
}

.channel-switch:hover {
  transform: translateY(-2px);
  border-color: rgba(79, 242, 255, 0.4);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45), 0 0 14px rgba(79, 242, 255, 0.12);
}

.channel-switch:active {
  transform: translateY(0) scale(0.97);
}

.channel-switch:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.channel-switch.is-active {
  border-color: rgba(79, 242, 255, 0.6);
  box-shadow:
    0 0 22px rgba(79, 242, 255, 0.25),
    0 0 44px rgba(79, 242, 255, 0.12),
    inset 0 0 14px rgba(79, 242, 255, 0.08);
}

.switch-art {
  display: block;
  width: 100%;
  height: auto;
}

.switch-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  transition: color 0.3s, text-shadow 0.3s;
}

.channel-switch.is-active .switch-label {
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(79, 242, 255, 0.7);
}

/* --- SVG内部パーツ --- */
.sw-bezel {
  fill: url(#swBezelGrad);
  stroke: rgba(133, 156, 190, 0.34);
  stroke-width: 1;
}

.sw-well {
  fill: url(#swWellGrad);
  stroke: rgba(0, 0, 0, 0.65);
  stroke-width: 1;
}

.sw-track {
  fill: rgba(2, 4, 9, 0.92);
  stroke: rgba(79, 242, 255, 0.14);
  stroke-width: 1;
  transition: stroke 0.3s;
}

.channel-switch.is-active .sw-track {
  stroke: rgba(79, 242, 255, 0.5);
}

.sw-trail {
  fill: url(#swTrailGrad);
  opacity: 0;
  transform: scaleX(0.12);
  transform-box: fill-box;
  transform-origin: left center;
  transition:
    transform 0.45s cubic-bezier(0.2, 1, 0.3, 1),
    opacity 0.3s ease;
}

.channel-switch.is-active .sw-trail {
  opacity: 1;
  transform: scaleX(1);
  animation: trail-hum 2.6s ease-in-out 0.5s infinite;
}

@keyframes trail-hum {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.62; }
}

.sw-thumb {
  transform: translateX(0);
  transition: transform 0.5s cubic-bezier(0.22, 1.5, 0.36, 1);
}

/* OFF位置 cx=30 → ON位置 cx=90 (SVGユーザー座標) */
.channel-switch.is-active .sw-thumb {
  transform: translateX(60px);
}

.sw-thumb-base {
  fill: url(#swThumbGrad);
  stroke: rgba(6, 10, 18, 0.85);
  stroke-width: 1;
}

.sw-thumb-lit {
  fill: url(#swThumbLitGrad);
  opacity: 0;
  filter: drop-shadow(0 0 5px rgba(79, 242, 255, 0.9));
}

.channel-switch.is-active .sw-thumb-lit {
  opacity: 1;
  animation:
    sw-ignite 0.6s steps(1) 1,
    core-breathe 2.8s ease-in-out 0.6s infinite;
}

/* 点火: 蛍光灯のようにフリッカーしてから安定点灯 */
@keyframes sw-ignite {
  0%   { opacity: 0; }
  10%  { opacity: 1; }
  22%  { opacity: 0.18; }
  34%  { opacity: 1; }
  46%  { opacity: 0.44; }
  60%  { opacity: 1; }
}

@keyframes core-breathe {
  50% { opacity: 0.78; }
}

/* 消灯: 一瞬明るく閃いてから残光が減衰する */
.channel-switch.is-powering-off .sw-thumb-lit {
  animation: sw-power-down 0.55s ease-out 1 forwards;
}

@keyframes sw-power-down {
  0%   { opacity: 1; }
  12%  { opacity: 0.95; }
  22%  { opacity: 0.12; }
  36%  { opacity: 0.6; }
  100% { opacity: 0; }
}

.channel-switch.is-powering-off .sw-trail {
  animation: sw-power-down 0.45s ease-out 1 forwards;
}

.sw-glyph {
  fill: none;
  stroke: rgba(125, 144, 172, 0.75);
  stroke-width: 1.7;
  stroke-linecap: round;
  transition: stroke 0.35s;
}

.channel-switch.is-active .sw-glyph {
  stroke: #062028;
}

.sw-ring {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 1.4;
  stroke-dasharray: 10 7;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 0.3s;
}

.channel-switch.is-active .sw-ring {
  opacity: 0.9;
  animation:
    sw-ignite 0.6s steps(1) 1,
    ring-spin 2.4s linear infinite;
}

.channel-switch.is-powering-off .sw-ring {
  animation: sw-power-down 0.45s ease-out 1 forwards;
}

@keyframes ring-spin {
  to { transform: rotate(360deg); }
}

/* 回線状態LED */
.sw-led {
  fill: #22314b;
  transition: fill 0.3s;
}

.channel-switch.stream-ok .sw-led {
  fill: var(--ok);
}

.channel-switch.stream-checking .sw-led {
  fill: var(--warn);
  animation: led-scan 0.9s ease-in-out infinite;
}

.channel-switch.stream-dead .sw-led {
  fill: var(--dead);
  animation: led-scan 1.6s ease-in-out infinite;
}

@keyframes led-scan {
  50% { opacity: 0.25; }
}

.channel-switch.stream-dead {
  border-color: rgba(255, 83, 100, 0.3);
}

/* ---- 下部コンソール ---- */
.console {
  position: fixed;
  right: 16px;
  bottom: 12px;
  left: 16px;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px 16px;
}

#signalCanvas {
  display: block;
  width: 100%;
  height: 74px;
  border: 1px solid rgba(79, 242, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(rgba(79, 242, 255, 0.05) 1px, transparent 1px) 0 0 / 100% 12px,
    linear-gradient(180deg, rgba(6, 10, 19, 0.95), rgba(3, 5, 10, 0.95));
}

.console-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  font-family: var(--font-mono);
}

.console-btn {
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(170deg, rgba(30, 44, 70, 0.8), rgba(10, 15, 27, 0.9));
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.15s;
}

.console-btn:hover {
  border-color: var(--line-strong);
  box-shadow: 0 0 14px rgba(79, 242, 255, 0.22);
}

.console-btn:active {
  transform: scale(0.96);
}

.console-btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

.console-btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.volume {
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
}

.volume input[type="range"] {
  width: 120px;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan) var(--vol, 80%), #1b2740 var(--vol, 80%));
  outline-offset: 4px;
  cursor: pointer;
}

.volume input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  background: #0b1322;
  box-shadow: 0 0 10px rgba(79, 242, 255, 0.6);
}

.volume input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  background: #0b1322;
  box-shadow: 0 0 10px rgba(79, 242, 255, 0.6);
}

#volumeValue {
  min-width: 3ch;
  color: var(--cyan);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#playerCors,
#playerPlain {
  display: none;
}

/* ---- モバイル ---- */
@media (max-width: 860px) {
  body {
    padding-right: 10px;
    padding-left: 10px;
    padding-bottom: 210px;
  }

  .channel-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .now-playing {
    grid-template-columns: auto auto 1fr;
  }

  .now-genre,
  .now-status {
    display: none;
  }

  .console {
    right: 10px;
    bottom: 10px;
    left: 10px;
    grid-template-columns: 1fr;
    gap: 10px;
    width: calc(100% - 20px);
  }

  .console-controls {
    justify-content: space-between;
  }
}

@media (max-width: 480px) {
  .channel-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .switch-label {
    font-size: 0.56rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
