/* ============================================================
   TETRIS // 赛博方块终端 - 全局视觉系统
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@100;300;400;700&display=swap');

:root {
  --bg: #0d1117;
  --ink: #e2e8f0;
  --ink-dim: #6b7280;
  --ink-faint: #374151;
  --accent-green: #34d399;
  --accent-cyan: #22d3ee;
  --accent-red: #ef4444;
  --accent-yellow: #facc15;
  --border: rgba(255,255,255,0.10);
  --border-dim: rgba(255,255,255,0.05);
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10px;
  letter-spacing: 0.05em;
}

/* ── CRT 扫描线 + RGB 色散 ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    linear-gradient(rgba(18,16,16,0) 50%, rgba(0,0,0,0.10) 50%),
    linear-gradient(90deg, rgba(255,0,0,0.04), rgba(0,255,0,0.015), rgba(0,0,255,0.04));
  background-size: 100% 2px, 3px 100%;
  pointer-events: none;
  z-index: 9999;
}

/* ── 噪点纹理 ── */
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' 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");
  opacity: 0.45;
  pointer-events: none;
  z-index: 9998;
}

/* ── 屏幕角标 ── */
.corner-mark {
  position: fixed;
  width: 14px; height: 14px;
  pointer-events: none;
  z-index: 100;
}
.corner-mark::before, .corner-mark::after {
  content: '';
  position: absolute;
  border-color: rgba(52,211,153,0.5);
  border-style: solid;
}
.corner-mark.tl { top: 6px; left: 6px; }
.corner-mark.tl::before { top: 0; left: 0; width: 100%; height: 1px; border-width: 1px 0 0 0; }
.corner-mark.tl::after { top: 0; left: 0; width: 1px; height: 100%; border-width: 0 0 0 1px; }
.corner-mark.tr { top: 6px; right: 6px; transform: scaleX(-1); }
.corner-mark.tr::before { top: 0; left: 0; width: 100%; height: 1px; border-width: 1px 0 0 0; }
.corner-mark.tr::after { top: 0; left: 0; width: 1px; height: 100%; border-width: 0 0 0 1px; }
.corner-mark.bl { bottom: 6px; left: 6px; transform: scaleY(-1); }
.corner-mark.bl::before { top: 0; left: 0; width: 100%; height: 1px; border-width: 1px 0 0 0; }
.corner-mark.bl::after { top: 0; left: 0; width: 1px; height: 100%; border-width: 0 0 0 1px; }
.corner-mark.br { bottom: 6px; right: 6px; transform: scale(-1); }
.corner-mark.br::before { top: 0; left: 0; width: 100%; height: 1px; border-width: 1px 0 0 0; }
.corner-mark.br::after { top: 0; left: 0; width: 1px; height: 100%; border-width: 0 0 0 1px; }

/* ── 主容器 ── */
.game-wrapper {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  position: relative;
  z-index: 10;
  transform-origin: center top;
  transition: transform 0.15s ease-out;
}

/* ── HUD 面板 ── */
.hud-panel {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  padding: 16px;
  position: relative;
}
.hud-panel::before, .hud-panel::after {
  content: '';
  position: absolute;
  width: 10px; height: 10px;
  pointer-events: none;
}
.hud-panel::before {
  top: -1px; left: -1px;
  border-top: 1.5px solid rgba(52,211,153,0.6);
  border-left: 1.5px solid rgba(52,211,153,0.6);
}
.hud-panel::after {
  bottom: -1px; right: -1px;
  border-bottom: 1.5px solid rgba(52,211,153,0.6);
  border-right: 1.5px solid rgba(52,211,153,0.6);
}

.panel-title {
  font-size: 11px;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(52,211,153,0.12);
  text-shadow: 0 0 8px rgba(52,211,153,0.35);
}

/* ── 最左侧列 ── */
.far-left-col {
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── 日志面板 ── */
.log-panel {
  height: 180px;
  display: flex;
  flex-direction: column;
  padding-bottom: 8px;
}
.log-export {
  font-size: 8px;
  color: var(--accent-cyan);
  cursor: pointer;
  letter-spacing: 0.1em;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.log-export:hover { opacity: 1; }
.log-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 9px;
  line-height: 1.7;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
  scrollbar-width: thin;
  scrollbar-color: rgba(52,211,153,0.2) transparent;
}
.log-content::-webkit-scrollbar { width: 3px; }
.log-content::-webkit-scrollbar-thumb { background: rgba(52,211,153,0.2); }
.log-content .log-line { white-space: pre-wrap; word-break: break-all; }
.log-content .log-line.log-warn { color: #facc15; }
.log-content .log-line.log-err { color: #ef4444; }
.log-content .log-line.log-ok { color: #34d399; }
.log-content .log-line.log-boss { color: #f97316; }

/* ── 左侧列 ── */
.left-col {
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.physics-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ── 游戏主区域 ── */
.game-board-container { position: relative; }

#game-canvas {
  display: block;
  border: 1px solid var(--border);
  border-radius: 2px;
}

#next-canvas, #hold-canvas {
  display: block;
  margin: 0 auto;
}

/* ── 数据显示 ── */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}
.stat-label {
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 11px;
}
.stat-value {
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 20px;
  text-shadow: 0 0 6px rgba(34,211,238,0.35);
}

/* ── 分数大字 ── */
.score-block {
  text-align: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-dim);
}
.score-block .stat-label {
  font-size: 9px;
  margin-bottom: 6px;
}
.score-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-yellow);
  text-shadow:
    0 0 8px rgba(250,204,21,0.5),
    0 0 20px rgba(250,204,21,0.2);
  letter-spacing: 0.05em;
  transition: transform 0.12s ease-out, text-shadow 0.12s ease-out;
  transform-origin: center center;
}
.score-value.pop {
  transform: scale(var(--pop-scale, 1.2));
  text-shadow:
    0 0 12px rgba(250,204,21,0.8),
    0 0 30px rgba(250,204,21,0.4),
    0 0 50px rgba(250,204,21,0.15);
}
.score-value.rainbow {
  animation: rainbowPulse 0.6s ease-out;
  transform: scale(1.6);
}
@keyframes rainbowPulse {
  0% {
    color: #facc15;
    text-shadow: 0 0 10px rgba(250,204,21,0.9), 0 0 30px rgba(250,204,21,0.5);
    transform: scale(0.8);
  }
  20% {
    color: #ef4444;
    text-shadow: 0 0 15px rgba(239,68,68,0.9), 0 0 40px rgba(239,68,68,0.4);
    transform: scale(1.6);
  }
  40% {
    color: #a855f7;
    text-shadow: 0 0 15px rgba(168,85,247,0.9), 0 0 40px rgba(168,85,247,0.4);
    transform: scale(1.5);
  }
  60% {
    color: #22d3ee;
    text-shadow: 0 0 15px rgba(34,211,238,0.9), 0 0 40px rgba(34,211,238,0.4);
    transform: scale(1.4);
  }
  80% {
    color: #34d399;
    text-shadow: 0 0 15px rgba(52,211,153,0.9), 0 0 40px rgba(52,211,153,0.4);
    transform: scale(1.3);
  }
  100% {
    color: var(--accent-yellow);
    text-shadow: 0 0 8px rgba(250,204,21,0.5), 0 0 20px rgba(250,204,21,0.2);
    transform: scale(1);
  }
}

/* ── 颜色积分 ── */
.color-scores {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}
.color-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.color-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.color-dot {
  width: 6px;
  height: 6px;
  border-radius: 1px;
  flex-shrink: 0;
}
.color-label {
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.color-pts {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.color-bar-wrap {
  height: 4px;
  background: var(--border-dim);
  border-radius: 1px;
  overflow: hidden;
}
.color-bar {
  height: 100%;
  border-radius: 1px;
  transition: width 0.3s ease-out;
  min-width: 0;
}

/* ── Boss 区域 ── */
.boss-area {
  position: relative;
  flex-shrink: 0;
}
#boss-canvas {
  display: block;
  border: 1px solid var(--border);
  border-radius: 2px;
}

/* ── 控制提示 ── */
.controls-hint {
  font-size: 10px;
  color: var(--ink-faint);
  line-height: 2.1;
  letter-spacing: 0.12em;
}
.controls-hint .key {
  color: var(--accent-green);
  font-weight: 700;
}

/* ── Overlay 覆盖层 ── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6,10,16,0.88);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
  border: 1px solid var(--border);
}
.overlay.hidden { display: none; }

.overlay-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-shadow: 0 0 20px rgba(52,211,153,0.5);
  margin-bottom: 6px;
}
.overlay-sub {
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  animation: blinkText 1.2s ease-in-out infinite;
}
.overlay-version {
  font-size: 9px;
  color: var(--accent-cyan);
  letter-spacing: 0.2em;
  margin-bottom: 20px;
  text-shadow: 0 0 6px rgba(34,211,238,0.3);
}
.overlay-score {
  font-size: 14px;
  color: var(--accent-cyan);
  margin: 8px 0;
  letter-spacing: 0.12em;
  text-shadow: 0 0 8px rgba(34,211,238,0.4);
}

/* ── 遥测日志 ── */
.telemetry {
  position: fixed;
  bottom: 10px; left: 10px;
  font-size: 8px;
  color: rgba(52,211,153,0.35);
  letter-spacing: 0.12em;
  pointer-events: none;
  z-index: 10;
}

/* ── 升级选择面板 ── */
.upgrade-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,10,16,0.92);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}
.upgrade-overlay.hidden { display: none; }
.upgrade-panel {
  border: 1px solid rgba(52,211,153,0.3);
  background: rgba(0,0,0,0.6);
  padding: 30px 36px;
  min-width: 360px;
  text-align: center;
}
.upgrade-header {
  font-size: 13px;
  color: var(--accent-green);
  letter-spacing: 0.3em;
  text-shadow: 0 0 10px rgba(52,211,153,0.4);
  margin-bottom: 6px;
}
.upgrade-subtitle {
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 0.15em;
  margin-bottom: 24px;
}
.upgrade-options {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 20px;
}
.upgrade-card {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.4);
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  min-width: 140px;
  text-align: center;
}
.upgrade-card:hover,
.upgrade-card.kb-focus {
  border-color: rgba(52,211,153,0.5);
  background: rgba(52,211,153,0.05);
  box-shadow: 0 0 15px rgba(52,211,153,0.1);
}
.upgrade-card .uc-icon {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.upgrade-card .uc-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 6px;
}
.upgrade-card .uc-desc {
  font-size: 9px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
  line-height: 1.6;
}
.upgrade-card .uc-cost {
  font-size: 9px;
  color: var(--accent-yellow);
  margin-top: 8px;
  letter-spacing: 0.1em;
}
.upgrade-skip {
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.15em;
  animation: blinkText 1.2s ease-in-out infinite;
}

/* ── 答题面板 ── */
.quiz-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,10,16,0.94);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 300;
}
.quiz-overlay.hidden { display: none; }
.quiz-panel {
  border: 1px solid rgba(250,204,21,0.3);
  background: rgba(0,0,0,0.7);
  padding: 30px 40px;
  max-width: 580px;
  width: 90vw;
}
.quiz-header {
  font-size: 13px;
  color: var(--accent-yellow);
  letter-spacing: 0.3em;
  text-shadow: 0 0 10px rgba(250,204,21,0.4);
  margin-bottom: 6px;
}
.quiz-reward {
  font-size: 10px;
  color: var(--accent-cyan);
  letter-spacing: 0.15em;
  margin-bottom: 20px;
  text-shadow: 0 0 6px rgba(34,211,238,0.3);
}
.quiz-question {
  font-size: 14px;
  color: var(--ink);
  line-height: 1.8;
  margin-bottom: 20px;
  letter-spacing: 0.03em;
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-opt {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.6;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: border-color 0.2s, background 0.2s;
}
.quiz-opt:hover,
.quiz-opt.kb-focus {
  border-color: rgba(52,211,153,0.5);
  background: rgba(52,211,153,0.05);
}
.quiz-opt.correct {
  border-color: #34d399;
  background: rgba(52,211,153,0.15);
  color: #34d399;
}
.quiz-opt.wrong {
  border-color: #ef4444;
  background: rgba(239,68,68,0.15);
  color: #ef4444;
}
.quiz-opt.disabled {
  pointer-events: none;
  opacity: 0.5;
}
.quiz-analysis {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--border-dim);
  background: rgba(0,0,0,0.2);
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.7;
  letter-spacing: 0.02em;
}
.quiz-analysis.hidden { display: none; }
.quiz-result {
  margin-top: 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-align: center;
}
.quiz-result.win { color: #34d399; text-shadow: 0 0 8px rgba(52,211,153,0.5); }
.quiz-result.lose { color: #ef4444; }
.quiz-close-btn {
  margin-top: 18px;
  text-align: center;
  font-size: 11px;
  color: var(--accent-cyan);
  letter-spacing: 0.2em;
  cursor: pointer;
  padding: 10px;
  border: 1px solid rgba(34,211,238,0.3);
  background: rgba(34,211,238,0.05);
  transition: background 0.2s, border-color 0.2s;
}
.quiz-close-btn:hover {
  background: rgba(34,211,238,0.12);
  border-color: rgba(34,211,238,0.6);
}

/* ── 动画 ── */
@keyframes blinkText {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Audio Floating (right-top) ── */
.audio-floating {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.audio-toggle-btn {
  font-family: var(--font-mono);
  font-size: 16px;
  width: 32px;
  height: 32px;
  background: rgba(13, 17, 23, 0.85);
  color: var(--accent-cyan);
  border: 1px solid rgba(34, 211, 238, 0.3);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  backdrop-filter: blur(6px);
}
.audio-toggle-btn:hover {
  background: rgba(34, 211, 238, 0.1);
  border-color: rgba(34, 211, 238, 0.6);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.3);
}
.audio-dropdown {
  margin-top: 6px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: 4px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
  min-width: 200px;
}
.audio-dropdown.hidden {
  display: none;
}
.audio-panel {
  padding: 10px 14px;
}
.audio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.audio-row:last-child { margin-bottom: 0; }
.audio-label {
  font-size: 10px;
  color: var(--ink-dim);
  width: 30px;
  flex-shrink: 0;
  letter-spacing: 0.1em;
}
.audio-val {
  font-size: 10px;
  color: var(--accent-cyan);
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}
.audio-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--ink-faint);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.audio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: 2px solid var(--bg);
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.5);
  cursor: pointer;
}
.audio-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: 2px solid var(--bg);
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.5);
  cursor: pointer;
}
.mute-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  background: transparent;
  color: var(--accent-green);
  border: 1px solid var(--accent-green);
  padding: 3px 12px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s;
  width: 100%;
}
.mute-btn:hover {
  background: rgba(52, 211, 153, 0.1);
}
.mute-btn.active {
  color: var(--accent-red);
  border-color: var(--accent-red);
}
.mute-btn.active:hover {
  background: rgba(239, 68, 68, 0.1);
}
