:root {
  --bg0: #e8f3fb;
  --bg1: #d7eaf8;
  --card: #ffffff;
  --ink: #1a2b3c;
  --muted: #5b738a;
  --line: #c5d8ea;
  --accent: #2f6fed;
  --accent-hover: #1f5ad0;
  --danger: #9b2c2c;
  --danger-bg: #fde8e8;
  --ok: #0f6b45;
  --ok-bg: #e3f6ec;
  --mine: #fff4d6;
  --mine-line: #e2b84c;
  --radius: 14px;
  --font: "IBM Plex Sans SC", "IBM Plex Sans", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1000px 500px at 0% 0%, #cfe6f8 0%, transparent 55%),
    radial-gradient(900px 480px at 100% 0%, #b9daf5 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 40px;
  gap: 20px;
}

.page-board {
  align-items: stretch;
  justify-content: flex-start;
}

.shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 28px 18px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.shell-wide {
  width: min(1440px, 100%);
  padding: 20px 28px 40px;
}

.brand {
  text-align: center;
  color: var(--ink);
  max-width: 420px;
}

.brand-mark {
  margin: 0 0 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
  color: #4d7eb8;
}

.brand h1, .topbar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  color: var(--ink);
}

.topbar-light {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  backdrop-filter: blur(6px);
}

.topbar-right {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.latest-card {
  min-width: 220px;
  text-align: left;
  border: 1px solid #9dbce0;
  background: linear-gradient(180deg, #f7fbff, #e8f2fc);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.latest-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(47, 111, 237, 0.12);
}

.latest-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.latest-score {
  display: block;
  margin-top: 2px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.latest-meta {
  display: block;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--ink);
}

.latest-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 35, 55, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-mask[hidden] {
  display: none !important;
}

.scoring-mask {
  z-index: 80;
  background: rgba(16, 32, 52, 0.62);
  backdrop-filter: blur(2px);
}

.scoring-panel {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(20, 35, 55, 0.28);
  padding: 28px 24px 24px;
  text-align: center;
}

.scoring-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 3px solid #d7e6f6;
  border-top-color: var(--accent);
  animation: scoring-spin 0.8s linear infinite;
}

@keyframes scoring-spin {
  to { transform: rotate(360deg); }
}

.scoring-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 600;
}

.scoring-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.modal-panel {
  width: min(860px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(20, 35, 55, 0.25);
  padding: 16px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
}

.modal-title-group {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-title-sep {
  flex: 0 0 auto;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 600;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  font-weight: 500;
  cursor: pointer;
  flex: 0 0 auto;
}

.modal-close:hover {
  background: #e8f0fa;
  color: var(--ink);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.pager-info {
  color: var(--muted);
  font-size: 0.88rem;
  min-width: 120px;
  text-align: center;
}

.pager button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.quota-box {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef5fc;
  border: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--ink);
}

.quota-day {
  color: var(--muted);
  font-weight: 600;
}

.deadline-banner {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0 0;
  padding: 12px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, #fff4e8 0%, #ffe0c2 100%);
  border: 1px solid #f0a35a;
  box-shadow: 0 4px 14px rgba(196, 90, 20, 0.12);
}

.deadline-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: #9a3b00;
  letter-spacing: 0.02em;
}

.deadline-value {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.1;
  color: #c2410c;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.deadline-banner.is-closed {
  background: linear-gradient(135deg, #fde8e8 0%, #f8c7c7 100%);
  border-color: #e07070;
}

.deadline-banner.is-closed .deadline-label,
.deadline-banner.is-closed .deadline-value {
  color: #9b1c1c;
}

.cooldown-banner {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #7eb6e8;
  background: linear-gradient(135deg, #e8f4ff 0%, #d6ebff 100%);
  box-shadow: 0 4px 14px rgba(29, 79, 124, 0.1);
}

.cooldown-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1d4f7c;
}

.cooldown-value {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
  color: #0b5cab;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.cooldown-banner.is-waiting {
  border-color: #f0a35a;
  background: linear-gradient(135deg, #fff7ed 0%, #ffe8cc 100%);
}

.cooldown-banner.is-waiting .cooldown-label {
  color: #9a3b00;
}

.cooldown-banner.is-waiting .cooldown-value {
  color: #c2410c;
}

.cooldown-banner.is-ready {
  border-color: #6fbf86;
  background: linear-gradient(135deg, #eaf8ef 0%, #d8f3e1 100%);
}

.cooldown-banner.is-ready .cooldown-label,
.cooldown-banner.is-ready .cooldown-value {
  color: #1f7a3d;
}

.cooldown-banner.is-closed {
  border-color: #e07070;
  background: linear-gradient(135deg, #fde8e8 0%, #f8c7c7 100%);
}

.cooldown-banner.is-closed .cooldown-label,
.cooldown-banner.is-closed .cooldown-value {
  color: #9b1c1c;
}

.foot a {
  color: var(--accent);
}

.btn-secondary.is-active {
  background: #1d4f7c;
  color: #fff;
  border-color: #1d4f7c;
}

.teacher-edit-cell {
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}

.teacher-score-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.score-input {
  width: 96px !important;
  margin: 0 !important;
  padding: 8px 10px !important;
  font-size: 0.9rem !important;
  border-radius: 8px !important;
  border: 1px solid var(--line);
  background: #fff;
}

.score-input-text {
  width: 120px !important;
}

.teacher-time {
  min-width: 140px;
  font-size: 0.85rem;
  color: var(--muted);
}

.btn-save-score {
  width: auto !important;
  margin: 0 !important;
  padding: 8px 14px !important;
  font-size: 0.88rem !important;
  background: #1d4f7c;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-save-score:hover {
  background: #163d61;
}

.add-group-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 14px;
  align-items: flex-end;
  margin-top: 14px;
}

.add-group-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.add-group-form select,
.add-group-form input[type="text"] {
  width: auto;
  min-width: 180px;
  margin: 0;
  padding: 8px 12px;
  font-size: 0.95rem;
}

.add-group-form .btn-save-score {
  height: 40px;
}

input[type="number"] {
  width: 100%;
  appearance: textfield;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  outline: none;
}


.sub {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.topbar .sub strong {
  color: var(--ink);
}

.card, .panel {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  box-shadow: 0 10px 30px rgba(47, 111, 237, 0.08);
  border: 1px solid var(--line);
}

.panel {
  width: 100%;
  padding: 18px 18px 16px;
}

.panel-board {
  padding: 12px;
}

.panel-head {
  margin-bottom: 14px;
}

.panel-head-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-head-row h2 {
  margin: 0;
  font-size: 1.1rem;
}

.refresh-meta,
.score-formula {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 8px;
}

select,
input[type="text"],
input[type="file"] {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus,
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.18);
}

button,
.btn-secondary {
  margin-top: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 13px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.1s ease;
}

button {
  background: var(--accent);
  color: #fff;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-secondary {
  background: #e8f0fa;
  color: var(--ink);
}

.btn-secondary:hover {
  background: #d7e6f6;
}

.btn-inline {
  width: auto;
  margin-top: 0;
  padding: 10px 14px;
  white-space: nowrap;
}

.btn-danger-inline {
  width: auto !important;
  margin: 0 !important;
  padding: 8px 14px !important;
  font-size: 0.88rem !important;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-danger-inline:hover {
  background: #7f1d1d;
}

.clear-board-form .read-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.alert {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.alert-error, .card .alert {
  background: var(--danger-bg);
  color: var(--danger);
  margin-bottom: 12px;
}

.alert-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.foot {
  color: var(--muted);
  font-size: 0.8rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.table-wrap-wide {
  border-radius: 12px;
}

.board {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.board-large {
  min-width: 100%;
}

.board th,
.board td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.98rem;
}

.board-large th,
.board-large td {
  padding: 16px 18px;
  font-size: 1.02rem;
}

.board th {
  background: #eef5fc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
}

.board tr:last-child td {
  border-bottom: none;
}

.rank-cell {
  font-weight: 700;
  width: 72px;
}

.score-cell {
  font-weight: 700;
  font-size: 1.08rem;
}

.time-cell {
  color: var(--muted);
  white-space: nowrap;
}

.medal {
  display: inline-flex;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  color: #1a1408;
  font-weight: 700;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
}

.medal.gold { background: linear-gradient(180deg, #ffe08a, #f0b429); }
.medal.silver { background: linear-gradient(180deg, #eef2f4, #b8c4ce); }
.medal.bronze { background: linear-gradient(180deg, #f0c29a, #c7783c); color: #fff; }

.board tr.rank-1 td { background: #fff9e8; }
.board tr.rank-2 td { background: #f4f7fa; }
.board tr.rank-3 td { background: #fbf3eb; }

.board tr.is-mine td {
  background: var(--mine) !important;
  box-shadow: inset 4px 0 0 var(--mine-line);
  font-weight: 600;
}

.tag-mine {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--mine-line);
  color: #3d2e08;
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
}

.upload-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.upload-form input[type="text"] {
  flex: 0 1 220px;
  margin-top: 0;
}

.upload-form input[type="file"] {
  display: none;
}

.dropzone {
  position: relative;
  margin-top: 12px;
  padding: 28px 18px;
  border: 2px dashed #7eb6e8;
  border-radius: 12px;
  background: #f5faff;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  display: block;
  flex: none;
}

.dropzone-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #1d4f7c;
}

.dropzone-file {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.dropzone.is-dragover {
  border-color: #0b5cab;
  background: #e8f3ff;
  box-shadow: 0 0 0 3px rgba(11, 92, 171, 0.15);
}

.dropzone.has-file {
  border-color: #6fbf86;
  background: #eef9f2;
}

.dropzone.has-file .dropzone-file {
  color: #1f7a3d;
  font-weight: 600;
}

.dropzone.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: #f3f6f9;
  border-color: #c5d0db;
}

.dropzone.is-disabled input[type="file"] {
  pointer-events: none;
}

.upload-form button {
  margin-top: 0;
  width: auto;
  min-width: 140px;
}

.format-details {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: #f7fbff;
}

.read-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  margin: 0 0 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef5fc;
  border: 1px solid var(--line);
  font-size: 0.92rem;
  color: var(--ink);
  cursor: pointer;
}

.read-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.upload-form-gated {
  align-items: stretch;
}

.format-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  user-select: none;
}

.format-details[open] summary {
  margin-bottom: 12px;
  color: var(--ink);
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.demo-block {
  background: #f7fbff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.demo-block-accent {
  border-color: #9dbce0;
  background: #eef6ff;
}

.demo-block h3 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.code-demo {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #1c2f44;
  color: #d7ebff;
  font-size: 0.82rem;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre;
}

.demo-rules {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.65;
}

.demo-rules code {
  background: #e7eef6;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

@media (max-width: 900px) {
  .shell-wide {
    padding: 16px 12px 32px;
  }
  .demo-grid {
    grid-template-columns: 1fr;
  }
  .panel-head-row,
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .upload-form button {
    width: 100%;
  }
}
