/* 차곡(CHAGOK) — "한밤의 작업실" 다크 테마 */
:root {
  --bg: #16182B;
  --board-bg: #1E2038;
  --grid: #2A2D47;
  --border: #4A4E78;
  --panel: #23264A;
  --text: #F2F0FA;
  --text-sub: #A9A8C4;
  --accent: #FFC247;
  --disabled: #6B6E8F;
  --danger: #FF6B5E;
  --cell: 24px;          /* game.js가 화면 크기에 맞춰 덮어쓴다 */
  --side: 200px;
  --gap: 32px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.safe-probe {
  position: fixed; left: 0; bottom: 0; width: 0; height: 0; visibility: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 전체 틀 ── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.wordmark { margin: 0; display: flex; align-items: baseline; gap: 10px; font-weight: 700; }
.wm-ko { font-size: 28px; color: var(--text); letter-spacing: 0.04em; }
.wm-mark { border-bottom: 3px solid var(--accent); padding-bottom: 1px; }
.wm-en { font-size: 12px; color: var(--text-sub); letter-spacing: 0.3em; font-weight: 600; }

.icon-btn {
  display: none;
  width: 44px; height: 44px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active:not(:disabled) { background: var(--grid); }
.icon-btn:disabled { color: var(--disabled); cursor: default; }

/* ── 3단 배치(768px 이상) ── */
.layout {
  display: grid;
  grid-template-columns: var(--side) auto var(--side);
  grid-template-rows: auto auto 1fr;
  grid-template-areas:
    "stats board next"
    "stats board actions"
    "stats board help";
  column-gap: var(--gap);
  row-gap: 16px;
  justify-content: center;
  align-items: start;
  padding: 0 16px 16px;
}

.panel { background: var(--panel); border-radius: 12px; padding: 16px; }
.panel-title { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--text-sub); }

.stats { grid-area: stats; display: flex; flex-direction: column; gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-sub); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }

.board-wrap {
  grid-area: board;
  position: relative;
  box-sizing: content-box;
  width: calc(var(--cell) * 10);
  height: calc(var(--cell) * 20);
  border: 2px solid var(--border);
  background: var(--board-bg);
}
#board { display: block; width: 100%; height: 100%; }

.next-panel { grid-area: next; }
#next { display: block; margin: 0 auto; background: var(--board-bg); border-radius: 8px; }

.actions { grid-area: actions; display: flex; flex-direction: column; gap: 8px; }

.help { grid-area: help; font-size: 14px; color: var(--text-sub); }
.help dl { margin: 0; display: grid; gap: 6px; }
.help dl > div { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.help dt { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.help dd { margin: 0; }

/* ── 버튼 ── */
.btn {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:active { filter: brightness(0.92); }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-secondary:active:not(:disabled) { background: var(--grid); }
.btn-danger { background: var(--danger); color: var(--bg); }
.btn:disabled { color: var(--disabled); cursor: default; }

/* ── 오버레이 ── */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  padding: 12px;
  text-align: center;
  background: rgba(22, 24, 43, 0.88);
}
.overlay-paused { background: var(--bg); }
.overlay p, .overlay h2 { margin: 0; }
.ov-wordmark { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 700; }
.ov-wordmark .wm-ko { font-size: 40px; }
.ov-title { font-size: 28px; font-weight: 700; }
.ov-text { font-size: 14px; color: var(--text-sub); line-height: 1.5; }
.ov-label { font-size: 12px; color: var(--text-sub); margin-bottom: -8px !important; }
.ov-score { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ov-new { font-size: 14px; color: var(--accent); font-weight: 600; }
.ov-small { font-size: 12px; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.btn-ov { width: 160px; max-width: 100%; height: 48px; flex: none; }
.btn-ov-sub { width: 160px; max-width: 100%; height: 44px; flex: none; }

.toast {
  position: absolute; top: 12%; left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 10px;
  background: rgba(22, 24, 43, 0.85);
  color: var(--accent);
  font-size: 20px; font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

/* ── 확인 창 ── */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(22, 24, 43, 0.7);
}
.dialog {
  width: 100%; max-width: 320px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.dialog p { margin: 0 0 16px; font-size: 16px; line-height: 1.5; }
.dialog-btns { display: flex; gap: 8px; }

/* ── 터치 조작 ── */
.touch {
  display: none;
  position: sticky; bottom: 0; z-index: 5;
  margin-top: auto;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-group {
  display: grid;
  grid-template-columns: 76px 76px;
  grid-template-rows: 64px 56px;
  gap: 8px;
}
.tbtn {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 24px; line-height: 1;
  padding: 0;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  transition: transform 60ms;
}
.tbtn-wide { grid-column: 1 / span 2; }
.tbtn-drop { border-color: var(--accent); }
.tbtn.pressed { background: var(--grid); transform: scale(0.96); }
.tbtn:disabled { opacity: 0.4; }

.rotate-notice {
  display: none;
  position: fixed; inset: 0; z-index: 30;
  align-items: center; justify-content: center;
  background: var(--bg);
  font-size: 20px; font-weight: 700;
}

/* 터치 버튼: 폭 768px 미만이거나 주 입력 장치가 터치일 때 */
@media (max-width: 767px), (pointer: coarse) {
  .touch { display: flex; }
  .kbd-only { display: none; }
}

/* 중간 구간 */
@media (min-width: 768px) and (max-width: 1279px) {
  :root { --side: 160px; --gap: 20px; }
}

/* 모바일 */
@media (max-width: 767px) {
  .topbar { height: 44px; justify-content: space-between; padding: 0 12px; margin-bottom: 8px; }
  .wm-ko { font-size: 16px; }
  .wm-en { font-size: 12px; letter-spacing: 0.2em; }
  .wm-mark { border-bottom-width: 2px; }
  .icon-btn { display: block; }

  .layout {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "board next"
      "board stats"
      "board actions"
      "board .";
    column-gap: 8px;
    row-gap: 8px;
    justify-content: stretch;
    padding: 0 12px 8px;
  }
  .panel { padding: 8px; }
  .panel-title { margin-bottom: 4px; }
  .stats { gap: 8px; }
  .stat-value { font-size: 20px; }
  .help { display: none; }
  #btn-pause { display: none; }
  .actions .btn { font-size: 14px; }

  .ov-wordmark .wm-ko { font-size: 28px; }
  .ov-score { font-size: 28px; }
  .overlay { gap: 10px; padding: 8px; }
}

/* 가로로 돌린 휴대폰은 지원하지 않는다 */
@media (max-height: 479px) and (orientation: landscape) and (pointer: coarse) {
  .rotate-notice { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  .tbtn { transition: none; }
}
