/* ==========================================================================
   p-bit 풀이기 스타일
   진교봇 사이트(jingyobot-server의 layout.js)와 같은 색·글꼴·상단 메뉴를 사용
   라이트/다크는 기기 시스템 설정을 따름. 클래스 이름은 app.js가 쓰는 그대로 유지
   ========================================================================== */

:root {
  --bg: #F5F6F8; --tile: #FFFFFF; --tile-alt: #ECEEF2; --fg: #0E1116; --muted: #5A6170; --faint: #8A909B;
  --line: #DEE1E6; --accent: #D9530F; --accent-soft: rgba(217, 83, 15, 0.10);
  --ok: #1E8A5A; --ok-soft: rgba(30, 138, 90, 0.10); --warn: #B7791F; --warn-soft: rgba(183, 121, 31, 0.12);
  --bad: #C2412D; --bad-soft: rgba(194, 65, 45, 0.10); --blue: #2F6FDB; --blue-soft: rgba(47, 111, 219, 0.10);
  --board-line: #0E1116; --chart-bg: #FFFFFF; --chart-grid: #E4E7EB;
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --wrap: 1320px; --cell: 44px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B0C0E; --tile: #15171A; --tile-alt: #1B1E22; --fg: #ECEDEF; --muted: #A2A8B2; --faint: #737A85;
    --line: #2A2E34; --accent: #FF8A3D; --accent-soft: rgba(255, 138, 61, 0.13);
    --ok: #4CC38A; --ok-soft: rgba(76, 195, 138, 0.13); --warn: #E3B341; --warn-soft: rgba(227, 179, 65, 0.13);
    --bad: #FF6B57; --bad-soft: rgba(255, 107, 87, 0.13); --blue: #6EA2FF; --blue-soft: rgba(110, 162, 255, 0.13);
    --board-line: #A2A8B2; --chart-bg: #101215; --chart-grid: #2A2E34; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B0C0E; --tile: #15171A; --tile-alt: #1B1E22; --fg: #ECEDEF; --muted: #A2A8B2; --faint: #737A85;
  --line: #2A2E34; --accent: #FF8A3D; --accent-soft: rgba(255, 138, 61, 0.13);
  --ok: #4CC38A; --ok-soft: rgba(76, 195, 138, 0.13); --warn: #E3B341; --warn-soft: rgba(227, 179, 65, 0.13);
  --bad: #FF6B57; --bad-soft: rgba(255, 107, 87, 0.13); --blue: #6EA2FF; --blue-soft: rgba(110, 162, 255, 0.13);
  --board-line: #A2A8B2; --chart-bg: #101215; --chart-grid: #2A2E34; color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden, [hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap {
  max-width: var(--wrap); margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; color: var(--faint); }

/* ================= 상단 메뉴 (진교봇 사이트와 같음) ================= */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.nav {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.nav .wrap { display: flex; align-items: center; gap: 24px; height: 52px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -0.01em; }
.mark { width: 18px; height: 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.mark i { background: var(--fg); border-radius: 1.5px; opacity: .22; }
.mark i.on { opacity: 1; background: var(--accent); }
.nav-links { display: flex; gap: 22px; font-size: 13px; color: var(--muted); margin-left: auto; }
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--fg); }
.nav-links a[aria-current="page"] { font-weight: 600; }
.nav-admin { font-size: 13px; color: var(--faint); display: inline-flex; align-items: center; gap: 5px; }
.nav-admin:hover { color: var(--fg); }
.nav-admin svg { width: 13px; height: 13px; }
.nav-cta { font-size: 13px; font-weight: 500; padding: 6px 14px; border-radius: 999px; background: var(--fg); color: var(--bg); }
/* 테마 선택 버튼 (자동 → 라이트 → 다크, 동작은 진교봇 서버의 /theme.js) */
.theme-btn { flex: 0 0 auto; width: 30px; height: 30px; margin: 0 -8px; border-radius: 50%; border: 1px solid transparent; background: none; color: var(--faint); display: grid; place-items: center; cursor: pointer; }
.theme-btn:hover { color: var(--fg); border-color: var(--line); }
.theme-btn svg { width: 16px; height: 16px; display: none; }
.theme-btn:not([data-mode]) .i-auto, .theme-btn[data-mode="auto"] .i-auto, .theme-btn[data-mode="light"] .i-light, .theme-btn[data-mode="dark"] .i-dark { display: block; }
@media (max-width: 900px) { .nav-links { display: none; } .nav-admin { margin-left: auto; } }
@media (max-width: 520px) { .nav-admin span { display: none; } }

/* ================= 페이지 머리말과 탭 ================= */
.app-container { padding-bottom: 40px; min-height: calc(100vh - 52px); display: flex; flex-direction: column; }
.app-header { padding-block: 36px 0; display: grid; gap: 18px; }
.header-content { display: grid; gap: 8px; }
.header-content h1 { font-size: clamp(28px, 3.6vw, 40px); font-weight: 700; letter-spacing: -0.025em; line-height: 1.15; text-wrap: balance; }
.header-intro { color: var(--muted); max-width: 72ch; }
.nav-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab-btn {
  background: none; border: 0; padding: 10px 16px; font-size: 15px; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab-btn:hover { color: var(--fg); }
.tab-btn.active { color: var(--fg); border-bottom-color: var(--accent); }

/* ================= 탭 내용 ================= */
.tab-pane { display: none; flex: 1; padding-top: 20px; }
.tab-pane.active { display: block; }
.pane-grid { display: grid; grid-template-columns: 460px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1200px) { .pane-grid { grid-template-columns: minmax(0, 1fr); } }

.card { background: var(--tile); border-radius: 20px; padding: 22px; min-width: 0; }
.card h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 16px; }
.card h3 { font-size: 14px; font-weight: 600; margin: 14px 0 8px; }
.card h4 { font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 10px 6px; }

/* ================= 입력과 버튼 ================= */
.preset-box, .string-input-box, .form-section { margin-bottom: 16px; }
label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.radio-group label, .checkbox-item label { display: inline-flex; align-items: center; gap: 6px; color: var(--fg); font-size: 14px; }
select, input[type="text"], input[type="number"], textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 16px; outline: none; transition: border-color .2s, box-shadow .2s;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
textarea { resize: vertical; font-family: var(--font); line-height: 1.5; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 14px; }

.btn-group { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--tile); color: var(--fg); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: border-color .2s, background .2s, transform .2s;
}
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--accent); }
.btn-primary { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.btn-primary:hover:not(:disabled) { border-color: var(--fg); opacity: .9; }
.btn-secondary { background: var(--tile-alt); border-color: var(--tile-alt); }
.btn-secondary:hover:not(:disabled) { border-color: var(--faint); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn-danger:hover:not(:disabled) { border-color: var(--bad); background: var(--bad-soft); }
.btn-outline { background: transparent; }
.btn-full { width: 100%; }

/* ================= 알림 ================= */
.alert-banner { padding: 10px 14px; border-radius: 12px; font-size: 13.5px; font-weight: 500; margin: 12px 0; }
.alert-banner.info { background: var(--blue-soft); color: var(--blue); }
.alert-banner.success { background: var(--ok-soft); color: var(--ok); }
.alert-banner.warning { background: var(--warn-soft); color: var(--warn); }
.alert-banner.error { background: var(--bad-soft); color: var(--bad); }

/* ================= 고급 설정 ================= */
.advanced-settings { background: var(--bg); border-radius: 14px; padding: 12px 14px; margin: 14px 0; }
.advanced-settings summary { font-weight: 600; font-size: 13.5px; cursor: pointer; }
.settings-content { margin-top: 12px; display: grid; gap: 10px; }
.setting-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; align-items: end; }
.radio-group { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 4px; }
.help-text { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.help-text strong { color: var(--fg); }
.card-footer-tip { font-size: 13px; color: var(--muted); background: var(--bg); padding: 10px 14px; border-radius: 12px; margin-top: 10px; }
.field-guide { font-size: 13px; color: var(--muted); margin: 8px 0; }
.student-count-display, .seat-counter { font-size: 13.5px; color: var(--muted); margin-top: 6px; }
.student-count-display strong, .seat-counter strong { color: var(--fg); font-variant-numeric: tabular-nums; }

/* ================= 스도쿠 판 ================= */
.display-layout { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 1300px) { .display-layout { grid-template-columns: minmax(0, 1fr); } }
.grid-wrapper { min-width: 0; }

.sudoku-grid {
  display: grid; grid-template-columns: repeat(9, var(--cell)); grid-template-rows: repeat(9, var(--cell));
  border: 2px solid var(--board-line); border-radius: 6px; overflow: hidden; background: var(--tile);
  width: fit-content; max-width: 100%; outline: none;
}
.sudoku-grid:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.sudoku-cell {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 19px; font-weight: 500;
  cursor: pointer; user-select: none; transition: background-color .15s; font-variant-numeric: tabular-nums;
}
.sudoku-cell:nth-child(3n) { border-right: 2px solid var(--board-line); }
.sudoku-cell:nth-child(9n) { border-right: none; }
.sudoku-cell.row-box-bottom { border-bottom: 2px solid var(--board-line); }
.sudoku-cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft) !important; }
.cell-clue { color: var(--fg); font-weight: 700; background: var(--tile-alt); }
.cell-blue { color: var(--blue); background: var(--blue-soft); }
.cell-red { color: var(--bad); background: var(--bad-soft); }
.cell-orange { color: var(--accent); background: var(--accent-soft); }
@media (max-width: 520px) { :root { --cell: 30px; } .sudoku-cell { font-size: 15px; } }

.legend-box { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 14px; font-size: 13px; color: var(--muted); width: 0; min-width: 100%; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item strong { color: var(--fg); min-width: 2ch; }
.legend-item strong, .stat-pill strong, .metric-val { font-variant-numeric: tabular-nums; display: inline-block; text-align: right; }
#stat-sweep { min-width: 5ch; }
#stat-beta { min-width: 4ch; }
#stat-viol { min-width: 3ch; }
#stat-time { min-width: 6ch; }
.legend-color { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.color-clue { background: var(--fg); }
.color-blue { background: var(--blue); }
.color-red { background: var(--bad); }
.color-orange { background: var(--accent); }
.spurious-note { font-size: 13px; font-weight: 500; color: var(--accent); background: var(--accent-soft); padding: 8px 12px; border-radius: 10px; margin-top: 10px; }

/* ================= 모니터와 차트 ================= */
.monitor-wrapper { background: var(--bg); border-radius: 16px; padding: 16px; min-width: 0; }
.monitor-wrapper h3 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.stats-ribbon { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.stat-pill { background: var(--tile); border: 1px solid var(--line); padding: 5px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.stat-pill strong { color: var(--fg); font-family: var(--mono); font-weight: 500; }
.canvas-container { background: var(--chart-bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
canvas { width: 100%; height: auto; display: block; }
.result-box { margin-top: 12px; padding: 12px 14px; background: var(--tile); border: 1px solid var(--line); border-radius: 12px; font-size: 13.5px; }
.result-box h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; padding: 0; color: var(--fg); }

/* ================= 자리 배치 ================= */
.blackboard-indicator {
  background: var(--fg); color: var(--bg); text-align: center; font-size: 12px; font-weight: 600;
  padding: 5px; border-radius: 8px; margin-bottom: 12px; letter-spacing: 0.2em;
}
.seat-builder-scroll, .seating-canvas-wrapper { overflow-x: auto; }
.seat-builder { display: grid; gap: 6px; margin: 10px 0; background: var(--bg); padding: 10px; border-radius: 12px; width: fit-content; }
.seat-toggle-cell {
  width: 48px; height: 48px; border-radius: 8px; border: 1px solid var(--line); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 11px; cursor: pointer; user-select: none; font-weight: 600;
  transition: background .15s, border-color .15s;
}
.seat-toggle-cell.active-seat { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.seat-toggle-cell.aisle-seat { background: transparent; border-style: dashed; color: var(--faint); }

.student-table-wrapper { margin-top: 12px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.student-condition-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.student-condition-table th, .student-condition-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.student-condition-table th { background: var(--tile-alt); font-weight: 600; font-size: 12px; color: var(--muted); position: sticky; top: 0; z-index: 1; }
.student-condition-table select, .student-condition-table input { font-size: 14px; padding: 5px 8px; }

/* 자리 배치도는 결과 카드 폭을 다 쓰고, 만족도 분석은 그 아래 (옆에 두면 자리 칸이 좁아져 이름이 줄바꿈됨) */
.display-layout.seating-display { grid-template-columns: minmax(0, 1fr); }
.seating-canvas-wrapper { background: var(--bg); border-radius: 16px; padding: 16px; min-width: 0; }
.seating-board { display: grid; gap: 10px; position: relative; margin-top: 12px; }
.seat-card {
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--tile); min-height: 60px; padding: 8px 4px; min-width: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 3px; position: relative; text-align: center;
}
.seat-card.front-seat { border-color: var(--accent); background: var(--accent-soft); }
.seat-card.virtual-seat { background: transparent; border-style: dashed; }
.seat-card.conflict-seat { border-color: var(--bad); background: var(--bad-soft); }
/* 이름은 한 줄로, 칸보다 길면 말줄임 */
.student-card-name { font-size: 14px; font-weight: 600; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.front-badge-icon { font-size: 10px; line-height: 1.5; background: var(--accent); color: #fff; padding: 0 6px; border-radius: 999px; white-space: nowrap; }
.seating-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 14px; font-size: 12.5px; color: var(--muted); }
.legend-pill { width: 13px; height: 13px; display: inline-block; border-radius: 3px; vertical-align: -1px; }
.pill-front { background: var(--accent-soft); border: 1.5px solid var(--accent); }
.pill-empty { background: transparent; border: 1px dashed var(--faint); }
.legend-line { display: inline-block; width: 18px; height: 3px; vertical-align: middle; border-radius: 2px; }
.line-friend { background: var(--ok); }
.line-avoid { background: var(--bad); }

.satisfaction-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.eval-metric { background: var(--tile); border: 1px solid var(--line); padding: 8px 12px; border-radius: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.metric-label { font-size: 12.5px; color: var(--muted); }
.metric-val { font-size: 15px; font-weight: 600; font-family: var(--mono); }

.random-compare-card { margin-top: 12px; background: var(--tile); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.random-compare-card h4 { font-size: 14px; font-weight: 600; color: var(--fg); padding: 0; margin-bottom: 6px; }
.compare-list { list-style: none; font-size: 13px; margin-bottom: 8px; color: var(--muted); display: grid; gap: 4px; }
.compare-list strong { color: var(--fg); font-variant-numeric: tabular-nums; }
.compare-verdict { font-size: 13px; font-weight: 600; color: var(--ok); background: var(--ok-soft); padding: 6px 10px; border-radius: 8px; }

/* ================= 푸터 ================= */
.app-footer { margin-top: auto; padding-top: 32px; font-size: 12px; color: var(--faint); font-family: var(--mono); display: grid; gap: 4px; }
.privacy-notice { font-family: var(--font); }

@media (max-width: 520px) {
  .card { padding: 16px; border-radius: 16px; }
  .monitor-wrapper, .seating-canvas-wrapper { padding: 12px; }
  .satisfaction-summary { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { .btn, .sudoku-cell, .seat-toggle-cell { transition: none; } }
