/* =========================================================
   스파인 장기 — style.css
   먹색 다크 베이스(허브 연속) + 원목/한지 밝은 장기판.
   토큰(/assets/css/tokens.css)을 먼저 로드하고, 여기서는
   data-game="janggi" 변수(--game-cho/han/wood/hanji 등)를 사용한다.
   ========================================================= */

:root[data-game="janggi"] {
  --jg-gold: #c9a45c;                 /* 절제된 단청 금선 */
  --jg-frame-1: #7a5836;              /* 판 테두리 원목 */
  --jg-frame-2: #4a3320;
  --jg-frame-edge: #2a1c0e;
}

* { box-sizing: border-box; }
button, .board, .opt, .nav-btn, .ctrl-btn, .theme-card, .level-tab {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
html { -webkit-text-size-adjust: 100%; }

body.sgh-base {
  min-height: 100vh;
  line-height: 1.6;
  /* 먹색 다크에 아주 옅은 원목빛 광원 — 4중 레이어 대신 절제 */
  background:
    radial-gradient(900px 460px at 82% -12%, rgba(169, 126, 85, .10), transparent 62%),
    radial-gradient(760px 460px at -8% 112%, rgba(63, 143, 110, .07), transparent 58%),
    var(--sgh-bg-0);
}

/* 헤더 nav 버튼 (토큰은 a만 커버) */
.sgh-header__nav .nav-btn {
  display: inline-flex; align-items: center;
  min-height: var(--sgh-touch);
  padding: 0 var(--sgh-sp-3);
  border: 0; background: transparent;
  border-radius: var(--sgh-r-md);
  font-family: inherit; font-size: var(--sgh-fs-small); font-weight: 600;
  color: var(--sgh-text-2); cursor: pointer;
  transition: background var(--sgh-t-fast), color var(--sgh-t-fast);
}
.sgh-header__nav .nav-btn:hover { background: var(--sgh-bg-2); color: var(--sgh-text-1); }
.sgh-header__nav .nav-btn.active { color: var(--sgh-text-1); background: var(--game-accent-soft); }
.sgh-logo__mark { flex: 0 0 auto; }

.page { padding-top: var(--sgh-sp-6); padding-bottom: var(--sgh-sp-7); }

/* ---------- 화면 전환 ---------- */
.screen { display: none; }
.screen.active { display: block; animation: rise .28s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.screen-title {
  font-family: var(--sgh-font-display); font-weight: 700;
  font-size: var(--sgh-fs-h1); margin: 0 0 var(--sgh-sp-5);
}

/* =========================================================
   대국 화면 — 판 우선
   ========================================================= */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--sgh-sp-5);
  align-items: start;
}
.board-col { min-width: 0; }

/* 플레이어 바 */
.player-bar {
  display: flex; align-items: center; gap: var(--sgh-sp-3);
  background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1);
  border-radius: var(--sgh-r-md); padding: 8px 12px; margin: 6px 0;
  transition: border-color var(--sgh-t-fast), box-shadow var(--sgh-t-fast);
}
.player-bar .tag {
  font-family: var(--sgh-font-display); font-weight: 900; font-size: 16px;
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 8px; color: #fff; flex: none;
}
.player-bar.p-cho .tag { background: var(--game-cho); }
.player-bar.p-han .tag { background: var(--game-han); }
.player-bar .pb-txt { min-width: 0; }
.player-bar .who { font-weight: 700; font-size: 14px; color: var(--sgh-text-1); }
.player-bar .score { font-size: 12px; color: var(--sgh-text-3); }
.player-bar .caps { margin-left: auto; display: flex; flex-wrap: wrap; gap: 3px; max-width: 52%; justify-content: flex-end; }
.cap-pc {
  font-family: var(--sgh-font-display); font-weight: 800; font-size: 12px;
  width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px;
  background: var(--sgh-bg-2); border: 1px solid var(--sgh-border-1);
}
.cap-pc.cho { color: var(--game-cho); }
.cap-pc.han { color: var(--game-han); }
.player-bar.turn-now { border-color: var(--game-accent); box-shadow: 0 0 0 1px var(--game-accent); }

/* 판 프레임 — 원목, 그림자 절제(2겹) */
.board-frame {
  position: relative; border-radius: 16px; padding: 12px;
  background: linear-gradient(155deg, var(--jg-frame-1), var(--jg-frame-2) 60%, var(--jg-frame-edge));
  border: 1px solid var(--jg-frame-edge);
  box-shadow: var(--sgh-shadow-2), inset 0 1px 0 rgba(255, 235, 200, .18);
  max-width: 560px; margin: 0 auto;
}
.board {
  position: relative; width: 100%; aspect-ratio: 10 / 11;
  border-radius: 6px; overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .3);
}
.board svg.grid-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.board::after {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: 6px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .18);
}

/* 착점 표식 / 기물 (렌더 함수가 생성 — 클래스 유지) */
.cell-hit { position: absolute; transform: translate(-50%, -50%); width: 9.5%; aspect-ratio: 1; border-radius: 50%; z-index: 7; }
.cell-hit.dot::after {
  content: ""; position: absolute; inset: 32%; border-radius: 50%;
  background: rgba(63, 143, 110, .9); box-shadow: 0 0 0 3px rgba(63, 143, 110, .22);
  animation: pulse 1.2s ease infinite;
}
.cell-hit.dot.cap::after { background: rgba(178, 72, 61, .92); box-shadow: 0 0 0 3px rgba(178, 72, 61, .26); }
@keyframes pulse { 50% { transform: scale(1.16); } }

.pc {
  position: absolute; transform: translate(-50%, -50%); aspect-ratio: 1; user-select: none;
  filter: drop-shadow(0 3px 3px rgba(20, 10, 0, .4));
  transition: left .22s ease, top .22s ease; z-index: 5;
}
.pc svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.pc.sel { filter: brightness(1.08) drop-shadow(0 0 7px rgba(201, 164, 92, .95)); z-index: 6; }
.pc.mv { cursor: pointer; }
.sel-ring {
  position: absolute; transform: translate(-50%, -50%); width: 13.5%; aspect-ratio: 1;
  border: 2px solid rgba(201, 164, 92, .9); border-radius: 50%;
  box-shadow: 0 0 12px rgba(201, 164, 92, .5); pointer-events: none; z-index: 4;
}
.last-mark {
  position: absolute; transform: translate(-50%, -50%); width: 8%; aspect-ratio: 1;
  border: 2px dashed rgba(201, 164, 92, .85); border-radius: 50%; pointer-events: none; z-index: 4;
}

/* 상태줄 */
.status-line { display: flex; align-items: center; gap: var(--sgh-sp-2); margin-top: var(--sgh-sp-3); min-height: 34px; flex-wrap: wrap; }
.turn-chip.cho .sgh-status__dot, .turn-chip.cho::before { }
.turn-chip { font-weight: 600; }
.turn-chip.cho { background: var(--game-accent-soft); border-color: var(--game-cho); color: var(--sgh-text-1); }
.turn-chip.han { background: rgba(178, 72, 61, .12); border-color: var(--game-han); color: var(--sgh-text-1); }
.badge-alert { font-family: var(--sgh-font-display); font-weight: 800; letter-spacing: 2px; animation: pulse 1s ease infinite; }
.badge-alert.bik { background: rgba(201, 164, 92, .16); border-color: var(--jg-gold); color: var(--jg-gold); }
.thinking { font-size: var(--sgh-fs-small); color: var(--sgh-text-3); display: none; align-items: center; gap: 8px; }
.thinking.on { display: inline-flex; }
.thinking::before {
  content: ""; width: 12px; height: 12px;
  border: 2px solid var(--game-accent); border-top-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 대국 조작 */
.game-ctrl { margin-top: var(--sgh-sp-3); }
.ctrl-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sgh-sp-2); }
.ctrl-grid.ctrl-sub { grid-template-columns: 1fr 1fr; margin-top: var(--sgh-sp-2); }
.rp-grid { grid-template-columns: repeat(4, 1fr); }
.ctrl-btn {
  min-height: var(--sgh-touch);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--sgh-border-2); background: var(--sgh-bg-1);
  border-radius: var(--sgh-r-md); padding: 8px 6px;
  font-family: inherit; font-size: var(--sgh-fs-small); font-weight: 600;
  color: var(--sgh-text-1); cursor: pointer;
  transition: background var(--sgh-t-fast), border-color var(--sgh-t-fast), color var(--sgh-t-fast);
}
.ctrl-btn:hover { background: var(--sgh-bg-3); border-color: var(--game-accent); }
.ctrl-btn.primary { background: var(--game-accent); border-color: transparent; color: var(--sgh-brand-ink); }
.ctrl-btn.primary:hover { background: color-mix(in srgb, var(--game-accent) 85%, white); }
.ctrl-btn.warn { color: var(--sgh-danger); border-color: rgba(208, 91, 82, .5); }
.ctrl-btn.warn:hover { background: rgba(208, 91, 82, .12); border-color: var(--sgh-danger); }
.ctrl-btn[disabled] { opacity: .4; cursor: not-allowed; }

/* 사이드 패널 (기보) */
.side-panel { display: flex; flex-direction: column; gap: var(--sgh-sp-4); }
.panel-box {
  background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1);
  border-radius: var(--sgh-r-lg); padding: var(--sgh-sp-4);
}
.panel-box > summary {
  cursor: pointer; list-style: none;
  font-size: var(--sgh-fs-caption); font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--sgh-text-3); margin-bottom: var(--sgh-sp-3);
}
.panel-box > summary::-webkit-details-marker { display: none; }
.move-log { max-height: 340px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.move-log .mv-row { display: flex; gap: 8px; padding: 5px 8px; border-radius: 7px; background: var(--sgh-bg-2); }
.move-log .n { color: var(--sgh-text-3); width: 26px; flex: none; }
.move-log .s-cho { color: var(--game-cho); font-weight: 700; }
.move-log .s-han { color: var(--game-han); font-weight: 700; }
.mv-row.cur { outline: 2px solid var(--game-accent); }

/* =========================================================
   시작 모달
   ========================================================= */
.start-modal { max-width: 460px; }
.start-modes { display: flex; width: 100%; margin-bottom: var(--sgh-sp-5); }
.start-modes .start-mode { flex: 1; position: relative; }
.start-mode.is-soon { opacity: .72; }
.soon-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  background: var(--sgh-warn); color: #201a10; border-radius: var(--sgh-r-pill);
  padding: 1px 6px; margin-left: 4px;
}
.start-adv { margin-bottom: var(--sgh-sp-4); border-top: 1px solid var(--sgh-border-1); padding-top: var(--sgh-sp-3); }
.start-adv > summary {
  cursor: pointer; list-style: none; font-size: var(--sgh-fs-small);
  font-weight: 600; color: var(--sgh-text-2); padding: 4px 0;
}
.start-adv > summary::-webkit-details-marker { display: none; }
.start-adv > summary::before { content: "▸ "; color: var(--game-accent); }
.start-adv[open] > summary::before { content: "▾ "; }
.start-go { width: 100%; margin-top: var(--sgh-sp-3); font-family: var(--sgh-font-display); }
.start-close { width: 100%; margin-top: var(--sgh-sp-3); }

/* 옵션 그룹 (모달 공용) */
.opt-group { margin-bottom: var(--sgh-sp-4); }
.opt-group > label { display: block; font-size: var(--sgh-fs-small); font-weight: 700; color: var(--sgh-text-2); margin-bottom: 8px; }
.opt-row { display: grid; gap: 8px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-5 { grid-template-columns: repeat(5, 1fr); }
.opt {
  border: 1px solid var(--sgh-border-2); background: var(--sgh-bg-1);
  border-radius: var(--sgh-r-md); padding: 10px 6px; text-align: center;
  color: var(--sgh-text-1); cursor: pointer; min-height: var(--sgh-touch);
  transition: border-color var(--sgh-t-fast), background var(--sgh-t-fast);
}
.opt b { display: block; font-size: 14px; font-family: var(--sgh-font-display); }
.opt span { display: block; font-size: 11px; color: var(--sgh-text-3); margin-top: 2px; }
.opt:hover { border-color: var(--game-accent); }
.opt.selected { border-color: var(--game-accent); background: var(--game-accent-soft); box-shadow: inset 0 0 0 1px var(--game-accent); }
.opt.selected span { color: var(--sgh-text-2); }

/* =========================================================
   종료 모달
   ========================================================= */
.overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  place-items: center; padding: var(--sgh-sp-5);
  background: rgba(8, 6, 4, .62); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.overlay.on { display: grid; }
.modal {
  background: var(--sgh-bg-2); border: 1px solid var(--sgh-border-2);
  border-radius: var(--sgh-r-lg); max-width: 420px; width: 100%;
  padding: var(--sgh-sp-7) var(--sgh-sp-6); text-align: center;
  box-shadow: var(--sgh-shadow-2); animation: rise .28s ease;
}
.modal .big { font-family: var(--sgh-font-display); font-weight: 900; font-size: 32px; margin-bottom: 6px; }
.modal .big.win { color: var(--game-cho); }
.modal .big.lose { color: var(--game-han); }
.modal .big.draw { color: var(--jg-gold); }
.modal .why { color: var(--sgh-text-2); font-size: 14px; margin-bottom: 14px; }
.modal .score-line { display: flex; justify-content: center; gap: 18px; font-size: 14px; margin-bottom: 20px; color: var(--sgh-text-1); }
.modal .score-line b { font-family: var(--sgh-font-display); }
.modal-btns { display: flex; gap: var(--sgh-sp-2); }
.modal-btns .sgh-btn { flex: 1; padding: 0 var(--sgh-sp-3); }

/* =========================================================
   장기교실
   ========================================================= */
.level-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sgh-sp-3); margin-bottom: var(--sgh-sp-5); }
.level-tab {
  background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1); border-radius: var(--sgh-r-lg);
  padding: 14px 10px; text-align: center; cursor: pointer;
  transition: border-color var(--sgh-t-fast), background var(--sgh-t-fast);
}
.level-tab .hanja { font-family: var(--sgh-font-display); font-weight: 900; font-size: 20px; color: var(--jg-gold); }
.level-tab .t { font-family: var(--sgh-font-display); font-weight: 700; font-size: 16px; margin: 3px 0 1px; color: var(--sgh-text-1); }
.level-tab .e { font-size: 10px; letter-spacing: .1em; color: var(--sgh-text-3); }
.level-tab:hover { border-color: var(--game-accent); }
.level-tab.active { border-color: var(--game-accent); background: var(--game-accent-soft); }

.toc-box { background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1); border-radius: var(--sgh-r-lg); padding: 14px 16px; margin-bottom: var(--sgh-sp-4); }
.toc-box .toc-t { font-size: 12px; font-weight: 700; color: var(--jg-gold); letter-spacing: .12em; margin-bottom: 10px; }
.toc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.toc-item { display: flex; gap: 9px; align-items: flex-start; background: var(--sgh-bg-2); border-radius: 9px; padding: 8px 10px; }
.toc-item .num { flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--game-accent); color: var(--sgh-brand-ink); font-size: 11px; font-weight: 800; display: grid; place-items: center; margin-top: 2px; }
.toc-item b { font-size: 13px; display: block; color: var(--sgh-text-1); }
.toc-item span { font-size: 11px; color: var(--sgh-text-3); }

.lesson-section { background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1); border-radius: var(--sgh-r-lg); padding: 22px 24px; margin-bottom: var(--sgh-sp-4); }
.lesson-section.accent { border-left: 3px solid var(--game-han); }
.lesson-section h3 { font-family: var(--sgh-font-display); font-size: 19px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; color: var(--sgh-text-1); }
.lesson-section h3 .ic { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--sgh-bg-3); color: var(--jg-gold); font-size: 17px; }
.lesson-section p { font-size: 14px; margin-bottom: 10px; color: var(--sgh-text-2); }
.lesson-section ul { padding-left: 20px; }
.lesson-section li { font-size: 14px; margin-bottom: 7px; color: var(--sgh-text-2); }
.lesson-section blockquote {
  border-left: 3px solid var(--game-han); background: var(--sgh-bg-2); border-radius: 0 10px 10px 0;
  padding: 10px 16px; margin: 12px 0; font-family: var(--sgh-font-display); font-size: 14px; color: var(--sgh-text-1);
}
.c-cho { color: var(--game-cho); font-weight: 700; }
.c-han { color: var(--game-han); font-weight: 700; }
.dot-note { color: var(--game-accent); font-weight: 700; }
.lesson-note { margin-top: 14px; border-left: 3px solid var(--jg-gold); background: var(--sgh-bg-2); border-radius: 0 10px 10px 0; padding: 12px 16px; font-size: 13px; color: var(--sgh-text-2); }

.piece-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; margin-top: 14px; }
.piece-card { background: var(--sgh-bg-2); border: 1px solid var(--sgh-border-1); border-radius: 12px; padding: 14px; }
.piece-card .ph {
  font-family: var(--sgh-font-display); font-weight: 900; font-size: 20px; width: 40px; height: 40px;
  display: grid; place-items: center; color: var(--game-cho);
  background: var(--sgh-bg-3); border: 1px solid var(--jg-gold); margin-bottom: 8px;
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
}
.piece-card b { font-size: 14px; color: var(--sgh-text-1); }
.piece-card .pts { font-size: 12px; color: var(--jg-gold); font-weight: 700; margin-left: 6px; }
.piece-card p { font-size: 12.5px; color: var(--sgh-text-2); margin-top: 5px; }

.diagram-grid { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.diag { background: var(--sgh-bg-2); border: 1px solid var(--sgh-border-1); border-radius: 12px; padding: 12px; width: 200px; }
.diag.wide { width: 100%; max-width: 560px; }
.diag.tall { width: 240px; }
.diag svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.diag .d-badge { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: var(--game-han); border-radius: var(--sgh-r-pill); padding: 2px 10px; margin-top: 8px; }
.diag .d-label { font-family: var(--sgh-font-display); font-weight: 700; font-size: 14px; margin-top: 6px; color: var(--sgh-text-1); }
.diag .d-cap { font-size: 12px; color: var(--sgh-text-3); margin-top: 3px; }

.bars { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 64px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; color: var(--sgh-text-2); }
.bar-row .bar { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--jg-gold), #b98d3f); }
.bar-row .v { font-weight: 700; color: var(--jg-gold); }

/* =========================================================
   장기판 테마 화면
   ========================================================= */
.theme-sec { background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1); border-radius: var(--sgh-r-lg); padding: 22px; margin-bottom: var(--sgh-sp-5); }
.theme-sec h2 { font-family: var(--sgh-font-display); font-size: var(--sgh-fs-h2); color: var(--sgh-text-1); }
.theme-sec .sub { color: var(--sgh-text-2); font-size: 14px; margin: 4px 0 18px; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.theme-card {
  border: 2px solid var(--sgh-border-2); border-radius: 12px; overflow: hidden;
  background: var(--sgh-bg-2); text-align: left; padding: 0 0 12px; cursor: pointer;
  transition: border-color var(--sgh-t-fast), transform var(--sgh-t-fast);
}
.theme-card:hover { border-color: var(--game-accent); transform: translateY(-2px); }
.theme-card.selected { border-color: var(--game-accent); box-shadow: 0 0 0 2px var(--game-accent-soft); }
.theme-card svg { width: 100%; height: auto; display: block; }
.theme-card .tn { font-family: var(--sgh-font-display); font-weight: 700; font-size: 15px; padding: 10px 13px 0; display: block; color: var(--sgh-text-1); }
.theme-card .te { font-size: 11px; letter-spacing: .08em; color: var(--sgh-text-3); padding: 0 13px; display: block; }
.pv-piece-row { display: flex; gap: 10px; justify-content: center; padding: 16px 0 8px; }
.pv-pc { width: 52px; height: 52px; display: block; filter: drop-shadow(0 2px 3px rgba(20, 10, 0, .35)); }
.pv-pc svg { width: 100%; height: 100%; display: block; }

/* =========================================================
   기보함
   ========================================================= */
.theme-sec .sub + .file-btn, .file-btn { display: inline-flex; margin-bottom: 14px; min-height: var(--sgh-touch); }
.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec-empty { text-align: center; color: var(--sgh-text-3); font-size: 14px; padding: 34px 10px; background: var(--sgh-bg-2); border-radius: 12px; line-height: 1.9; }
.record-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--sgh-bg-2); border: 1px solid var(--sgh-border-1); border-radius: 12px; padding: 12px 14px; }
.rec-info { flex: 1; min-width: 200px; }
.rec-info b { font-size: 14px; display: block; color: var(--sgh-text-1); }
.rec-info span { font-size: 12px; color: var(--sgh-text-3); }
.rec-actions { display: flex; gap: 8px; }
.rec-actions .ctrl-btn { padding: 8px 12px; font-size: 12px; min-height: 38px; }

/* =========================================================
   소개(접힘) — 긴 SEO 문단
   ========================================================= */
.sgh-about {
  max-width: 760px; margin: var(--sgh-sp-7) auto 0;
  background: var(--sgh-bg-1); border: 1px solid var(--sgh-border-1);
  border-radius: var(--sgh-r-lg); padding: var(--sgh-sp-4) var(--sgh-sp-5);
}
.sgh-about > summary { cursor: pointer; font-weight: 600; font-size: var(--sgh-fs-small); color: var(--sgh-text-2); }
.sgh-about p { margin-top: var(--sgh-sp-3); font-size: var(--sgh-fs-small); color: var(--sgh-text-3); line-height: 1.75; }

/* ---------- 토스트 ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--sgh-bg-3); color: var(--sgh-text-1); font-size: 14px; font-weight: 600;
  padding: 12px 22px; border-radius: var(--sgh-r-pill); z-index: 300; opacity: 0; pointer-events: none;
  transition: opacity var(--sgh-t-med), transform var(--sgh-t-med);
  box-shadow: var(--sgh-shadow-2); max-width: 90vw; text-align: center;
  border: 1px solid var(--sgh-border-2);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================================
   반응형 — 브레이크포인트 640 / 1024 통일
   ========================================================= */

/* 태블릿 이하: 사이드 패널을 판 아래로 */
@media (max-width: 1023px) {
  .game-layout { grid-template-columns: 1fr; gap: var(--sgh-sp-3); }
  .side-panel { flex-direction: row; flex-wrap: wrap; }
  .side-panel .panel-box { flex: 1; min-width: 240px; }
  .move-log { max-height: 200px; }
  /* 세로 화면에서 판이 우선 보이도록 높이 기준 제한 */
  .board-frame { max-width: min(100%, 62vh); }
}

/* 모바일: 1열, 조작 버튼 44px 유지 */
@media (max-width: 639px) {
  .sgh-wrap { padding: 0 var(--sgh-sp-3); }
  .page { padding-top: var(--sgh-sp-4); }
  .sgh-header__game { display: none; }
  .sgh-header__inner { gap: var(--sgh-sp-2); min-width: 0; }
  /* 내비가 넘치면 페이지가 아니라 내비 자체가 가로 스크롤 */
  .sgh-header__nav {
    gap: 0;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .sgh-header__nav::-webkit-scrollbar { display: none; }
  .sgh-header__nav .nav-btn { padding: 0 8px; font-size: var(--sgh-fs-caption); flex: 0 0 auto; }
  .sgh-header__nav a { padding: 0 8px; flex: 0 0 auto; }
  .cols-5 { grid-template-columns: repeat(3, 1fr); }
  .board-frame { max-width: min(100%, 74vh); padding: 8px; }
  .player-bar { padding: 6px 10px; }
  .player-bar .who { font-size: 13px; }
  .side-panel { flex-direction: column; }
  .side-panel .panel-box { min-width: 0; }
  .theme-grid { grid-template-columns: 1fr 1fr; }
  .level-tabs { gap: 8px; }
  .level-tab { padding: 10px 6px; }
  .level-tab .hanja { font-size: 16px; }
  .level-tab .t { font-size: 13px; }
  .level-tab .e { display: none; }
  .lesson-section { padding: 18px 16px; }
  .diag { width: calc(50% - 7px); }
  .diag.wide, .diag.tall { width: 100%; }
  .record-row { gap: 8px; }
  .rec-actions { width: 100%; }
  .rec-actions .ctrl-btn { flex: 1; }
}

/* 가로(landscape) 모바일: 판과 조작을 좌우로 나눠 판이 작아지지 않게 */
@media (max-height: 560px) and (orientation: landscape) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 260px; }
  .board-frame { max-width: min(100%, 88vh); }
  .side-panel { flex-direction: column; }
  .move-log { max-height: 40vh; }
}
