/* ============================================================
   바둑 앱 · 디자인 토큰 (Design Tokens) v2 — 2026-06-28
   ------------------------------------------------------------
   - 라이트/다크 모드 (prefers-color-scheme + body.theme-dark/light 강제)
   - 컴포넌트 클래스: .btn / .btn-primary / .btn-ghost / .btn-danger
                     .chip / .segmented / .input / .select / .card / .surface
   - 6단계 반응형 (모바일↔태블릿↔데스크탑 · 가로/세로)
   - iOS safe-area, 44px 최소 탭, PWA 친화 레이아웃
   - 바둑판이 모바일/태블릿 가로모드에서도 반드시 보이도록 board-first 레이아웃
   ============================================================ */

/* ============================================================
   1) Light theme tokens (default)
   ============================================================ */
:root {
  color-scheme: light dark;

  /* ---- 표면 / 배경 ---- */
  --bg:              #f6f3ec;
  --bg-elev:         #fbf8f1;       /* 헤더/툴바 등 한 단계 위 표면 */
  --surface:         #ffffff;
  --surface-subtle:  #faf8f3;
  --code-bg:         #f1efe8;
  --hover-bg:        #f1ecde;
  --press-bg:        #e9e1cb;

  /* ---- 반상·돌 ---- */
  --board:           #dcb35c;
  --board-edge:      #b88c3a;
  --stone-b:         #161616;
  --stone-b-edge:    #000000;
  --stone-w:         #ffffff;
  --stone-w-edge:    #8a8a8a;

  /* ---- 텍스트 ---- */
  --text:            #1d1d1f;
  --text-soft:       #4a4a4f;
  --text-muted:      #6e6e76;
  --text-faint:      #93939c;
  --text-on-accent:  #1d1300;

  /* ---- 보더 ---- */
  --border:          #e7e1d0;
  --border-strong:   #d2c8ae;
  --border-faint:    #efece4;

  /* ---- 강조 / 상태 ---- */
  --accent:          #b88c3a;
  --accent-soft:     #d6ad60;
  --accent-bg:       #f1e3bf;
  --accent-bg-hover: #e8d49d;
  --link:            #0f6cbd;
  --success:         #1f7a3a;
  --warning:         #d18d10;
  --danger:          #c0392b;
  --info:            #1565c0;

  --focus-ring:      0 0 0 3px rgba(184, 140, 58, 0.45);

  /* ---- 복기 등급 ---- */
  --grade-inaccuracy:#f0c419;
  --grade-mistake:   #e67e22;
  --grade-blunder:   #c0392b;

  /* ---- 소셜 브랜드 ---- */
  --naver:           #03c75a;
  --kakao:           #fee500;
  --google:          #ffffff;

  /* ---- 그림자 (elevation) ---- */
  --shadow-1: 0 1px 2px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.03);
  --shadow-2: 0 4px 14px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-3: 0 12px 32px rgba(0,0,0,.14), 0 4px 8px rgba(0,0,0,.06);
  --shadow-card-hover: 0 8px 20px rgba(0,0,0,.10);

  /* ---- Spacing scale ---- */
  --gap-xs:  4px;
  --gap-sm:  8px;
  --gap-md: 12px;
  --gap-lg: 20px;
  --gap-xl: 24px;
  --gap-2xl: 36px;

  /* ---- Radius ---- */
  --radius-xs:  4px;
  --radius-sm:  8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-pill: 999px;

  /* ---- Typography ---- */
  --font: -apple-system,BlinkMacSystemFont,"SF Pro Text","Apple SD Gothic Neo","Pretendard","Noto Sans KR","Malgun Gothic",system-ui,sans-serif;
  --font-mono: ui-monospace,SFMono-Regular,Menlo,Monaco,"Courier New",monospace;
  --fs-xs:  12px;
  --fs-sm:  13px;
  --fs-md:  14px;
  --fs-base:15px;
  --fs-lg:  16px;
  --fs-xl:  19px;
  --fs-2xl: 22px;
  --fs-3xl: 30px;
  --lh-tight: 1.25;
  --lh-base:  1.5;
  --lh-loose: 1.7;
  --fw-medium: 500;
  --fw-semi:   600;
  --fw-bold:   700;

  /* ---- Layout ---- */
  --container-narrow: 420px;
  --container-medium: 600px;
  --container-wide:  1080px;

  --tap: 44px;            /* Apple HIG 최소 터치 영역 */
  --header-h: 56px;       /* 모바일 헤더 높이 */

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);

  /* ---- Motion ---- */
  --t-fast: 120ms;
  --t-med:  200ms;
  --t-slow: 320ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in:  cubic-bezier(0.4, 0, 1, 1);

  /* ---- Breakpoints (JS 참조용) ---- */
  --bp-mobile: 480px;
  --bp-tablet: 1024px;
}

/* ============================================================
   2) Dark theme tokens
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) {
    --bg:              #0f1115;
    --bg-elev:         #14171d;
    --surface:         #1a1e26;
    --surface-subtle:  #15181f;
    --code-bg:         #20242d;
    --hover-bg:        #232833;
    --press-bg:        #2c323e;

    --text:            #f1f1f3;
    --text-soft:       #c7c8cd;
    --text-muted:      #9499a3;
    --text-faint:      #6c7280;
    --text-on-accent:  #ffffff;

    --border:          #2a3040;
    --border-strong:   #3a4156;
    --border-faint:    #232836;

    --accent:          #d6ae5b;
    --accent-soft:     #b88c3a;
    --accent-bg:       #4a3a18;
    --accent-bg-hover: #5a4720;
    --link:            #6cb6ff;
    --success:         #58c97a;
    --warning:         #f1c25a;
    --danger:          #ee5d4c;
    --info:            #5aa8f4;

    --focus-ring:      0 0 0 3px rgba(214, 174, 91, 0.5);

    --shadow-1: 0 1px 2px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.03);
    --shadow-2: 0 4px 14px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.35);
    --shadow-3: 0 12px 32px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.4);
    --shadow-card-hover: 0 8px 20px rgba(0,0,0,.55);
  }
}
body.theme-dark, :root.theme-dark {
  --bg:              #0f1115;
  --bg-elev:         #14171d;
  --surface:         #1a1e26;
  --surface-subtle:  #15181f;
  --code-bg:         #20242d;
  --hover-bg:        #232833;
  --press-bg:        #2c323e;
  --text:            #f1f1f3;
  --text-soft:       #c7c8cd;
  --text-muted:      #9499a3;
  --text-faint:      #6c7280;
  --text-on-accent:  #ffffff;
  --border:          #2a3040;
  --border-strong:   #3a4156;
  --border-faint:    #232836;
  --accent:          #d6ae5b;
  --accent-bg:       #4a3a18;
  --accent-bg-hover: #5a4720;
  --link:            #6cb6ff;
  --shadow-1: 0 1px 2px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.03);
  --shadow-2: 0 4px 14px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.35);
  --shadow-3: 0 12px 32px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.4);
}

/* ============================================================
   3) Base reset / body
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: var(--lh-base);
  -webkit-text-size-adjust: 100%;
  font-feature-settings: "cv11" 1, "ss01" 1;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
img, svg { max-width: 100%; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-bg); color: var(--text-on-accent); }

/* 키보드 사용자에게만 포커스 링 노출 */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ============================================================
   4) Modern App Bar (헤더)
   ============================================================ */
.appbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--gap-md);
  padding: calc(var(--safe-top) + 10px) var(--gap-xl) 10px;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.appbar h1 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semi);
  letter-spacing: -0.01em;
}
.appbar .appbar-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.appbar-actions {
  display: flex; align-items: center; gap: var(--gap-sm); flex-wrap: nowrap;
}
.appbar-link {
  font-size: var(--fs-sm);
  color: var(--text-soft);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.appbar-link:hover { background: var(--hover-bg); text-decoration: none; }

/* legacy header 폴백 (인라인 header 그대로 쓰는 페이지) */
header:not(.appbar) {
  padding: 14px var(--gap-xl) 14px calc(var(--gap-xl) + var(--safe-left));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
header:not(.appbar) h1 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semi);
  letter-spacing: -0.01em;
}

/* ============================================================
   5) Buttons (모던 컴포넌트)
   ============================================================ */
button, .btn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  min-height: var(--tap);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out);
  user-select: none;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--hover-bg); }
button:active, .btn:active { background: var(--press-bg); transform: scale(0.98); }
button:disabled, .btn:disabled, button[disabled] {
  opacity: 0.45; cursor: not-allowed; pointer-events: none;
}

.btn-primary, button.btn-primary, button.active {
  background: var(--accent-bg);
  color: var(--text-on-accent);
  border-color: var(--accent);
  font-weight: var(--fw-semi);
  box-shadow: var(--shadow-1);
}
.btn-primary:hover, button.btn-primary:hover, button.active:hover {
  background: var(--accent-bg-hover);
}

.btn-solid {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
  font-weight: var(--fw-semi);
  box-shadow: var(--shadow-2);
}
.btn-solid:hover { background: var(--accent-soft); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
}
.btn-ghost:hover { background: var(--hover-bg); }

.btn-danger {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border-strong));
  color: var(--danger);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: var(--fs-sm); }
.btn-icon {
  min-height: var(--tap); min-width: var(--tap);
  padding: 0; border-radius: var(--radius-md);
}
.btn-block { width: 100%; }
.btn-pill { border-radius: var(--radius-pill); }

/* ============================================================
   6) Chips & Segmented control (옵션 선택 트렌드)
   ============================================================ */
.chip-group { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  color: var(--text-soft);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-out);
}
.chip:hover { background: var(--hover-bg); }
.chip.active, .chip[aria-pressed="true"] {
  background: var(--accent-bg);
  color: var(--text-on-accent);
  border-color: var(--accent);
  font-weight: var(--fw-semi);
}

.segmented {
  display: inline-flex;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.segmented > button, .segmented > .seg {
  border: none; background: transparent;
  padding: 8px 14px; min-height: 38px;
  font-size: var(--fs-sm);
  border-radius: calc(var(--radius-md) - 4px);
  color: var(--text-soft);
  font-weight: var(--fw-medium);
}
.segmented > button.active, .segmented > .seg.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
  font-weight: var(--fw-semi);
}

/* ============================================================
   7) Inputs / Selects / Textarea
   ============================================================ */
input, select, textarea {
  font: inherit;
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  min-height: var(--tap);
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  outline: none;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

/* 커스텀 select 화살표 */
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23777' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
:root.theme-dark select,
body.theme-dark select,
@media (prefers-color-scheme: dark) { :root:not(.theme-light) select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23bbb' d='M6 8L0 0h12z'/></svg>");
} }

textarea { min-height: 96px; resize: vertical; line-height: var(--lh-base); }

/* checkbox 컨테이너용 */
.checkbox {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--fs-sm); color: var(--text-soft);
  cursor: pointer; min-height: var(--tap);
}
.checkbox input[type="checkbox"] {
  width: 20px; height: 20px;
  min-height: auto; padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* form-row: label + control */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field-label { font-size: var(--fs-sm); color: var(--text-soft); font-weight: var(--fw-medium); }
.field-hint { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 2px; }

/* ============================================================
   8) Card / Surface
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg);
  margin-bottom: var(--gap-md);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--t-med) var(--ease-out);
}
.card-tight { padding: var(--gap-md); }
.card .t {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--gap-sm);
  font-weight: var(--fw-medium);
  letter-spacing: 0.01em;
}
.surface { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); }

/* ============================================================
   9) Layout (반응형)
   기본: 좌(보드) + 우(패널) 2열
   모바일: 1열 (보드 위 → 패널 아래)
   모바일 가로(landscape): 보드 좌측 + 패널 우측, 패널은 스크롤 가능
   ============================================================ */
.layout {
  display: flex;
  gap: var(--gap-lg);
  flex-wrap: wrap;
  padding: var(--gap-xl);
  align-items: flex-start;
  max-width: var(--container-wide);
  margin: 0 auto;
}
.layout .left {
  flex: 1 1 360px;
  min-width: 0;
  max-width: var(--container-medium);
}
.layout .panel {
  width: 280px;
  flex-shrink: 0;
}

.wrap { max-width: var(--container-medium); margin: 24px auto; padding: 0 16px; }
.wrap-narrow { max-width: var(--container-narrow); margin: 32px auto; padding: 0 16px; }

/* ============================================================
   10) Board wrapper — 나무결 + 자연 음영
   ============================================================ */
.boardwrap {
  position: relative;
  background:
    url('/images/wood-board.svg') center / cover no-repeat,
    radial-gradient(ellipse at 50% 35%, #ffe7b8 0%, #f3d089 55%, #d6a868 100%) !important;
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid #c9a468;
  box-shadow:
    inset 0 -8px 14px rgba(120,80,30,0.14),
    inset 0  2px  6px rgba(255,255,255,0.30),
    0 6px 16px rgba(0,0,0,0.18);
}

/* 반상 우상단 확대/축소 토글(문제 영역 확대) — 국지 문제에서만 노출 */
.boardwrap .zoom-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  min-height: 32px;
  font-size: 12px;
  font-weight: 600;
  color: #3a2a14;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(120, 80, 30, 0.35);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.14);
  transition: background 0.15s ease, transform 0.05s ease;
}
.boardwrap .zoom-toggle:hover { background: #fff; }
.boardwrap .zoom-toggle:active { transform: translateY(1px); }
.boardwrap .zoom-toggle[hidden] { display: none; }
.boardwrap .zoom-toggle .zoom-ico { font-size: 14px; line-height: 1; }
@media (max-width: 720px) {
  .boardwrap .zoom-toggle { top: 6px; right: 6px; padding: 5px 8px; font-size: 11px; }
  .boardwrap .zoom-toggle .zoom-label { display: none; }
}

/* ============================================================
   11) 반응형 — 모바일 / 태블릿 / 가로 / 세로
   ============================================================ */

/* 태블릿 세로 (≤1024) — 패널 폭 축소 */
@media (max-width: 1024px) {
  .layout { padding: 16px; gap: 16px; }
  .layout .panel { width: 240px; }
}

/* 모바일 세로 (≤720) — 1열 세로 스택 */
@media (max-width: 720px) {
  .layout { flex-direction: column; padding: 12px; gap: 12px; }
  .layout .left,
  .layout > .left { max-width: 100%; min-width: 0; width: 100%; }
  .panel, .layout .panel { width: 100%; flex-shrink: 1; }

  .wrap, .wrap-narrow { padding: 0 14px; margin: 16px auto; }
  .appbar, header:not(.appbar) { padding: calc(var(--safe-top) + 10px) 14px 10px; }

  /* iOS Safari 자동 줌 방지 */
  input, select, textarea { font-size: 16px; }

  .card { padding: 14px; border-radius: var(--radius-md); }
  .boardwrap { padding: 10px; }
}

/* 모바일 가로 (landscape, max-height ≤ 500px) — 보드 우선 2열
   바둑판이 반드시 보이도록 보드 영역을 화면 높이에 맞추고 패널은 사이드 스크롤 */
@media (max-height: 500px) and (orientation: landscape) {
  body.board-first { overflow: hidden; }
  body.board-first .appbar,
  body.board-first header:not(.appbar) {
    padding: 6px 12px; min-height: 42px;
  }
  body.board-first .appbar h1,
  body.board-first header:not(.appbar) h1 { font-size: var(--fs-md); }
  body.board-first .appbar-sub { display: none; }
  body.board-first .layout {
    flex-direction: row !important;
    flex-wrap: nowrap;
    padding: 8px;
    gap: 10px;
    height: calc(100dvh - 50px);
    overflow: hidden;
    align-items: stretch;
  }
  body.board-first .layout .left {
    flex: 0 0 auto;
    max-width: none;
    width: auto;
    display: flex; flex-direction: column;
    height: 100%;
  }
  body.board-first .layout .left .boardwrap {
    height: 100%;
    aspect-ratio: 1 / 1;
    padding: 6px;
  }
  body.board-first .layout .left .boardwrap svg { height: 100%; width: 100%; }
  body.board-first .layout .panel {
    flex: 1 1 auto;
    width: auto;
    max-width: none;
    height: 100%;
    overflow-y: auto;
    padding-right: 4px;
  }
  body.board-first .card { padding: 10px; margin-bottom: 8px; }
  body.board-first .controls-bar,
  body.board-first .controls { gap: 6px; }
  body.board-first button, body.board-first .btn { min-height: 38px; padding: 6px 10px; font-size: var(--fs-sm); }
}

/* 작은 모바일 (≤380) — 헤더/카드 더 컴팩트 */
@media (max-width: 380px) {
  .appbar h1, header:not(.appbar) h1 { font-size: var(--fs-md); }
  .card { padding: 12px; }
  button, .btn { padding: 8px 12px; font-size: var(--fs-sm); }
}

/* ============================================================
   12) Toolbar (보드 상단 컨트롤바)
   ============================================================ */
.controls-bar {
  display: flex; flex-wrap: wrap;
  gap: var(--gap-sm);
  align-items: center;
  margin-bottom: var(--gap-md);
  padding: var(--gap-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.controls-bar .label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}

/* ============================================================
   13) Pills / Badge / Dot
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; font-size: var(--fs-xs);
  background: var(--surface-subtle); color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.badge-success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); border-color: transparent; }
.badge-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: transparent; }
.dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }

/* ============================================================
   14) 접근성 — 큰 글씨 모드
   ============================================================ */
body.a11y-large {
  --fs-xs:  14px; --fs-sm:  16px; --fs-md:  17px;
  --fs-base:18px; --fs-lg:  20px; --fs-xl:  24px;
  --fs-2xl: 28px; --fs-3xl: 38px;
  --gap-sm: 10px; --gap-md: 16px; --gap-lg: 24px; --gap-xl: 32px;
  --radius-md: 14px; --radius-lg: 18px;
  --tap: 52px;
}
body.a11y-large .boardwrap { padding: 22px; }

/* 모션 줄임 선호 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   15) 마지막 착수 펄스 + 힌트 마커 (board-fx.js)
   ============================================================ */
@keyframes bd-pulse-anim {
  0%   { stroke-opacity: 0.9; r: var(--bd-pulse-r0, 6); stroke-width: 3; }
  100% { stroke-opacity: 0.0; r: var(--bd-pulse-r1, 22); stroke-width: 1; }
}
.bd-pulse { animation: bd-pulse-anim 1.2s ease-out forwards; pointer-events: none; }

.bd-hint-marker { pointer-events: none; }
@keyframes bd-hint-blink { 0%,100% { opacity: 0.95; } 50% { opacity: 0.45; } }
.bd-hint-marker { animation: bd-hint-blink 1.6s ease-in-out infinite; }

/* ============================================================
   16) 로딩 오버레이
   ============================================================ */
.bd-loading-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 18, 12, 0.40);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease-out;
}
.bd-loading-overlay.bd-on { opacity: 1; pointer-events: auto; }
.bd-loading-card {
  min-width: 280px; max-width: 80vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px 24px;
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  transform: scale(0.96);
  transition: transform 0.15s ease-out;
}
.bd-loading-overlay.bd-on .bd-loading-card { transform: scale(1); }
.bd-loading-spinner { width: 42px; height: 42px; position: relative; }
.bd-loading-spinner::before, .bd-loading-spinner::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid transparent;
}
.bd-loading-spinner::before {
  border-top-color: var(--accent); border-right-color: var(--accent);
  animation: bd-spin 0.9s cubic-bezier(0.4, 0.0, 0.6, 1) infinite;
}
.bd-loading-spinner::after {
  border-bottom-color: rgba(184, 140, 58, 0.25);
  border-left-color: rgba(184, 140, 58, 0.25);
  animation: bd-spin 1.4s cubic-bezier(0.4, 0.0, 0.6, 1) infinite reverse;
}
@keyframes bd-spin { to { transform: rotate(360deg); } }
.bd-loading-msg { font-size: var(--fs-md); color: var(--text); text-align: center; font-weight: 500; min-height: 20px; }
.bd-loading-sub { font-size: var(--fs-xs); color: var(--text-faint); text-align: center; margin-top: -8px; }
.bd-loading-bar { width: 100%; height: 6px; background: var(--border-faint); border-radius: 3px; overflow: hidden; position: relative; }
.bd-loading-bar::before {
  content: ""; position: absolute; inset: 0; width: 40%;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  animation: bd-bar-flow 1.4s cubic-bezier(0.4, 0.0, 0.2, 1) infinite;
}
@keyframes bd-bar-flow { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
/* 결정형 진행률 바: ::before 애니메이션 대신 fill 요소가 실제 진행률을 표시 */
.bd-loading-bar-fill { position: absolute; top: 0; left: 0; bottom: 0; width: 0%; background: var(--accent); border-radius: 3px; transition: width 0.28s cubic-bezier(0.22, 0.61, 0.36, 1); display: none; }
.bd-loading-bar.bd-determinate::before { display: none; }
.bd-loading-bar.bd-determinate .bd-loading-bar-fill { display: block; }
.bd-loading-pct { font-size: var(--fs-xs); color: var(--text-faint); text-align: center; margin-top: -4px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.bd-loading-cancel {
  margin-top: 6px; padding: 8px 18px; min-height: 36px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle); color: var(--text);
  border: 1px solid var(--border);
  font-size: var(--fs-sm); font-weight: var(--fw-semi);
  cursor: pointer; transition: background 0.12s ease, border-color 0.12s ease;
}
.bd-loading-cancel:hover { background: var(--hover-bg); border-color: var(--danger); color: var(--danger); }
.bd-loading-cancel:active { transform: translateY(1px); }
@media (max-width: 720px) { .bd-loading-card { min-width: 240px; padding: 22px 24px 18px; } }

/* ============================================================
   17) Bottom sheet (모바일 패널 풀업) — 선택 사용
   ============================================================ */
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  padding: 12px 16px calc(16px + var(--safe-bottom));
  z-index: 60;
  transform: translateY(100%);
  transition: transform var(--t-med) var(--ease-out);
}
.bottom-sheet.open { transform: translateY(0); }
.bottom-sheet::before {
  content: ""; display: block; width: 38px; height: 4px;
  border-radius: 999px; background: var(--border-strong);
  margin: 4px auto 10px;
}

/* ============================================================
   18) Utility
   ============================================================ */
.muted { color: var(--text-muted); }
.note { font-size: var(--fs-xs); color: var(--text-faint); line-height: var(--lh-base); }
/* 상태 컬러 토큰 — 각 페이지 인라인 중복 제거용 (login/import/problems/problems-admin) */
.ok { color: var(--success); }
.err { color: var(--danger); }
.ng { color: var(--danger); }
.go { color: var(--link); }
.msg { font-size: var(--fs-sm); margin-top: var(--gap-md); min-height: 18px; }
/* SGF/파일 업로드 공통 dropzone (import/problems-admin) */
input[type="file"] {
  font-family: var(--font);
  padding: 10px;
  background: var(--surface-subtle);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  font-size: var(--fs-sm);
  color: var(--text-soft);
}
input[type="file"]:hover { border-color: var(--accent); background: var(--hover-bg); }
input[type="file"]:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.row { display: flex; align-items: center; gap: var(--gap-sm); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-sm); }
.stack { display: flex; flex-direction: column; gap: var(--gap-sm); }
.spacer { flex: 1; }
.hide-mobile { } .hide-desktop { display: none; }
@media (max-width: 720px) {
  .hide-mobile { display: none !important; }
  .hide-desktop { display: initial; }
}

/* ============================================================
   19) Mobile-app polish — 모든 페이지 공통 (네이티브 앱 같은 UX)
   ------------------------------------------------------------
   - iOS 입력 시 자동 줌 방지 (font-size 16px+)
   - 탭 하이라이트 / 콜아웃 제거
   - 오버스크롤 차단(SPA처럼 동작)
   - 가로 스와이프 스크롤 차단
   - safe-area 전역 적용
   - 스티키 앱바 + 바텀 패딩(키패드/홈인디케이터 대응)
   ============================================================ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  overscroll-behavior-y: contain;
  overflow-x: hidden;
  padding-left: var(--safe-left, env(safe-area-inset-left, 0px));
  padding-right: var(--safe-right, env(safe-area-inset-right, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
/* 본문은 사용자 선택 허용, 인터랙티브 요소는 선택 비허용(네이티브 앱 느낌) */
.btn, .chip, .segmented > *, .appbar, .controls-bar, .bd-menu, .bottom-sheet::before {
  -webkit-user-select: none; user-select: none;
}

/* iOS 입력 자동 줌 방지 — 모바일에서만 16px 보장 */
@media (max-width: 720px) {
  .input, .select, input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="search"], input[type="tel"], input[type="url"],
  textarea, select {
    font-size: 16px !important;
  }
}

/* 스티키 앱바 — 모바일/태블릿에서 상단 고정, safe-area 대응 */
@media (max-width: 1024px) {
  .appbar {
    position: sticky; top: 0; z-index: 50;
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
    backdrop-filter: saturate(140%) blur(10px);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
    border-bottom: 1px solid var(--border);
  }
}

/* 카드 액티브 피드백 — 터치 시 살짝 눌리는 느낌 */
@media (hover: none) {
  .btn:active, .chip:active, .start-card:active, .card:active {
    transform: scale(0.985); transition: transform .08s ease;
  }
}

/* 모바일에서 라벨/툴팁의 가독성 강화 */
@media (max-width: 720px) {
  body { font-size: 15px; line-height: 1.5; }
  h1 { font-size: var(--fs-xl); }
  h2 { font-size: var(--fs-lg); }
  .chip { min-height: 36px; padding: 6px 12px; }
  .btn { min-height: 44px; }
  .controls-bar { gap: 6px; flex-wrap: wrap; }
}

/* 태블릿/모바일 가로에서 헤더 컴팩트화 */
@media (orientation: landscape) and (max-height: 500px) {
  .appbar { padding-top: env(safe-area-inset-top, 0px); padding-bottom: 4px; }
  .appbar h1 { font-size: var(--fs-md); }
  .appbar-sub { display: none; }
}

/* 폼 일반 — 모든 페이지의 input 그룹이 같은 룩앤필 갖도록 */
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--gap-md); }
.form-row > label { font-size: var(--fs-sm); color: var(--text-soft); font-weight: var(--fw-semi); }
.form-row .input, .form-row .select { width: 100%; }

/* 페이지 컨테이너 — 콘텐츠 폭을 일관되게 */
.page {
  max-width: 1100px; margin: 0 auto;
  padding: var(--gap-lg) var(--gap-md) calc(var(--gap-xl) + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 1280px) {
  .page { max-width: 1280px; padding: var(--gap-xl) var(--gap-lg) var(--gap-xl); }
}

/* 다크 모드에서도 토큰 변수로 자동 처리됨 (별도 오버라이드 불필요) */
