:root {
  --ink: #172029;
  --muted: #6d7b87;
  --line: #dde5e2;
  --surface: #ffffff;
  --canvas: #f3f6f5;
  --nav: #10231e;
  --green-950: #0d3f34;
  --green-800: #0e5e4c;
  --green-700: #087a62;
  --green-500: #56d2b0;
  --green-100: #dff3ed;
  --amber-100: #fff0cd;
  --amber-700: #9a6200;
  --red-100: #fde7e4;
  --red-700: #c64239;
  --shadow: 0 22px 54px rgba(16, 43, 35, .10);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }

.topbar {
  height: 72px; padding: 0 34px; display: flex; align-items: stretch;
  gap: 48px; background: var(--nav); color: #fff; position: sticky; top: 0;
  z-index: 20; box-shadow: 0 1px 0 rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; font-weight: 800; letter-spacing: .2px; white-space: nowrap; }
.nav { display: flex; align-items: stretch; gap: 4px; }
.nav-link {
  min-width: 76px; padding: 0 18px; border: 0; color: #bdc8c4; background: transparent;
  display: grid; place-items: center; font-weight: 700; border-bottom: 3px solid transparent;
}
.nav-link:hover:not(:disabled), .nav-link.active { color: #fff; border-color: var(--green-500); }
.nav-link:disabled { color: #56635f; cursor: not-allowed; }
.account { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.role-chip { border: 1px solid #3a514a; border-radius: 999px; padding: 4px 9px; color: #afc4bd; font-size: 12px; }
.account-menu { position: relative; }
.account-button { color: white; border: 0; background: none; font-weight: 700; padding: 12px 4px; }
.dropdown {
  display: none; position: absolute; right: 0; top: 48px; min-width: 168px; padding: 8px;
  border-radius: 12px; background: #fff; color: var(--ink); box-shadow: var(--shadow);
}
.account-menu.open .dropdown { display: grid; }
.dropdown button { text-align: left; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; }
.dropdown button:hover { background: var(--canvas); }

.page { max-width: 1380px; margin: 0 auto; padding: 36px 30px 64px; }
.page.narrow { max-width: 1180px; }
.hero {
  min-height: 216px; display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 42px; padding: 36px 42px; border-radius: 20px; background: var(--green-950);
  color: #fff; box-shadow: var(--shadow);
}
.eyebrow { color: #72d8bb; font-weight: 800; letter-spacing: 1.4px; font-size: 14px; }
.hero h1 { margin: 10px 0 12px; max-width: 820px; font: 700 clamp(35px, 4vw, 55px)/1.02 Georgia, serif; }
.hero-meta { color: #a8d5c9; font-size: 16px; }
.hero-stats { display: flex; gap: 74px; text-align: center; min-width: 280px; justify-content: center; }
.stat strong { display: block; font-size: 34px; margin-bottom: 7px; }
.stat span { color: #9fcfc2; }
.overview-note {
  max-width: 760px; margin: 54px auto 0; text-align: center; color: var(--muted); line-height: 1.8;
}
.overview-note h2 { color: var(--ink); margin-bottom: 8px; }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 30px 0 16px; }
.section-head h2 { margin: 0 0 7px; font: 700 30px/1.2 Georgia, "Microsoft YaHei", serif; }
.section-head p { margin: 0; color: var(--muted); }
.search, .filter-select {
  min-height: 45px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); outline: none;
}
.search { width: 260px; }
.search:focus, .filter-select:focus, .field input:focus, .field textarea:focus { border-color: var(--green-700); box-shadow: 0 0 0 3px rgba(8,122,98,.12); }
.filters { display: flex; gap: 10px; }

.table-card { overflow: auto; border: 1px solid var(--line); background: #fff; border-radius: 16px; box-shadow: 0 12px 35px rgba(28,57,48,.05); }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th { text-align: left; font-size: 13px; color: #4d5d58; background: #eef3f1; padding: 15px 16px; white-space: nowrap; }
td { padding: 16px; border-top: 1px solid #edf1ef; white-space: nowrap; }
tbody tr:hover { background: #fbfdfc; }
.problem-link { color: #17619a; font-weight: 750; }
.problem-link:hover { text-decoration: underline; }
.problem-letter { color: var(--green-700); font-weight: 850; }
.status { display: inline-flex; padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.status.accepted { color: var(--green-800); background: var(--green-100); }
.status.partial { color: var(--amber-700); background: var(--amber-100); }
.status.failed { color: var(--red-700); background: var(--red-100); }
.status.pending, .status.none { color: #66736f; background: #e9eeec; }
.status.tle { color: #9a5b00; background: #ffe8c7; }
.status.mle { color: #4f3a9e; background: #e8e2fb; }
.status.ce { color: #17557f; background: #dcebf7; }
.score-100 { background: #dff2ec; color: #075c49; font-weight: 800; text-align: center; }
.score-mid { background: #fff0cd; color: #8b5700; font-weight: 800; text-align: center; }
.score-zero { color: #98a3a0; font-weight: 700; text-align: center; }
.rank-first { color: #ad7300; font-weight: 850; }

/* Course settings: the two datetime inputs and their save button. */
.window-form { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin-top: 18px; }
.window-form .field { flex: 0 0 220px; margin: 0; }
.window-form input[type="datetime-local"] { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; font-family: inherit; }
.window-form .button { height: 42px; }
.submit-note.warn { color: #8b5700; background: var(--amber-100); border-radius: 10px; padding: 10px 14px; }

/* The ranking table carries 18 problem columns plus rank / name / total.
   A fixed layout with an explicit colgroup keeps every column inside the card,
   so the whole course is visible at once instead of needing a sideways scroll. */
.ranking-card { overflow: hidden; }
.ranking-table { width: 100%; min-width: 0; table-layout: fixed; }
.ranking-table th, .ranking-table td { padding: 11px 3px; text-align: center; }
.ranking-table thead th { font-size: 12px; padding: 13px 3px; }
.ranking-table tbody td { font-size: 13px; }
.ranking-table col.c-rank { width: 52px; }
.ranking-table col.c-total { width: 72px; }
.ranking-table col.c-problem { width: 42px; }
.ranking-table th:nth-child(2), .ranking-table td:nth-child(2) {
  text-align: left; padding-left: 16px; padding-right: 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ranking-table tbody td:nth-child(2) { font-weight: 650; }
/* On a genuinely narrow screen readability wins over "no scrolling". */
@media (max-width: 880px) {
  .ranking-card { overflow-x: auto; }
  .ranking-table { min-width: 900px; }
}
.empty { padding: 72px 20px; text-align: center; color: var(--muted); }
.loading-spinner { width: 30px; height: 30px; margin: 0 auto 14px; border: 3px solid #d9e8e3; border-top-color: var(--green-700); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.back-link { display: inline-flex; margin-bottom: 14px; color: #17619a; font-weight: 700; }
.problem-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 34px rgba(28,57,48,.05); }
.statement { padding: 32px 38px; }
.statement h1 { margin: 5px 0 12px; font: 700 36px/1.15 Georgia, serif; }
.statement h3 { margin: 28px 0 9px; }
.statement p { line-height: 1.75; color: #35413e; }
.rich-text { line-height: 1.75; color: #35413e; overflow-wrap: anywhere; }
.rich-text img { max-width: 100%; height: auto; }
.notice { padding: 10px 14px; border-radius: 9px; background: var(--amber-100); color: #8a6118; font-size: 13px; }
.sample { background: var(--nav); color: #d8f1e9; border-radius: 9px; padding: 15px 17px; font: 14px/1.55 Consolas, monospace; white-space: pre-wrap; }
/* Submission detail: without this the metadata and code sit flush against the
   card border and the page looks unfinished. */
.detail-card { padding: 30px 34px; }
.code-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-top: 26px; }
.code-head h3 { margin: 0; }
.code-meta { color: var(--muted); font-size: 13px; }
.code-view { margin: 10px 0 0; max-height: none; overflow-x: auto; }
.side-stack { display: grid; gap: 16px; }
.info-card, .submit-card { padding: 22px; }
.info-card h3, .submit-card h3 { margin: 0 0 16px; }
.info-list { display: grid; gap: 12px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 14px; }
.info-row strong { color: var(--ink); text-align: right; }
.code-editor {
  width: 100%; min-height: 255px; resize: vertical; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; font: 13px/1.6 Consolas, "Cascadia Code", monospace; outline: none;
}
.button { border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 750; }
.button.primary { background: var(--green-700); color: white; }
.button.primary:hover { background: var(--green-800); }
.button.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.button.danger { background: #fff; color: var(--red-700); border: 1px solid #f0cac6; }
.button.block { width: 100%; }
.submit-note { margin: 11px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(7,24,19,.68); backdrop-filter: blur(2px); }
.modal { width: min(100%, 520px); background: #fff; border-radius: 18px; padding: 32px; box-shadow: 0 30px 90px rgba(0,0,0,.25); }
.modal h2 { font-size: 27px; margin: 5px 0 10px; }
.modal-copy { color: var(--muted); line-height: 1.6; margin-bottom: 22px; }
.field { display: grid; gap: 7px; margin: 15px 0; }
.field label { font-weight: 700; font-size: 14px; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px 13px; outline: none; background: #fff; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.dev-hint { padding: 12px; background: var(--green-100); color: #155e4d; border-radius: 10px; font-size: 13px; line-height: 1.6; }
.form-error { min-height: 20px; color: var(--red-700); font-size: 13px; }

.admin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 22px; }
.admin-card { padding: 22px; }
.admin-card h3 { margin-top: 0; }
.admin-card p { color: var(--muted); line-height: 1.55; min-height: 48px; }
.admin-wide { grid-column: 1 / -1; }
.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fake-upload { border: 1px dashed #9fb2ac; padding: 24px; border-radius: 10px; text-align: center; color: var(--muted); }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 80; padding: 13px 17px; border-radius: 10px; background: var(--nav); color: white; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 900px) {
  .topbar { padding: 0 18px; gap: 15px; }
  .brand { font-size: 14px; }
  .nav-link { min-width: auto; padding: 0 10px; }
  .page { padding: 25px 17px 50px; }
  .hero { grid-template-columns: 1fr; padding: 28px; }
  .hero-stats { justify-content: flex-start; }
  .problem-layout { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: 1fr 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-wide { grid-column: auto; }
}
@media (max-width: 620px) {
  .topbar { height: auto; min-height: 64px; flex-wrap: wrap; padding-top: 10px; }
  .brand { width: calc(100% - 110px); }
  .account { position: absolute; right: 16px; top: 10px; }
  .nav { width: 100%; order: 3; overflow-x: auto; }
  .nav-link { height: 45px; flex: 1; }
  .hero h1 { font-size: 32px; }
  .hero-stats { gap: 38px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
  .side-stack { grid-template-columns: 1fr; }
  .statement { padding: 24px 20px; }
  .date-grid { grid-template-columns: 1fr; }
}
