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

:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface2: #1f2937;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --gold: #f59e0b;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: rgba(255,255,255,0.08);
  --up: #34d399;
  --down: #f87171;
  --danger: #f87171;

  /* board themes (set on body) */
  --sq-light: #e8edf4;
  --sq-dark: #6f82a3;
  --sq-sel: rgba(99,102,241,0.55);
  --sq-last: rgba(245,158,11,0.38);
  --sq-check: rgba(248,113,113,0.65);
}

body.theme-blue  { --sq-light: #dce8f5; --sq-dark: #5a7aa8; }
body.theme-slate { --sq-light: #cfd4dc; --sq-dark: #4b5563; }

html, body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── AUTH LOADING ── */
#auth-loading {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 999;
  font-size: 14px; color: var(--muted);
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(99,102,241,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loading-spinner.small { width: 22px; height: 22px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── NAV (디자인 시스템 공통) ── */
nav {
  display: flex; align-items: center; gap: 0;
  padding: 0 40px; height: 56px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,26,0.92);
  backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 100;
}
.logo {
  display: flex; align-items: center; gap: 9px;
  font-size: 15px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text); text-decoration: none;
  flex-shrink: 0; margin-right: 32px;
}
.logo-icon {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  border-radius: 7px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
}
.logo span { color: var(--accent-light); }
.nav-menu { display: flex; align-items: center; gap: 2px; flex: 1; }
.nav-menu .nav-link {
  padding: 6px 12px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--muted);
  text-decoration: none; transition: color .15s, background .15s; white-space: nowrap;
}
.nav-menu .nav-link:hover { color: var(--text); background: rgba(255,255,255,.06); }
.nav-menu .nav-link.active { color: var(--text); background: rgba(99,102,241,.14); }
.nav-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.nav-email {
  font-size: 12px; color: var(--muted);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-logout {
  background: rgba(255,255,255,.04); border: 1px solid var(--border);
  color: var(--muted); padding: 5px 13px; border-radius: 7px;
  font-size: 12px; font-weight: 500; font-family: 'Inter', sans-serif;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-logout:hover { border-color: rgba(255,255,255,.18); color: var(--text); background: rgba(255,255,255,.07); }

/* ── MAIN ── */
main { max-width: 1240px; margin: 0 auto; padding: 22px 28px 40px; }

/* ── PAGE HEADER ── */
.chess-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.ch-title-group h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.ch-title-group h1 span { color: var(--accent-light); }
.ch-subtitle { font-size: 13px; color: var(--muted); margin-top: 4px; }
.ch-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.engine-indicator {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: rgba(255,255,255,.02);
}
.engine-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  transition: background .2s; flex-shrink: 0;
}
.engine-indicator.ready .dot   { background: var(--up); }
.engine-indicator.thinking .dot{ background: var(--gold); animation: pulse 1s infinite; }
.engine-indicator.error .dot   { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* ── BUTTONS ── */
.btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 9px; padding: 10px 16px;
  font-size: 13px; font-weight: 600; font-family: 'Inter', sans-serif;
  cursor: pointer; transition: background .18s, transform .1s, opacity .18s; white-space: nowrap;
}
.btn:hover { background: var(--accent-light); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.ghost { background: rgba(255,255,255,.04); color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { background: rgba(255,255,255,.08); color: var(--text); border-color: rgba(255,255,255,.18); }
.btn.sm { padding: 7px 12px; font-size: 12px; border-radius: 8px; }
.btn.xs { padding: 5px 10px; font-size: 11px; border-radius: 7px; }

/* ── STUDIO GRID ── */
.studio-grid {
  display: grid;
  grid-template-columns: minmax(360px, auto) 1fr;
  gap: 24px; align-items: start;
}

/* ── BOARD COLUMN ── */
.board-col { display: flex; flex-direction: column; gap: 10px; }
.board-area { display: flex; gap: 10px; align-items: stretch; }

.eval-bar {
  position: relative; width: 20px; border-radius: 6px; overflow: hidden;
  background: #1a2233; border: 1px solid var(--border); flex-shrink: 0;
  display: flex; flex-direction: column-reverse;
}
.eval-fill { width: 100%; background: #f2f4f8; height: 50%; transition: height .4s ease; }
.eval-num { position: absolute; left: 0; right: 0; text-align: center; font-size: 9px; font-weight: 700; }
.eval-num.top { top: 3px; color: #1a2233; }
.eval-num.bottom { bottom: 3px; color: #e8edf4; }

.board-wrap { position: relative; width: var(--board-size, 480px); height: var(--board-size, 480px); flex-shrink: 0; }
.board {
  width: 100%; height: 100%;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(0,0,0,0.5); user-select: none; touch-action: none;
  container-type: inline-size;           /* 기물/좌표를 보드 실제 크기에 비례해 스케일 */
  -webkit-user-select: none;
  -webkit-touch-callout: none;           /* 롱프레스 콜아웃 방지 */
  -webkit-tap-highlight-color: transparent;
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq.sel::after    { content:''; position:absolute; inset:0; background: var(--sq-sel); }
.sq.last::before  { content:''; position:absolute; inset:0; background: var(--sq-last); }
.sq.check .piece  { filter: drop-shadow(0 0 6px var(--sq-check)); }
.sq.check::before { content:''; position:absolute; inset:0; background: var(--sq-check); border-radius:50%; transform: scale(.85); z-index:0; }

.sq .coord-file, .sq .coord-rank {
  position: absolute; font-size: clamp(7px, 2.1cqw, 11px); font-weight: 700; opacity: .65; pointer-events: none;
}
.sq .coord-rank { top: 2px; left: 3px; }
.sq .coord-file { bottom: 1px; right: 3px; }
.sq.light .coord-file, .sq.light .coord-rank { color: var(--sq-dark); }
.sq.dark  .coord-file, .sq.dark  .coord-rank { color: var(--sq-light); }

.piece {
  position: relative; z-index: 2;
  width: 86%; height: 86%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9.3cqw;                      /* 보드 너비의 9.3% → 칸(12.5%)의 약 75% */
  line-height: 1; cursor: grab;
}
@supports not (font-size: 1cqw) {         /* 컨테이너 쿼리 미지원 브라우저 폴백 */
  .piece { font-size: calc(var(--board-size, 480px) / 10.8); }
}
.board.animate .piece { transition: transform .18s ease; }
.piece.dragging { cursor: grabbing; z-index: 50; }

/* solid vs outline piece styles via glyph color/shadow */
.piece.w { color: #f8fafc; text-shadow: 0 1px 2px rgba(0,0,0,.55), 0 0 1px #000; }
.piece.b { color: #11161f; text-shadow: 0 1px 2px rgba(255,255,255,.25); }
body.pieces-outline .piece.w { color: #fff; -webkit-text-stroke: 1.2px #1a2233; text-shadow:none; }
body.pieces-outline .piece.b { color: #1a2233; -webkit-text-stroke: 1.2px #cbd5e1; text-shadow:none; }

.legal-dot {
  position: absolute; z-index: 1; width: 30%; height: 30%;
  border-radius: 50%; background: rgba(30,40,60,0.35); pointer-events: none;
}
.sq.light .legal-dot { background: rgba(30,40,60,0.30); }
.sq.dark  .legal-dot { background: rgba(255,255,255,0.32); }
.legal-dot.capture { width: 92%; height: 92%; background: transparent; border: 4px solid rgba(30,40,60,0.32); }
.sq.dark .legal-dot.capture { border-color: rgba(255,255,255,0.3); }

.board-overlay {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(8,11,20,0.0); backdrop-filter: blur(1px);
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
}
.overlay-card { text-align: center; padding: 26px 30px; }
.overlay-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.overlay-sub { font-size: 13px; color: var(--muted); margin-bottom: 18px; }

/* captured */
.captured-row {
  min-height: 24px; display: flex; align-items: center; gap: 1px;
  font-size: 18px; line-height: 1; flex-wrap: wrap; color: var(--muted);
}
.captured-row .cap-adv { margin-left: 8px; font-size: 11px; font-weight: 700; color: var(--up); font-family: 'Inter',sans-serif; }

.board-size-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--muted); margin-top: 2px;
}
.board-size-row input[type=range] { flex: 1; max-width: 220px; }

/* ── PANEL COLUMN ── */
.panel-col {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden; position: sticky; top: 72px;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.02); }
.tab {
  flex: 1; padding: 12px 6px; background: none; border: none;
  color: var(--muted); font-size: 12.5px; font-weight: 600; font-family: 'Inter',sans-serif;
  cursor: pointer; transition: color .15s, background .15s; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); background: rgba(99,102,241,.08); }
.tab-body { padding: 18px; max-height: 620px; overflow-y: auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }

.field-group { margin-bottom: 16px; }
.fg-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.fg-label small { font-weight: 400; opacity: .8; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  padding: 7px 13px; background: transparent; border: none; border-right: 1px solid var(--border);
  color: var(--muted); font-size: 12px; font-weight: 500; font-family: 'Inter',sans-serif; cursor: pointer; transition: all .15s;
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: rgba(255,255,255,.05); color: var(--text); }
.seg button.active { background: var(--accent); color: #fff; }

.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; }
.slider-val { font-size: 13px; font-weight: 700; color: var(--text); min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.hint { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.empty-hint { font-size: 12px; color: var(--muted); text-align: center; padding: 24px 10px; line-height: 1.6; }

input[type=range] { -webkit-appearance: none; appearance: none; height: 5px; border-radius: 3px; background: var(--surface2); cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid var(--surface); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid var(--surface); }

.switch-inline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-bottom: 12px; cursor: pointer; }
.switch-inline input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.disclaimer { font-size: 10.5px; color: var(--muted); line-height: 1.6; margin-top: 10px; opacity: .85; }

/* analysis */
.engine-error, .edit-error, .io-error {
  font-size: 12px; color: var(--danger); background: rgba(248,113,113,0.08);
  border: 1px solid rgba(248,113,113,0.2); border-radius: 8px; padding: 9px 11px; margin-bottom: 12px; line-height: 1.5;
}
.eval-summary { display: flex; align-items: baseline; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.eval-score-big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.eval-score-big.pos { color: var(--up); } .eval-score-big.neg { color: var(--down); }
.eval-meta { display: flex; gap: 12px; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.pv-list { display: flex; flex-direction: column; gap: 6px; }
.pv-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: rgba(255,255,255,.02); cursor: pointer; transition: border-color .15s, background .15s;
}
.pv-item:hover { border-color: rgba(99,102,241,.4); background: rgba(99,102,241,.06); }
.pv-rank { font-size: 11px; color: var(--muted); font-weight: 700; flex-shrink: 0; }
.pv-score { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 52px; flex-shrink: 0; }
.pv-score.pos { color: var(--up); } .pv-score.neg { color: var(--down); }
.pv-moves { font-size: 12px; color: var(--text); line-height: 1.5; word-break: break-word; }
.pv-moves .first-move { font-weight: 700; color: var(--accent-light); }

/* moves */
.movenav { display: flex; gap: 6px; margin-bottom: 12px; }
.movenav button {
  flex: 1; padding: 9px; background: rgba(255,255,255,.04); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; cursor: pointer; font-size: 14px; transition: all .15s;
}
.movenav button:hover { background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.18); }
.move-table-wrap { max-height: 300px; overflow-y: auto; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 10px; }
.move-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.move-table td { padding: 6px 10px; border-bottom: 1px solid rgba(255,255,255,.04); }
.move-table .mv-num { color: var(--muted); width: 34px; font-variant-numeric: tabular-nums; }
.move-table .mv-san { cursor: pointer; border-radius: 5px; font-weight: 500; }
.move-table .mv-san:hover { background: rgba(255,255,255,.07); }
.move-table .mv-san.current { background: var(--accent); color: #fff; }
.fen-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.fen-row label { font-size: 11px; color: var(--muted); font-weight: 600; flex-shrink: 0; }
.fen-row input {
  flex: 1; min-width: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; color: var(--text); font-size: 11px; font-family: ui-monospace, monospace; outline: none;
}
.fen-row input:focus { border-color: var(--accent); }

.play-status {
  font-size: 13px; color: var(--text); padding: 11px 13px; border-radius: 9px;
  background: rgba(99,102,241,.08); border: 1px solid rgba(99,102,241,.2); margin-bottom: 10px; line-height: 1.5;
}

/* editor palette */
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.palette .pz {
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  font-size: 26px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,.03); transition: all .15s; line-height: 1;
}
.palette .pz.w { color: #f8fafc; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.palette .pz.b { color: #11161f; background: rgba(255,255,255,.12); }
.palette .pz:hover { border-color: rgba(99,102,241,.45); }
.palette .pz.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: rgba(99,102,241,.14); }
.palette .pz.eraser { font-size: 18px; color: var(--muted); }

/* ── MODALS ── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(8,11,20,0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.promo-box, .io-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; box-shadow: 0 24px 64px rgba(0,0,0,.6); width: 100%;
}
.promo-box { max-width: 300px; text-align: center; }
.promo-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.promo-choices { display: flex; justify-content: center; gap: 8px; }
.promo-choices .pz {
  width: 56px; height: 56px; font-size: 34px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 11px; cursor: pointer; transition: all .15s; line-height: 1;
}
.promo-choices .pz:hover { border-color: var(--accent); background: rgba(99,102,241,.14); transform: translateY(-2px); }

.io-box { max-width: 520px; }
.io-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-size: 15px; font-weight: 600; }
.io-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.io-close:hover { color: var(--text); }
.io-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.io-tab { padding: 6px 14px; background: rgba(255,255,255,.04); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.io-tab.active { background: var(--accent); color: #fff; }
#io-text {
  width: 100%; min-height: 160px; resize: vertical;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; color: var(--text); font-size: 12px; font-family: ui-monospace, monospace; outline: none; line-height: 1.6;
}
#io-text:focus { border-color: var(--accent); }
.io-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ── ELO 증감 버튼 (슬라이더 보조) ── */
.step-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  background: rgba(255,255,255,.05); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; font-size: 18px; line-height: 1; cursor: pointer; font-family: 'Inter',sans-serif;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.step-btn:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.2); }
.step-btn:active { transform: scale(.94); }

/* ── 모바일 하단 고정 컨트롤 바 (기본 숨김) ── */
.mobile-bottombar {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  align-items: center; gap: 4px;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  background: rgba(10,14,26,0.96); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.mobile-bottombar .mbb {
  flex: 1; min-width: 44px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.05); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; font-size: 18px; line-height: 1; cursor: pointer; font-family: 'Inter',sans-serif;
  -webkit-tap-highlight-color: transparent; transition: background .12s, opacity .12s;
}
.mobile-bottombar .mbb:active { background: rgba(99,102,241,.25); }
.mobile-bottombar .mbb:disabled { opacity: .32; }
.mobile-bottombar .mbb-sep { width: 1px; height: 26px; background: var(--border); flex: 0 0 auto; margin: 0 2px; }

/* 비활성 기보 네비 버튼 (데스크톱 포함) */
.movenav button:disabled { opacity: .35; cursor: default; }

/* ── FOOTER ── */
footer {
  text-align: center; padding: 18px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--border); margin-top: 40px;
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   - >980px        : 데스크톱 2단 (보드 크기 = --board-size 슬라이더)
   - ≤980px        : 단일 컬럼 공통
   - 세로 모바일   : 보드 = 가용 폭/높이 중 작은 값, 하단 고정바
   - 가로(저높이)  : 보드+패널 2단, 보드는 높이 기준
   ══════════════════════════════════════════════════════════ */

/* 안전영역: 사이트 내비 좌우 패딩 */
nav { padding-left: max(40px, env(safe-area-inset-left)); padding-right: max(40px, env(safe-area-inset-right)); }

/* ── 태블릿/모바일 공통 (단일 컬럼) ── */
@media (max-width: 980px) {
  .studio-grid { grid-template-columns: 1fr; gap: 14px; }
  .panel-col { position: static; }
  .board-area { justify-content: center; }
  .board-size-row { display: none; }           /* 보드 자동 크기 → 수동 슬라이더 숨김 */
  .tab-body { max-height: none; overflow: visible; }  /* 페이지 전체 스크롤 사용 */
}

/* ── 세로 모바일/태블릿 ── */
@media (max-width: 980px) and (orientation: portrait) {
  nav { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .logo { margin-right: 14px; }
  .nav-menu .nav-link { padding: 5px 9px; font-size: 12px; }
  .nav-email { display: none; }

  main { padding: 10px 10px 0; }
  .chess-header { gap: 8px; margin-bottom: 10px; align-items: center; flex-wrap: nowrap; }
  .ch-title-group h1 { font-size: 17px; }
  .ch-subtitle { font-size: 11.5px; margin-top: 2px; }
  .ch-actions .btn { display: none; }           /* 헤더 액션 → 하단바/탭으로 이동 */
  .ch-actions { gap: 6px; }
  .engine-indicator { font-size: 11px; padding: 5px 9px; }

  .eval-bar { width: 16px; }
  .board-area { gap: 6px; }
  /* 보드: 가용 폭과 가용 높이 중 작은 값, 항상 정사각형 */
  .board-wrap {
    width: min(calc(100vw - 46px), calc(100vh - 250px));
    width: min(calc(100vw - 46px), calc(100dvh - 250px));
    height: auto; aspect-ratio: 1 / 1; flex-shrink: 1;
  }
  @supports not (aspect-ratio: 1 / 1) {
    .board-wrap { height: min(calc(100vw - 46px), calc(100dvh - 250px)); }
  }
  .captured-row { font-size: 15px; min-height: 20px; }

  .mobile-bottombar { display: flex; }
  footer { margin-top: 18px; margin-bottom: calc(68px + env(safe-area-inset-bottom)); }

  /* 패널 터치 타깃 */
  .tab { font-size: 12px; padding: 13px 4px; min-height: 46px; }
  .movenav button { padding: 12px; min-height: 46px; }
}

/* ── 가로 모바일 (저높이): 보드 + 패널 나란히 ── */
@media (max-width: 980px) and (orientation: landscape) and (max-height: 600px) {
  nav { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .nav-email { display: none; }
  main { padding: 8px 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .chess-header { margin-bottom: 6px; gap: 8px; }
  .chess-header .ch-subtitle { display: none; }
  .ch-title-group h1 { font-size: 15px; }
  .ch-actions .btn { display: none; }

  .studio-grid { grid-template-columns: auto minmax(230px, 1fr); gap: 10px; align-items: start; }
  .board-col { gap: 4px; }
  .captured-row { min-height: 15px; font-size: 13px; }
  .eval-bar { width: 14px; }
  .board-wrap {
    height: min(calc(100vh - 78px), calc(100vw - 270px));
    height: min(calc(100dvh - 78px), calc(100vw - 270px));
    width: auto; aspect-ratio: 1 / 1;
  }
  .mobile-bottombar { display: none !important; }
  .tab-body { max-height: calc(100dvh - 118px); overflow-y: auto; }
  .tab { min-height: 42px; }
  footer { display: none; }
}

/* ── 터치 입력 기기: 슬라이더·토글 확대 ── */
@media (pointer: coarse) {
  input[type=range] { height: 7px; }
  input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; }
  input[type=range]::-moz-range-thumb { width: 22px; height: 22px; }
  .switch-inline { padding: 4px 0; }
  .switch-inline input { width: 20px; height: 20px; }
  .seg button { padding: 10px 14px; }
  .pv-item { padding: 12px 11px; }
}

/* ── 초소형 화면 ── */
@media (max-width: 400px) {
  .logo span { display: none; }
  .tab { font-size: 11px; padding: 12px 2px; }
  .ch-title-group h1 { font-size: 16px; }
}

/* ── 모션 감소 설정 존중 ── */
@media (prefers-reduced-motion: reduce) {
  .board.animate .piece, .btn, .mbb, .step-btn, .eval-fill, .tab, .seg button,
  .pv-item, .movenav button, .nav-menu .nav-link {
    transition: none !important;
  }
  .engine-indicator.thinking .dot { animation: none !important; }
  .loading-spinner { animation-duration: 1.4s; }
}
