/* ===========================================================================
 * 第五頻道 CHANNEL 5 — 樣式 style.css
 * 賽博霓虹 × 復古映像管（CRT）電視主題
 * ======================================================================== */

:root {
  --bg: #06070f;
  --panel: rgba(12, 15, 30, 0.9);
  --cyan: #33e1ff;
  --magenta: #ff3df0;
  --ink: #eef3ff;
  --dim: #8ea0c8;
  --line: rgba(120, 140, 200, 0.18);
}

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

html, body {
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

/* 映像管外殼 */
#tv {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #11152b 0%, var(--bg) 55%, #03040a 100%);
  overflow: hidden;
}
#tv::after {
  /* 螢幕邊緣弧度暗角，模擬玻璃 */
  content: "";
  position: absolute; inset: 0;
  box-shadow: inset 0 0 140px 30px rgba(0, 0, 0, 0.85);
  border-radius: 22px;
  pointer-events: none;
  z-index: 60;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- CRT 疊層 ---- */
.crt { position: absolute; inset: 0; z-index: 55; pointer-events: none; mix-blend-mode: screen; }
.crt-scan {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 2px,
    transparent 3px);
  animation: scanroll 8s linear infinite;
}
.crt-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(120% 100% at 50% 50%, transparent 60%, rgba(0,0,0,0.5) 100%);
  mix-blend-mode: multiply;
}
.crt-flicker { position: absolute; inset: 0; background: rgba(120,180,255,0.02); animation: flicker 0.13s steps(2) infinite; }
@keyframes scanroll { from { background-position-y: 0; } to { background-position-y: 100px; } }
@keyframes flicker { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.7; } }

/* ---- 畫面通用 ---- */
.screen {
  position: absolute; inset: 0;
  z-index: 20;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 28px;
  text-align: center;
}
.screen.hidden { display: none; }
.screen.overlay { background: rgba(3, 4, 12, 0.72); backdrop-filter: blur(4px); z-index: 40; }

/* ---- 標題 ---- */
.signal-badge {
  color: var(--magenta);
  font: 700 13px/1 ui-monospace, monospace;
  letter-spacing: 3px;
  margin-bottom: 18px;
  animation: blink 1.6s steps(2) infinite;
}
@keyframes blink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: 0.25; } }

.logo {
  font-size: clamp(48px, 13vw, 96px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 0.95;
  text-shadow: 0 0 24px rgba(51, 225, 255, 0.5), 3px 0 var(--magenta), -3px 0 var(--cyan);
}
.logo span { color: var(--magenta); text-shadow: 0 0 24px rgba(255, 61, 240, 0.6); }
.logo-en {
  margin-top: 8px;
  font: 700 clamp(13px, 3vw, 18px)/1 ui-monospace, monospace;
  letter-spacing: 8px;
  color: var(--cyan);
  opacity: 0.85;
}
.tagline { margin: 22px 0 26px; color: var(--dim); font-size: 15px; }

.hint {
  list-style: none;
  margin-top: 30px;
  color: var(--dim);
  font-size: 13px;
  line-height: 2.1;
}
.hint b {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  margin: 0 2px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  font-family: ui-monospace, monospace;
}
.version {
  position: absolute; bottom: 16px; right: 18px;
  font: 600 11px ui-monospace, monospace;
  color: var(--dim); opacity: 0.6;
}
.more-games {
  display: inline-block;
  margin-top: 26px;
  padding: 9px 20px;
  border: 1px solid var(--magenta);
  border-radius: 999px;
  color: var(--magenta);
  font-size: 13px; font-weight: 700;
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s, transform 0.08s;
}
.more-games:hover { background: rgba(255, 61, 240, 0.12); box-shadow: 0 0 20px rgba(255, 61, 240, 0.35); }
.more-games:active { transform: scale(0.96); }

/* 語言切換鈕（固定右上，遊玩／暫停時隱藏避免擋畫面） */
#btn-lang {
  position: absolute; top: 14px; right: 16px; z-index: 50;
  appearance: none; cursor: pointer;
  min-width: 40px; height: 32px; padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(8, 10, 22, 0.6);
  color: var(--cyan);
  font: 800 13px ui-monospace, monospace;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
#btn-lang:hover { background: rgba(51, 225, 255, 0.12); border-color: var(--cyan); }
#btn-lang:active { transform: scale(0.94); }
body[data-state="play"] #btn-lang, body[data-state="pause"] #btn-lang { display: none; }

/* ---- 按鈕 ---- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: 700 15px/1 inherit;
  padding: 13px 26px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--cyan); }
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), #2aa8ff);
  color: #04121a; border: none;
  box-shadow: 0 0 24px rgba(51, 225, 255, 0.35);
}
.btn-primary:hover { box-shadow: 0 0 34px rgba(51, 225, 255, 0.55); background: linear-gradient(135deg, #5ceaff, #38b6ff); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-mini { padding: 4px 12px; font-size: 16px; border-radius: 8px; }
#btn-start { margin-top: 6px; font-size: 18px; padding: 15px 40px; }

/* ---- 選單 ---- */
.menu-head {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 18px 22px;
  flex-wrap: wrap;
}
.menu-head h2 { font-size: 20px; letter-spacing: 4px; }
.menu-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.speed-ctl { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); }
.speed-ctl b { color: var(--cyan); font-family: ui-monospace, monospace; min-width: 42px; }

.song-list {
  margin-top: 96px;
  width: min(680px, 100%);
  max-height: calc(100% - 120px);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 4px 6px 30px;
}
.song-card {
  --col: var(--cyan);
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--col);
  border-radius: 14px;
  background: linear-gradient(100deg, rgba(255,255,255,0.05), rgba(255,255,255,0.01));
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
}
.song-card:hover {
  transform: translateX(4px);
  box-shadow: -6px 0 24px -8px var(--col);
  border-color: var(--col);
}
.song-card.locked { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.7); }
.sc-ch { font: 900 16px ui-monospace, monospace; color: var(--col); text-align: center; line-height: 1; }
.sc-ch span { display: block; font-size: 30px; }
.sc-name { font-size: 18px; font-weight: 800; }
.sc-en { font: 600 11px ui-monospace, monospace; color: var(--dim); letter-spacing: 2px; margin: 2px 0 6px; }
.sc-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--dim); }
.sc-diff { color: var(--col); }
.sc-best { text-align: right; font: 800 22px ui-monospace, monospace; color: var(--ink); }
.sc-best i { font: 600 12px ui-monospace, monospace; color: var(--dim); font-style: normal; }

/* ---- 暫停 / 結算面板 ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 34px;
  width: min(440px, 100%);
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.panel h2 { letter-spacing: 6px; margin-bottom: 8px; }
.khint { color: var(--dim); font-size: 12px; margin-top: 6px; }
.khint b { font-family: ui-monospace, monospace; color: var(--ink); }

.result .result-ch { font: 700 13px ui-monospace, monospace; color: var(--cyan); letter-spacing: 2px; }
.result-bigtitle { font-size: 26px; font-weight: 900; letter-spacing: 2px; margin: 2px 0 10px; }
.result-row { display: flex; align-items: center; gap: 20px; }
.grade {
  font: 900 76px ui-monospace, monospace;
  width: 110px; text-align: center;
  line-height: 1;
  text-shadow: 0 0 30px currentColor;
}
.grade[data-grade="SS"], .grade[data-grade="S"] { color: #ffe14d; }
.grade[data-grade="A"] { color: #4dff9e; }
.grade[data-grade="B"] { color: var(--cyan); }
.grade[data-grade="C"] { color: #9b7bff; }
.grade[data-grade="D"] { color: #ff9f43; }
.grade[data-grade="F"] { color: #ff5470; }
.result-stats { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.stat-line { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.stat-line span { color: var(--dim); font-size: 13px; }
.stat-line b { font: 800 20px ui-monospace, monospace; }

.judge-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.jg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; text-align: center; }
.jg span { display: block; font: 700 10px ui-monospace, monospace; letter-spacing: 1px; color: var(--dim); }
.jg b { font: 800 20px ui-monospace, monospace; }
.jg.perfect b { color: #ffe14d; }
.jg.good b { color: #4dff9e; }
.jg.wrong b { color: #ff8a3d; }
.jg.miss b { color: #ff5470; }

.result-tags { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 4px; }
.tag { font: 700 12px ui-monospace, monospace; padding: 5px 12px; border-radius: 999px; }
.tag.new { background: rgba(255, 225, 77, 0.15); color: #ffe14d; border: 1px solid #ffe14d66; }
.tag.fc { background: rgba(77, 255, 158, 0.15); color: #4dff9e; border: 1px solid #4dff9e66; }
.tag.unlock { background: rgba(255, 61, 240, 0.15); color: var(--magenta); border: 1px solid #ff3df066; }
.tag.ach { background: rgba(255, 209, 61, 0.15); color: #ffd23d; border: 1px solid #ffd23d66; }

/* 成就牆 */
.ach-panel { width: min(560px, 100%); }
.ach-progress { color: var(--cyan); font: 700 13px ui-monospace, monospace; margin-bottom: 6px; }
.ach-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  max-height: 56vh; overflow-y: auto; padding: 4px 2px 6px;
}
.ach-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  opacity: 0.5; filter: grayscale(0.6);
}
.ach-item.got { opacity: 1; filter: none; border-color: rgba(255, 209, 61, 0.4); background: rgba(255, 209, 61, 0.06); }
.ach-emoji { font-size: 28px; flex-shrink: 0; width: 34px; text-align: center; }
.ach-info { text-align: left; min-width: 0; }
.ach-name { font-size: 14px; font-weight: 800; }
.ach-desc { font-size: 11px; color: var(--dim); margin-top: 2px; }
@media (max-width: 520px) { .ach-grid { grid-template-columns: 1fr; } }
.result-btns { display: flex; gap: 10px; margin-top: 8px; }
.result-btns .btn { flex: 1; }

/* ---- Toast ---- */
.toast {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: rgba(8, 10, 22, 0.95);
  border: 1px solid var(--magenta);
  color: var(--ink);
  padding: 12px 20px; border-radius: 12px;
  font-size: 13px; z-index: 70;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 0 24px rgba(255, 61, 240, 0.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- 手機觸控控制（只在遊玩時顯示） ---- */
#touch-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: none;
  justify-content: space-between; align-items: flex-end;
  padding: 14px 18px max(18px, env(safe-area-inset-bottom));
  pointer-events: none;
}
body[data-state="play"] #touch-controls { display: flex; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
}
.action { display: flex; gap: 12px; align-items: flex-end; }
.tc {
  pointer-events: auto;
  border: 2px solid currentColor;
  border-radius: 14px;
  background: rgba(8, 10, 22, 0.62);
  font: 900 22px ui-monospace, monospace;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  transition: transform 0.06s, box-shadow 0.1s, background 0.1s;
}
.tc.up { grid-column: 2; grid-row: 1; color: #ff8a3d; }
.tc.left { grid-column: 1; grid-row: 2; color: #3df0ff; }
.tc.right { grid-column: 3; grid-row: 2; color: #4dff9e; }
.tc.down { grid-column: 2; grid-row: 3; color: #ffd23d; }
.tc.clap { width: 72px; height: 72px; color: #ff4f9b; font-size: 15px; }
.tc.spin { width: 72px; height: 72px; color: #b06bff; font-size: 15px; }
.tc.on, .tc:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 22px currentColor, inset 0 0 18px -4px currentColor;
}
/* 桌機用鍵盤即可，隱藏虛擬按鈕 */
@media (hover: hover) and (pointer: fine) {
  #touch-controls { display: none !important; }
}

@media (max-width: 520px) {
  .song-list { margin-top: 110px; }
  .result-row { flex-direction: column; gap: 10px; }
  .grade { width: auto; }
  .dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
  .tc.clap, .tc.spin { width: 64px; height: 64px; }
}
