/* ============================================================
   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);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 20px;
  padding-bottom: 40px;
  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: 20px;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  z-index: 10;
}

/* ── HUD 面板 ── */
.hud-panel {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
  padding: 14px;
  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: 10px;
  text-shadow: 0 0 8px rgba(52,211,153,0.35);
}

/* ── 右侧组合面板 ── */
.right-group {
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── 左侧列 ── */
.left-col {
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.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: 10px;
}
.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: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.color-pts {
  font-size: 11px;
  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;
}

/* ── 控制提示 ── */
.controls-hint {
  font-size: 9px;
  color: var(--ink-faint);
  line-height: 2;
  letter-spacing: 0.1em;
}
.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;
}

/* ── 动画 ── */
@keyframes blinkText {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   移动端专属样式
   ============================================================ */

/* 移动端元素默认隐藏 */
.mobile-top-bar,
.mobile-controls {
  display: none;
}

/* ── 竖屏移动端适配 ── */
@media (orientation: portrait) and (max-width: 768px) {
  body {
    padding: 0;
    align-items: stretch;
    flex-direction: column;
    justify-content: flex-start;
  }

  .corner-mark { display: none; }
  .telemetry { display: none; }

  .desktop-only {
    display: none !important;
  }

  .mobile-top-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.45);
    z-index: 20;
  }

  .m-stat {
    text-align: center;
  }
  .m-stat-label {
    font-size: 8px;
    color: var(--ink-dim);
    letter-spacing: 0.15em;
    margin-bottom: 2px;
  }
  .m-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-cyan);
    text-shadow: 0 0 6px rgba(34,211,238,0.35);
  }
  .m-stat:first-child .m-stat-value {
    color: var(--accent-yellow);
    text-shadow: 0 0 8px rgba(250,204,21,0.5);
  }

  .game-wrapper {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    padding: 8px;
  }

  .game-board-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  #game-canvas {
    max-width: 100%;
    height: auto;
  }

  /* 虚拟按键 */
  .mobile-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    padding: 8px 12px 16px;
    gap: 12px;
    z-index: 20;
  }

  .mobile-dir-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 45%;
    max-width: 180px;
  }

  .mobile-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    width: 45%;
    max-width: 180px;
  }

  .m-btn {
    appearance: none;
    border: 1px solid var(--border);
    background: rgba(0,0,0,0.5);
    color: var(--accent-green);
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    border-radius: 8px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.05s, background 0.05s, box-shadow 0.05s;
    touch-action: manipulation;
    padding: 0;
    line-height: 1;
  }
  .m-btn:active, .m-btn.active {
    transform: scale(0.92);
    background: rgba(52,211,153,0.15);
    box-shadow: 0 0 12px rgba(52,211,153,0.35);
    border-color: rgba(52,211,153,0.5);
  }
  .m-btn-dir {
    font-size: 22px;
  }
  .m-btn-drop {
    color: var(--accent-yellow);
  }
  .m-btn-drop:active, .m-btn-drop.active {
    background: rgba(250,204,21,0.15);
    box-shadow: 0 0 12px rgba(250,204,21,0.35);
    border-color: rgba(250,204,21,0.5);
  }
  .m-btn-pause {
    color: var(--accent-red);
    font-size: 14px;
  }
  .m-btn-pause:active, .m-btn-pause.active {
    background: rgba(239,68,68,0.15);
    box-shadow: 0 0 12px rgba(239,68,68,0.35);
    border-color: rgba(239,68,68,0.5);
  }
}

/* ── 横屏小屏幕（手机横屏）── */
@media (orientation: landscape) and (max-height: 500px) {
  body {
    padding: 4px;
    align-items: center;
  }

  .game-wrapper {
    gap: 10px;
    align-items: center;
  }

  .left-col, .right-group {
    width: 110px;
    gap: 8px;
  }

  .hud-panel {
    padding: 8px;
  }

  .panel-title {
    font-size: 9px;
    margin-bottom: 6px;
  }

  .mobile-top-bar,
  .mobile-controls {
    display: none;
  }

  .controls-hint {
    font-size: 7px;
    line-height: 1.8;
  }
}

/* ── 超小屏横屏（显示虚拟按键替代桌面面板）── */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 800px) {
  .desktop-only {
    display: none !important;
  }

  .game-wrapper {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 12px;
  }

  .mobile-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    width: auto;
    padding: 0;
  }

  .mobile-dir-pad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: 44px;
    gap: 4px;
  }

  .mobile-actions {
    display: grid;
    grid-template-columns: repeat(2, 44px);
    grid-template-rows: 44px;
    gap: 4px;
  }

  .m-btn {
    height: 44px;
    font-size: 14px;
    border-radius: 6px;
  }
  .m-btn-dir {
    font-size: 18px;
  }
  .m-btn-pause {
    font-size: 12px;
  }
}
