:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1c2230;
  --muted: #667085;
  --accent: #3b5bdb;
  --accent-hover: #2f4ac0;
  --accent-soft: #e8edff;
  --ok: #138a4b;
  --ok-soft: #e3f5ea;
  --bad: #c92a2a;
  --bad-soft: #fde8e8;
  --warn: #b26b00;
  --warn-soft: #fff3db;
  --code-bg: #f4f5f8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: "JetBrains Mono", "D2Coding", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1e232d;
    --border: #2a303c;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --accent: #6d8bff;
    --accent-hover: #8aa2ff;
    --accent-soft: #1f2a4d;
    --ok: #4cc38a;
    --ok-soft: #12301f;
    --bad: #ff6b6b;
    --bad-soft: #3a1a1a;
    --warn: #f0b450;
    --warn-soft: #3a2c12;
    --code-bg: #12161d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }

/* ---------- 상단 바 ---------- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; }

/* ---------- 공통 요소 ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 32px 20px 64px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn kbd { font-family: var(--mono); font-size: 11px; opacity: .75; }

input[type=text], input[type=password], textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; }

.muted { color: var(--muted); }
.error-text { color: var(--bad); font-size: 14px; min-height: 1.4em; }
.hidden { display: none !important; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- 로그인 ---------- */
.login-wrap { min-height: calc(100vh - 56px); display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; height: 40px; }

/* ---------- 문제 목록 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; }
.progress { font-size: 14px; color: var(--muted); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.link { cursor: pointer; }
.table tbody tr.link:hover td { background: var(--surface-2); }
.table .num { width: 56px; color: var(--muted); }
.table .status { width: 120px; }
.tags { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-left: 8px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- 문제 풀이 화면 ---------- */
.solve {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(320px, 42%) 1fr;
}
.pane-left {
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 24px 28px 48px;
}
.pane-left h1 { font-size: 21px; margin: 0 0 8px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.markdown h2 { font-size: 16px; margin: 26px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 15px; margin: 20px 0 6px; }
.markdown p, .markdown li { font-size: 15px; }
.markdown code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.markdown pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow: auto; border: 1px solid var(--border); }
.markdown pre code { background: none; padding: 0; }
.markdown table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 12px; }
.markdown th { background: var(--surface-2); }
.markdown img { max-width: 100%; }

.pane-right { display: grid; grid-template-rows: auto 1fr auto minmax(180px, 34%); min-height: 0; min-width: 0; }
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .spacer { flex: 1; }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
#line-badge { white-space: nowrap; }
.editor-wrap { min-height: 0; position: relative; }
.editor-wrap .CodeMirror { position: absolute; inset: 0; height: auto; font-family: var(--mono); font-size: 14px; line-height: 1.55; }

.tabs { display: flex; gap: 2px; padding: 0 8px; background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.tab {
  padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer; font-family: inherit;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { overflow: auto; padding: 14px 16px; background: var(--bg); min-height: 0; }

.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.result-head .big { font-size: 17px; font-weight: 700; }
.big.ok { color: var(--ok); }
.big.bad { color: var(--bad); }
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 8px; margin-bottom: 14px; }
.case-chip { padding: 8px 10px; border-radius: 8px; font-size: 13px; background: var(--surface); border: 1px solid var(--border); }
.case-chip.ok { border-color: var(--ok); }
.case-chip.bad { border-color: var(--bad); }
.case-chip .t { font-size: 11px; color: var(--muted); }
.case-detail { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.case-detail h4 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 72px 1fr; gap: 4px 10px; font-size: 13px; }
.kv .k { color: var(--muted); }
pre.out {
  margin: 0; padding: 8px 10px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto;
}
pre.out.err { color: var(--bad); }
.stdin-box { margin-bottom: 12px; }
.stdin-box textarea { min-height: 64px; }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 관리자 ---------- */
.admin-grid { display: grid; gap: 20px; }
.admin-grid > * { min-width: 0; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 16px; }
.section-title .spacer { flex: 1; }
.scroll-x { overflow-x: auto; }
.matrix td, .matrix th { white-space: nowrap; text-align: center; padding: 8px 10px; font-size: 13px; }
.matrix td:first-child, .matrix th:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.matrix th:first-child { background: var(--surface-2); }
.cell { display: inline-block; min-width: 44px; padding: 2px 6px; border-radius: 6px; cursor: pointer; }
.cell.ok { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
.cell.part { background: var(--warn-soft); color: var(--warn); }
.cell.none { color: var(--muted); cursor: default; }
.validate-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.validate-list li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: min(900px, 100%); max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 16px 18px; overflow: auto; }

/* ---------- 반응형 ---------- */
@media (max-width: 860px) {
  .solve { grid-template-columns: 1fr; height: auto; }
  .pane-left { border-right: 0; border-bottom: 1px solid var(--border); max-height: none; }
  .pane-right { grid-template-rows: auto 60vh auto auto; }
  .tab-body { max-height: 60vh; }
  .table .hide-sm { display: none; }
}
.topbar > * { white-space: nowrap; }
@media (max-width: 560px) {
  .topbar { gap: 10px; padding: 0 16px; }
  .topbar .who { display: none; }
}

/* ---------- 급수 ---------- */
.grade-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.grade-card { display: block; padding: 22px; color: var(--text); transition: border-color .15s, transform .15s; }
.grade-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.grade-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.grade-desc { font-size: 14px; min-height: 1.6em; margin-bottom: 16px; }
.grade-progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 6px; }
.grade-progress > div { height: 100%; background: var(--ok); }
.grade-tabs { display: flex; gap: 8px; flex-wrap: wrap; }

/* '한 줄 수정' 문제에서 시작 코드와 달라진 줄 */
.cm-changed-line { background: var(--warn-soft); }
.toolbar { flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 1280px) { .toolbar .btn kbd { display: none; } }
