:root {
  --bg: #faf8ef;
  --fg: #776e65;
  --card: #ffffff;
  --box: #bbada0;
  --maze: #1e3a8a;
  --accent: #ffcc00;
}
[data-theme='dark'] {
  --bg: #14171f;
  --fg: #e6e6e6;
  --card: #1f2430;
  --box: #2a3040;
  --maze: #3b82f6;
  --accent: #ffcc00;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 440px;
  margin: 0 auto;
  padding: 14px 16px 4px;
}
.title { font-size: 28px; font-weight: 700; margin: 0; }
.header-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: none;
  background: var(--card);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
}
.theme-toggle .icon-moon { display: none; }
[data-theme='dark'] .theme-toggle .icon-sun { display: none; }
[data-theme='dark'] .theme-toggle .icon-moon { display: inline; }

.game { max-width: 440px; margin: 0 auto; padding: 8px 16px 40px; }

.scores {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}
.score-box {
  background: var(--box);
  color: #fff;
  border-radius: 10px;
  padding: 6px 16px;
  text-align: center;
  min-width: 84px;
}
.score-label { font-size: 11px; opacity: 0.85; }
.score-val { font-size: 20px; font-weight: 700; }

.board-wrap { position: relative; width: 100%; }
#board {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
  border-radius: 12px;
  image-rendering: pixelated;
}

.new-btn {
  display: block;
  width: 100%;
  margin: 14px auto 0;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.hint { font-size: 12px; opacity: 0.7; text-align: center; margin-top: 12px; line-height: 1.5; }

/* 모바일 방향 버튼 (스와이프 어려운 사람용) */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(2, 60px);
  gap: 8px;
  justify-content: center;
  margin: 18px auto 0;
}
.dbtn {
  border: none;
  border-radius: 14px;
  background: var(--card);
  color: var(--fg);
  font-size: 22px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dbtn:active { background: var(--accent); color: #1a1a1a; }
.dbtn.up { grid-area: 1 / 2; }
.dbtn.left { grid-area: 2 / 1; }
.dbtn.down { grid-area: 2 / 2; }
.dbtn.right { grid-area: 2 / 3; }

.overlay-msg {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 12px;
}
.overlay-msg.show { display: flex; }
.overlay-inner { text-align: center; padding: 20px; }
.overlay-inner p { color: #fff; font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.rank-line { font-size: 14px !important; font-weight: 500 !important; opacity: 0.9; min-height: 18px; }
.overlay-inner .new-btn { width: auto; padding: 10px 28px; margin-top: 14px; }
