* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: #1f2328; background: #f5f6f8;
}
a { color: #0b62d6; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 16px 0 8px; }
pre, code, textarea, .plain-editor { font-family: Consolas, "Cascadia Mono", "DejaVu Sans Mono", "Noto Sans Mono CJK SC", monospace; }
pre { margin: 0; white-space: pre-wrap; word-break: break-all; }

.topbar {
  display: flex; align-items: center; gap: 20px; height: 48px; padding: 0 20px;
  background: #24292f; color: #fff;
}
.topbar a { color: #e6edf3; }
.topbar .brand { font-weight: 700; font-size: 16px; color: #fff; }
.topbar nav { display: flex; gap: 16px; }
.topbar .who { margin-left: auto; color: #c9d1d9; }
.topbar .who a { margin-left: 10px; }

.page { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.card { background: #fff; border: 1px solid #d0d7de; border-radius: 8px; padding: 16px 20px; margin: 16px 0; }
.hint { color: #656d76; font-size: 13px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.title-row h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.scroll-x { overflow-x: auto; }

button, .btn {
  display: inline-block; font: inherit; padding: 5px 14px; border: 1px solid #d0d7de; border-radius: 6px;
  background: #f6f8fa; color: #1f2328; cursor: pointer; line-height: 1.5; white-space: nowrap;
}
button:hover, .btn:hover { background: #eef1f4; text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
button.primary, .btn.primary { background: #1f883d; border-color: #1a7f37; color: #fff; }
button.primary:hover, .btn.primary:hover { background: #1a7f37; }
button.danger { color: #cf222e; }
button.mini { padding: 0 8px; font-size: 12px; }

input, textarea {
  font: inherit; padding: 6px 10px; border: 1px solid #d0d7de; border-radius: 6px; background: #fff; width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid #54aeff; border-color: #54aeff; }
label { display: block; margin: 10px 0; font-weight: 600; }
label input, label textarea { margin-top: 4px; font-weight: 400; }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }
.form .actions { margin-top: 16px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.card.inline-form { margin: 16px 0; }
.inline-form input { width: auto; flex: 1; min-width: 140px; }
.login { max-width: 360px; margin: 60px auto; }
.login button { width: 100%; margin-top: 8px; padding: 8px; }

.site-footer { text-align: center; padding: 20px; font-size: 12px; }
.site-footer a { color: #656d76; }
body.ws-body .site-footer { display: none; }

.flashes { max-width: 1100px; margin: 12px auto 0; padding: 0 20px; }
.flash { padding: 8px 14px; border-radius: 6px; margin: 6px 0; background: #ddf4ff; border: 1px solid #54aeff66; }
.flash.ok { background: #dafbe1; border-color: #4ac26b66; }
.flash.error { background: #ffebe9; border-color: #ff818266; color: #82071e; }

table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #d0d7de; border-radius: 8px; overflow: hidden; }
table.list th, table.list td { padding: 8px 12px; border-bottom: 1px solid #eaeef2; text-align: left; vertical-align: middle; }
table.list th { background: #f6f8fa; font-weight: 600; }
table.list tr:last-child td { border-bottom: 0; }
table.matrix th, table.matrix td { text-align: center; white-space: nowrap; }
table.matrix td:first-child, table.matrix th:first-child { text-align: left; white-space: normal; min-width: 180px; }
table.list .inline-form input { min-width: 100px; max-width: 160px; }

.badge { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 12px; line-height: 20px; font-weight: 600; white-space: nowrap; }
.st-AC { background: #dafbe1; color: #116329; }
.st-OK { background: #ddf4ff; color: #0550ae; }
.st-WA { background: #ffebe9; color: #a40e26; }
.st-RE, .st-SE { background: #fff1e5; color: #953800; }
.st-TLE { background: #fbefff; color: #8250df; }
.st-CE { background: #fff8c5; color: #7d4e00; }
.st-pending, .st-judging { background: #eaeef2; color: #424a53; }
.st-none { background: transparent; color: #8c959f; border: 1px dashed #d0d7de; }

.title-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.title-line h1 { margin: 0; }
.title-row .title-line { margin-bottom: 0; }
a.back { display: inline-block; padding: 3px 12px; border: 1px solid #d0d7de; border-radius: 6px; background: #fff;
  color: #1f2328; font-size: 13px; white-space: nowrap; }
a.back:hover { background: #eef1f4; text-decoration: none; }
.problem .title-line { margin-bottom: 12px; }
.problem .title-line h1 { font-size: 20px; }

.tag { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: 12px; line-height: 20px; white-space: nowrap; vertical-align: middle; }
.tag-deleted { background: #eaeef2; color: #57606a; }
.tag-voided { background: #ffebe9; color: #a40e26; }
.tag-solution { background: #ddf4ff; color: #0550ae; }
.tag-resubmit { background: #fff1e5; color: #953800; font-weight: 600; }

.banner { padding: 8px 14px; border-radius: 6px; margin: 8px 0 12px; background: #ddf4ff; border: 1px solid #54aeff66; }
.banner-voided { background: #ffebe9; border-color: #ff818266; color: #82071e; }
.banner-resubmit { background: #fff1e5; border-color: #fb8f4466; color: #953800; font-weight: 600; }

.row-actions { display: flex; gap: 4px; flex-wrap: nowrap; justify-content: flex-start; }
.row-actions form { margin: 0; }
table.list .row-actions button, table.list .row-actions .btn { padding: 1px 8px; font-size: 12px; }
.actions-line { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin: 8px 0 16px; }
.actions-line form { margin: 0; }
tr.row-deleted td { background: #f6f8fa; }
tr.row-deleted td:first-child a { color: #8c959f; text-decoration: line-through; }

.solution summary { cursor: pointer; font-weight: 700; }
.solution-tools { margin: 8px 0 4px; }
.solution pre.code { background: #fafbfc; border: 1px solid #eaeef2; border-radius: 6px; padding: 10px 14px;
  font-size: 13px; overflow-x: auto; white-space: pre; word-break: normal; max-height: 480px; }
.problem .solution { margin: 16px 0; padding: 10px 14px; }
textarea.code-input { font-size: 13px; tab-size: 4; white-space: pre; }
.narrow { max-width: 420px; }
input.check-box { width: auto; }

.desc { white-space: pre-wrap; margin-bottom: 12px; }
.sample { margin: 12px 0; }
.sample-head { font-weight: 700; }
.sample-label { color: #656d76; font-size: 13px; margin: 6px 0 2px; display: flex; gap: 6px; align-items: center; }
.sample pre { background: #f6f8fa; border: 1px solid #eaeef2; border-radius: 6px; padding: 6px 10px; min-height: 30px; }
.sample-edit { border: 1px solid #eaeef2; border-radius: 6px; padding: 8px 12px; margin: 10px 0; }
.sample-edit-head { display: flex; justify-content: space-between; font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-col label { margin: 4px 0; }

.out .block { margin: 8px 0; }
.out .block-label { color: #656d76; font-size: 12px; margin-bottom: 2px; }
.out pre { background: #f6f8fa; border: 1px solid #eaeef2; border-radius: 6px; padding: 6px 10px; max-height: 320px; overflow: auto; }
.out pre.err { background: #ffebe9; border-color: #ffcecb; }
.out pre.warn { background: #fff8c5; border-color: #f2e08a; }
.result-head { display: flex; gap: 10px; align-items: center; margin: 4px 0; }
.result-head .badge { font-size: 14px; line-height: 24px; padding: 0 12px; }
.msg { margin: 6px 0; }
.err-text { color: #a40e26; }
.case { border: 1px solid #eaeef2; border-radius: 6px; padding: 6px 12px; margin: 8px 0; background: #fff; }
.case summary { cursor: pointer; display: flex; gap: 10px; align-items: center; }
.case-no { font-weight: 600; }
.code-file pre.code { background: #fafbfc; border: 1px solid #eaeef2; border-radius: 6px; padding: 10px 14px; font-size: 13px; overflow-x: auto; white-space: pre; word-break: normal; }

/* ---------- coding page ---------- */
body.ws-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
body.ws-body .flashes { display: none; }
main.ws { flex: 1; display: flex; min-height: 0; }
.problem { width: 36%; min-width: 280px; overflow: auto; padding: 16px 20px; background: #fff; border-right: 1px solid #d0d7de; }
.coder { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: #f6f8fa; border-bottom: 1px solid #d0d7de; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { display: flex; align-items: center; gap: 4px; padding: 3px 10px; border: 1px solid #d0d7de; border-radius: 6px; background: #fff; cursor: pointer; font-family: Consolas, monospace; }
.tab.active { background: #0b62d6; border-color: #0b62d6; color: #fff; }
.tab-close { border: 0; background: transparent; padding: 0 2px; color: inherit; line-height: 1; font-size: 15px; }
.tab-close:hover { background: transparent; color: #cf222e; }
.editor { flex: 1; min-height: 160px; position: relative; background: #fff; }
.plain-editor { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; padding: 10px 14px; font-size: 15px; resize: none; tab-size: 4; white-space: pre; }
.bottom { height: 38%; min-height: 180px; display: flex; flex-direction: column; border-top: 1px solid #d0d7de; background: #fff; }
.bottom-tabs { display: flex; gap: 2px; padding: 4px 10px 0; background: #f6f8fa; border-bottom: 1px solid #d0d7de; }
.bottom-tabs button { border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; background: transparent; }
.bottom-tabs button.active { background: #fff; border-color: #d0d7de; margin-bottom: -1px; }
.pane { flex: 1; overflow: auto; padding: 8px 12px; min-height: 0; }
.pane.hidden { display: none; }
#pane-run { display: flex; padding: 0; }
#pane-run.hidden { display: none; }
.io { display: flex; flex: 1; min-height: 0; }
.io-col { flex: 1; display: flex; flex-direction: column; padding: 8px 12px; min-width: 0; overflow: auto; }
.io-col + .io-col { border-left: 1px solid #eaeef2; }
.io-label { font-size: 12px; color: #656d76; margin-bottom: 4px; }
#stdin { flex: 1; resize: none; font-size: 14px; min-height: 80px; }

@media (max-width: 900px) {
  body.ws-body { height: auto; overflow: auto; }
  main.ws { flex-direction: column; }
  .problem { width: auto; border-right: 0; border-bottom: 1px solid #d0d7de; }
  .editor { height: 60vh; flex: none; }
  .bottom { height: auto; }
  .io { flex-direction: column; }
  .two-col { grid-template-columns: 1fr; }
}
