:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e2230; --border: #2a2f3d;
  --fg: #e6e8ee; --muted: #8b93a7; --accent: #4f8cff; --ok: #3ccf7a; --bad: #ff5c6c; --warn: #f5b942;
  --lv0: #6cc0ff; --lv1: #58d68d; --lv2: #f7b955; --lv3: #ff7b9c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Noto Sans KR", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; border: 1px solid var(--border); background: var(--panel2); color: var(--fg); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.danger { border-color: var(--bad); color: var(--bad); }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.spacer { flex: 1; }
code, pre { font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 48px; border-bottom: 1px solid var(--border); background: var(--panel); }
.brand { font-weight: 700; color: var(--fg); }
.tabs a { color: var(--muted); padding: 14px 10px; display: inline-block; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--fg); border-bottom-color: var(--accent); }
#userbox { display: flex; align-items: center; gap: 8px; }
#userbox img { width: 24px; height: 24px; border-radius: 50%; }

main { flex: 1; min-height: 0; overflow: auto; }
.page { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* 일차 목록 */
.notice { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; }
.daygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.daycard { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: block; color: var(--fg); }
.daycard:hover { border-color: var(--accent); }
.daycard.locked { opacity: .45; pointer-events: none; }
.daycard .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.daycard .num { font-weight: 700; font-size: 16px; }
.lvrow { display: flex; gap: 6px; }
.pill { flex: 1; text-align: center; font-size: 12px; padding: 3px 0; border-radius: 4px; background: var(--panel2); border: 1px solid var(--border); }
.pill.merged { background: color-mix(in srgb, var(--ok) 25%, transparent); border-color: var(--ok); }
.pill.submitted { background: color-mix(in srgb, var(--warn) 25%, transparent); border-color: var(--warn); }
.pill.draft { border-style: dashed; }
.legend { margin-top: 14px; font-size: 12px; }
.legend .pill { display: inline-block; flex: none; padding: 2px 8px; margin-right: 4px; }

/* 문제 화면 */
.problem { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.problem-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.problem-bar .lvtabs a { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); margin-right: 4px; font-size: 13px; }
.problem-bar .lvtabs a.active { color: var(--fg); border-color: var(--accent); background: var(--panel2); }
.problem-bar .lvtabs a .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 5px; background: var(--border); vertical-align: middle; }
.dot.merged { background: var(--ok) !important; } .dot.submitted { background: var(--warn) !important; } .dot.draft { background: var(--muted) !important; }
.split { display: grid; grid-template-columns: minmax(360px, 42%) 1fr; min-height: 0; }
.left { border-right: 1px solid var(--border); overflow: auto; min-height: 0; display: flex; flex-direction: column; }
.subtabs { display: flex; border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 1; }
.subtabs button { border: 0; border-radius: 0; background: transparent; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid transparent; }
.subtabs button.active { color: var(--fg); border-bottom-color: var(--accent); }
.md { padding: 16px 20px; line-height: 1.6; }
.md h1 { font-size: 20px; margin-top: 0; } .md h2 { font-size: 16px; margin-top: 24px; } .md h3 { font-size: 14px; }
.md table { border-collapse: collapse; margin: 8px 0; } .md th, .md td { border: 1px solid var(--border); padding: 4px 10px; }
.md pre { background: var(--panel2); padding: 10px; border-radius: 6px; overflow: auto; }
.md code { background: var(--panel2); padding: 1px 4px; border-radius: 3px; }
.md pre code { background: none; padding: 0; }
.right { display: grid; grid-template-rows: 1fr auto; min-height: 0; }
.editor-wrap { position: relative; min-height: 0; }
#editor { position: absolute; inset: 0; }
.editor-tools { position: absolute; top: 6px; right: 20px; z-index: 2; display: flex; gap: 6px; }
.editor-tools button { font-size: 12px; padding: 3px 8px; opacity: .8; }
.result { border-top: 1px solid var(--border); background: var(--panel); height: 260px; display: flex; flex-direction: column; min-height: 0; resize: vertical; overflow: hidden; }
.result-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.result-body { overflow: auto; padding: 10px 14px; flex: 1; font-size: 13px; }
.case { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; }
.case .mark { width: 16px; text-align: center; }
.case .name { width: 90px; color: var(--muted); }
.case .time { width: 110px; color: var(--muted); font-variant-numeric: tabular-nums; }
.case.pass .mark { color: var(--ok); } .case.fail .mark { color: var(--bad); }
.case-detail { margin: 2px 0 8px 26px; padding: 8px 10px; background: var(--panel2); border-radius: 6px; white-space: pre-wrap; word-break: break-all; font-family: Menlo, Consolas, monospace; font-size: 12px; color: #d7dbe6; }
.summary { font-weight: 600; } .summary.pass { color: var(--ok); } .summary.fail { color: var(--bad); }
.prbox { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--ok); border-radius: 6px; background: color-mix(in srgb, var(--ok) 12%, transparent); }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted); border-top-color: var(--fg); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 풀이 보기 */
.solvers { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.solvers button.active { border-color: var(--accent); background: var(--panel2); }
.codeview { padding: 12px 16px; overflow: auto; }
.codeview pre { margin: 0; line-height: 1.5; white-space: pre; }

/* 출석표 */
.att-table { border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.att-table th, .att-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: center; }
.att-table th { background: var(--panel); position: sticky; top: 0; }
.att-table td:first-child, .att-table th:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); }
.att-table .n4 { background: color-mix(in srgb, var(--ok) 35%, transparent); }
.att-table .n1, .att-table .n2, .att-table .n3 { background: color-mix(in srgb, var(--ok) 15%, transparent); }
.att-table .n0 { color: var(--muted); }
.att-table .me { outline: 1px solid var(--accent); }
.att-wrap { overflow: auto; max-height: calc(100vh - 160px); border: 1px solid var(--border); border-radius: 8px; }

/* 로그인 */
dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; padding: 20px 24px; min-width: 360px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.usercode { font-size: 32px; letter-spacing: 4px; font-weight: 700; text-align: center; padding: 12px; background: var(--panel2); border-radius: 8px; margin: 12px 0; font-family: Menlo, Consolas, monospace; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 80vw; }
.toast.bad { border-color: var(--bad); }
.toast.ok { border-color: var(--ok); }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; grid-template-rows: 40vh 1fr; }
  .left { border-right: 0; border-bottom: 1px solid var(--border); }
}
