/* ── 테마 변수 ─────────────────────────────────────── */
:root {
  --bg-from:    #1b0a3a;
  --bg-to:      #0d1b4e;
  --panel-bg:   rgba(255,255,255,0.06);
  --board-bg:   rgba(4,2,18,0.7);
  --border:     rgba(168,85,247,0.55);
  --border2:    rgba(168,85,247,0.22);
  --text:       #ede8ff;
  --muted:      #b094cc;
  --muted2:     #6a4f90;
  --accent:     #a855f7;
  --accent2:    #22d3ee;
  --accent-hv:  #9333ea;
  --grid:       rgba(168,85,247,0.08);
  --gc-bg:      rgba(12,5,32,0.96);
  --gc-btn:     rgba(168,85,247,0.18);
  --gc-btn-sh:  rgba(0,0,0,0.55);
  --glow-brd:   0 0 24px rgba(168,85,247,0.35), 0 0 6px rgba(168,85,247,0.55);
  --glow-btn:   0 0 18px rgba(168,85,247,0.55);
}

[data-theme="light"] {
  --bg-from:    #f3eaff;
  --bg-to:      #e6f0ff;
  --panel-bg:   rgba(255,255,255,0.75);
  --board-bg:   rgba(240,232,255,0.9);
  --border:     rgba(139,92,246,0.45);
  --border2:    rgba(139,92,246,0.2);
  --text:       #2a1054;
  --muted:      #7c5bb0;
  --muted2:     #b09acc;
  --accent:     #7c3aed;
  --accent2:    #0891b2;
  --accent-hv:  #6d28d9;
  --grid:       rgba(139,92,246,0.12);
  --gc-bg:      rgba(230,220,255,0.97);
  --gc-btn:     rgba(139,92,246,0.15);
  --gc-btn-sh:  rgba(100,60,180,0.2);
  --glow-brd:   0 0 18px rgba(139,92,246,0.2), 0 0 4px rgba(139,92,246,0.35);
  --glow-btn:   0 0 14px rgba(139,92,246,0.3);
}

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

body {
  background: linear-gradient(145deg, var(--bg-from) 0%, var(--bg-to) 100%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Courier New', monospace;
  color: var(--text);
  transition: background 0.4s, color 0.4s;
  overflow-x: hidden;
  user-select: none;
}

/* 배경 별빛 레이어 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.18) 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 15%, rgba(255,255,255,0.14) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 50% 65%, rgba(200,160,255,0.15) 0%, transparent 100%),
    radial-gradient(1px 1px at 10% 80%, rgba(255,255,255,0.10) 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 55%, rgba(200,220,255,0.12) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

body > * { position: relative; z-index: 1; }

/* ── 상단 버튼 ─────────────────────────────────────── */
#topbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.icon-btn {
  background: var(--panel-bg);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--text);
  font-size: 18px;
  width: 42px;
  height: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.icon-btn:hover {
  background: rgba(168,85,247,0.2);
  border-color: var(--border);
  box-shadow: var(--glow-btn);
}

/* ── 게임 영역 ─────────────────────────────────────── */
#app {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

canvas {
  border: 1.5px solid var(--border);
  background: var(--board-bg);
  display: block;
  box-shadow: var(--glow-brd);
  border-radius: 4px;
  transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}

/* ── 사이드 패널 (데스크탑) ────────────────────────── */
#panel {
  width: 140px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-stat-row,
.panel-next-row { display: contents; }

.box {
  background: var(--panel-bg);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.08);
  transition: background 0.3s, border-color 0.3s;
}
.box h3 {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.box .value {
  font-size: 22px;
  font-weight: bold;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#next-canvas {
  border: none;
  background: transparent;
  margin-top: 4px;
  box-shadow: none;
  border-radius: 0;
}

#btn {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 2px;
  box-shadow: 0 4px 16px rgba(168,85,247,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(168,85,247,0.65);
}
#btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(168,85,247,0.4);
}

#keys {
  font-size: 10px;
  color: var(--muted2);
  line-height: 2;
  letter-spacing: 0.3px;
}

/* ── 모바일 전용 재시작 버튼 (기본: 숨김) ─────────────── */
.mobile-only { display: none; }

/* ── 게임패드 (기본: 숨김) ─────────────────────────── */
#gamepad {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 18px 28px 20px;
  background: var(--gc-bg);
  border-top: 1px solid var(--border2);
  border-radius: 28px 28px 0 0;
  margin-top: 10px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* 왼쪽: ◀ ▶ */
.gc-left-group {
  display: flex;
  align-items: center;
}
.gc-lr {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

/* 오른쪽: (▼ + ↺) 위, ⚡ 아래 */
.gc-right-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.gc-mid-row {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

/* 버튼 공통 */
.gc-btn {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  border: 1px solid rgba(168,85,247,0.35);
  background: var(--gc-btn);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 0 var(--gc-btn-sh), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: transform 0.07s, box-shadow 0.07s, background 0.07s;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.gc-btn:active,
.gc-btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--gc-btn-sh), 0 0 16px rgba(168,85,247,0.6);
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border-color: transparent;
  color: #fff;
}

/* ⚡ 즉시낙하 버튼 강조 */
.gc-drop {
  background: rgba(34,211,238,0.15);
  border-color: rgba(34,211,238,0.45);
  box-shadow: 0 5px 0 rgba(0,80,100,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}
.gc-drop:active,
.gc-drop.pressed {
  background: linear-gradient(135deg, #22d3ee, #0891b2);
  box-shadow: 0 1px 0 rgba(0,80,100,0.5), 0 0 18px rgba(34,211,238,0.65);
  border-color: transparent;
}

/* ── 모바일 레이아웃 (≤640px) ──────────────────────── */
@media (max-width: 640px) {
  body {
    justify-content: flex-start;
    padding: 10px 0 0;
    gap: 0;
  }

  #topbar {
    width: 100%;
    padding: 0 12px;
    justify-content: flex-end;
    margin-bottom: 8px;
  }

  #app {
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 8px;
  }

  /* 세로형 패널: 두 행으로 구성 */
  #panel {
    width: 100%;
    flex-direction: column;
    padding: 0 12px;
    gap: 6px;
    order: -1;
  }

  /* Row 1: Score / Lines / Level */
  .panel-stat-row {
    display: flex;
    width: 100%;
    gap: 6px;
  }

  /* Row 2: Next 미리보기 + Restart 버튼 */
  .panel-next-row {
    display: flex;
    width: 100%;
    gap: 8px;
    align-items: stretch;
  }

  .box {
    flex: 1;
    padding: 8px 6px;
    text-align: center;
  }
  .box h3 { font-size: 9px; margin-bottom: 3px; }
  .box .value { font-size: 15px; }

  #next-box { flex: 1; }
  #next-canvas { margin-top: 2px; }

  /* 데스크탑 전용 요소 숨기기, 모바일 전용 요소 표시 */
  #keys  { display: none; }
  #btn   { display: none; }
  .mobile-only { display: flex; }

  /* 캔버스 중앙 정렬 */
  #board { display: block; margin: 0 auto; }

  /* 모바일 재시작 버튼 */
  #btn-mobile {
    flex: 1;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid var(--border2);
    background: var(--panel-bg);
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    align-self: stretch;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }
  #btn-mobile:active {
    background: linear-gradient(135deg, var(--accent), #6366f1);
    color: #fff;
    border-color: transparent;
  }

  /* 게임패드 표시 */
  #gamepad { display: flex; }
}

/* 아주 작은 화면 (≤360px) */
@media (max-width: 360px) {
  .gc-btn { width: 54px; height: 54px; font-size: 20px; }
}
