:root {
  --bg-black: #050505;
  --panel-dark: #121212;
  --panel-border: #262626;
  --panel-light: #e1e1e1;
  --text-main: #ffffff;
  --text-black: #000000;
  --text-muted: #888888;
  --accent-cyan: #00f0ff;
  --accent-magenta: #ff0055;
  --card-bg: #ffffff;
  --card-border: #cccccc;
}

body.light-mode {
  --bg-black: #f0f2f5;
  --panel-dark: #ffffff;
  --panel-border: #d0d0d0;
  --panel-light: #ffffff;
  --text-main: #111111;
  --text-black: #111111;
  --text-muted: #555555;
  --accent-cyan: #0088cc;
  --card-bg: #f9f9f9;
  --card-border: #bbbbbb;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
}

html,
body {
  /* 당겨서 새로고침, 끝에서 튕기는 효과 방지 */
  overscroll-behavior: none;
}

body {
  background-color: var(--bg-black);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.top-header {
  width: 100%;
  max-width: 1400px;
  display: flex;
  justify-content: flex-start;
  margin-bottom: 10px;
}

.brand-logo {
  font-size: clamp(1.6rem, 6vw, 3rem);
  font-weight: 900;
  font-family: "Arial Black", Impact, sans-serif;
  letter-spacing: -1.5px;
  color: var(--text-main);
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.4), 3px 3px 0px rgba(0,0,0,0.5);
}

.top-stats {
  display: flex;
  justify-content: center;
  gap: 50px;
  margin-bottom: 25px;
  width: 100%;
  max-width: 1400px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--text-main);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  margin-top: 4px;
  text-transform: uppercase;
}

.auth-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.form-box {
  background: var(--panel-light);
  color: var(--text-black);
  padding: 30px;
  width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

.form-box h3 {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.form-box p.subtitle {
  font-size: 0.8rem;
  font-weight: 700;
  color: #444444;
  margin-bottom: 20px;
  line-height: 1.4;
  text-transform: uppercase;
}

input {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: #181818;
  border: none;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  outline: none;
}

body.light-mode input {
  background: #e5e5e5;
  color: #000000;
}

input::placeholder {
  color: #666666;
}

.btn-tetrio {
  width: 100%;
  padding: 14px;
  background: #bebebe;
  border: none;
  color: #000000;
  font-size: 1.2rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.1s ease;
  margin-top: 8px;
}

body.light-mode .btn-tetrio {
  background: #222222;
  color: #ffffff;
}

.btn-tetrio:hover {
  background: #ffffff;
}

body.light-mode .btn-tetrio:hover {
  background: #000000;
}

.btn-tetrio.secondary {
  background: #333333;
  color: #ffffff;
}

body.light-mode .btn-tetrio.secondary {
  background: #e0e0e0;
  color: #111111;
}

.btn-tetrio.secondary:hover {
  background: #444444;
}

body.light-mode .btn-tetrio.secondary:hover {
  background: #cccccc;
}

#gameSection {
  width: 100%;
  max-width: 1400px;
}

.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-light);
  color: var(--text-black);
  padding: 15px 20px;
  margin-bottom: 20px;
  font-weight: 800;
  border: 1px solid var(--panel-border);
}

.user-info strong {
  color: var(--text-black);
  text-decoration: underline;
}

.controls-panel {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 15px;
}

.status-text {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent-cyan);
  margin-bottom: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* 레이아웃 컨테이너 통합 스타일 */
.layout-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0px;
  position: relative;
  transition: gap 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.layout-container.dual-mode {
  gap: 20px;
}

canvas#gameCanvas {
  background: #000000;
  border: 3px solid var(--panel-border);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
  width: min(800px, 78vh);
  max-width: 100%;
  height: auto;
  aspect-ratio: 1;
  display: block;
  /* 게임 중이 아닐 때는 게임판 위에서도 위아래 스크롤 가능 */
  touch-action: pan-y;
  cursor: crosshair;
  /* 길게 눌렀을 때 메뉴, 이미지 끌기, 선택 표시가 뜨지 않게 */
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#gameCanvas.playing {
  touch-action: none;
}

body.light-mode canvas#gameCanvas {
  background: #ffffff;
  border-color: #cccccc;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.08);
}

/* 상대방 캔버스 영역 */
.opponent-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 0;
  opacity: 0;
  transform: scale(0.85);
  overflow: hidden;
  transition: max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.4s ease 0.1s,
              transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.opponent-box.active {
  max-width: 420px;
  opacity: 1;
  transform: scale(1);
}

.opponent-box h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #ffaa00;
  white-space: nowrap;
}

#opponentCanvas {
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  width: 400px;
  max-width: 39vh;
}

/* 캔버스 중앙 카운트다운 오버레이 */
.canvas-wrap {
  position: relative;
}

.canvas-overlay-container {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

.countdown-overlay {
  font-size: 5rem;
  font-weight: 900;
  color: #00f0ff;
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.6);
  animation: pulseCount 1s infinite alternate;
}

@keyframes pulseCount {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.1); opacity: 1; }
}

.leaderboard-box {
  flex: 0 0 280px;
  background: var(--panel-light);
  color: var(--text-black);
  padding: 20px;
  height: 800px;
  max-height: 78vh;
  overflow-y: auto;
  border: 1px solid var(--panel-border);
}

.leaderboard-box h3 {
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--text-black);
  padding-bottom: 8px;
}

ol {
  padding-left: 20px;
}

li {
  padding: 8px 0;
  font-weight: 700;
  border-bottom: 1px solid #cccccc;
  font-size: 0.9rem;
}

.leaderboard-box .chain-title {
  margin-top: 25px;
}

#planetChain {
  display: block;
  margin: 0 auto;
}

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--panel-light);
  color: var(--text-black);
  padding: 30px;
  width: 600px;
  max-width: 90%;
  border: 1px solid var(--panel-border);
}

.modal-content h3 {
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 20px;
  text-transform: uppercase;
  border-bottom: 2px solid var(--text-black);
  padding-bottom: 10px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
}

.setting-row label {
  font-size: 1rem;
  font-weight: 900;
}

.theme-btn-group {
  display: flex;
  gap: 10px;
  width: 200px;
}

.theme-btn-group button {
  margin-top: 0;
  padding: 10px;
  font-size: 0.9rem;
}

/* 태블릿/폰: 게임판, 상대 판, 리더보드를 세로로 쌓는다 */
@media (max-width: 1100px) {
  body {
    padding: 12px;
  }

  .top-stats {
    gap: 20px;
    margin-bottom: 15px;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .stat-label {
    font-size: 0.65rem;
    letter-spacing: 1px;
  }

  .form-box {
    width: 100%;
    max-width: 420px;
    padding: 22px;
  }

  .user-bar {
    padding: 10px 12px;
    gap: 10px;
    font-size: 0.85rem;
  }

  .controls-panel {
    flex-wrap: wrap;
    gap: 8px;
  }

  .layout-container,
  .layout-container.dual-mode {
    flex-direction: column;
    align-items: center;
    gap: 15px;
  }

  canvas#gameCanvas {
    width: min(800px, 100%);
  }

  .canvas-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  /* 세로 배치에서는 max-width만으로는 높이가 남으므로 아예 숨긴다 */
  .opponent-box:not(.active) {
    display: none;
  }

  .opponent-box.active {
    max-width: 100%;
  }

  #opponentCanvas {
    width: min(260px, 60vw);
  }

  .leaderboard-box {
    flex: none;
    width: 100%;
    max-width: 800px;
    height: auto;
    max-height: none;
  }

  .countdown-overlay {
    font-size: 3.5rem;
  }
}