:root {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #667083;
  --paper: #f6f1e7;
  --panel: #fffaf0;
  --line: #ded4c3;
  --code: #121820;
  --accent: #e24b2f;
  --accent-2: #1d7f6e;
  --blue: #2f5fbd;
  --good: #16804f;
  --bad: #ba3329;
  --warn: #a66a00;
  font-family: "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(28, 36, 48, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(28, 36, 48, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

button,
textarea,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  border: 2px solid var(--ink);
  background: var(--panel);
  padding: 28px;
  box-shadow: 9px 9px 0 var(--ink);
}

.brand.large {
  margin-bottom: 28px;
}

.brand.large strong {
  font-size: 28px;
}

.login-card label {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  color: var(--muted);
}

.login-card input,
.search,
.profile-form input {
  width: 100%;
  border: 1px solid var(--ink);
  background: #fffdf7;
  color: var(--ink);
  outline: none;
}

.login-card input {
  height: 44px;
  padding: 0 12px;
}

.login-card p {
  color: var(--muted);
  margin: 16px 0 0;
}

.profile-form {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.74);
  padding: 10px;
  margin-bottom: 12px;
}

.profile-form label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
}

.profile-form div {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 8px;
}

.profile-form input {
  height: 34px;
  padding: 0 10px;
}

.profile-form button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.profile-form p {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.shell {
  display: grid;
  grid-template-columns: 330px minmax(360px, 1fr) minmax(430px, 42vw);
  min-height: 100vh;
}

.shell.teacher-mode {
  grid-template-columns: 330px minmax(0, 1fr);
}

.rail,
.problem-pane,
.workbench {
  min-width: 0;
  padding: 24px;
}

.rail {
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.72);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 2px solid var(--ink);
  background: var(--accent);
  color: white;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
  box-shadow: 5px 5px 0 var(--ink);
}

.brand strong,
.editor-head strong {
  display: block;
  font-size: 18px;
}

.brand small,
.editor-head small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

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

.filter,
.problem-card,
#resetBtn,
#statsBtn,
#logoutBtn,
.primary {
  border: 1px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.filter {
  min-height: 54px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
}

.filter:first-child {
  grid-column: 1 / -1;
  min-height: 42px;
  flex-direction: row;
  gap: 8px;
}

.filter b {
  font-weight: 700;
}

.filter.active {
  background: var(--ink);
  color: white;
}

.filter span {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  line-height: 1;
  opacity: 0.84;
}

.filter:first-child span {
  font-size: 15px;
}

.problem-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 278px);
  overflow: auto;
  padding-right: 4px;
}

.problem-card {
  position: relative;
  width: 100%;
  text-align: left;
  padding: 14px 54px 14px 14px;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.problem-card:hover,
.problem-card.active {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
}

.problem-card.active {
  background: #fff2c7;
}

.problem-card strong {
  display: block;
  font-size: 16px;
}

.problem-card span {
  display: block;
  color: var(--muted);
  margin-top: 7px;
  font-size: 13px;
}

.problem-card i {
  position: absolute;
  right: 12px;
  top: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-style: normal;
  font-size: 12px;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stats-panel div {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.84);
  padding: 10px;
}

.stats-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  line-height: 1;
}

.search {
  height: 38px;
  padding: 0 12px;
  margin-bottom: 12px;
}

.problem-pane {
  overflow: auto;
}

.topline,
.meta,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topline span,
.tag {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.8);
  padding: 6px 10px;
  font-size: 13px;
}

#progressBadge.AC {
  border-color: rgba(22, 128, 79, 0.4);
  background: rgba(22, 128, 79, 0.1);
}

h1 {
  margin: 16px 0 12px;
  font-size: clamp(30px, 5vw, 56px);
  line-height: 1;
  letter-spacing: 0;
}

.statement {
  margin-top: 28px;
}

.statement h2,
.sample-title {
  font-size: 15px;
  margin: 22px 0 8px;
  color: var(--accent);
}

.statement p {
  font-size: 17px;
  line-height: 1.8;
  margin: 0;
}

.samples {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 22px;
}

pre,
textarea {
  font-family: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  min-height: 72px;
  border: 1px solid var(--ink);
  background: #101820;
  color: #f8f0d8;
}

.workbench {
  display: grid;
  grid-template-rows: auto minmax(330px, 1fr) auto minmax(120px, 19vh) minmax(160px, 22vh);
  gap: 14px;
  border-left: 1px solid var(--line);
  background: #fdf7e9;
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.head-actions {
  display: flex;
  gap: 8px;
}

#resetBtn,
#statsBtn,
#logoutBtn {
  width: 38px;
  height: 38px;
  font-size: 20px;
}

.editor-wrap {
  position: relative;
  min-height: 330px;
  border: 2px solid var(--ink);
  background: var(--code);
  box-shadow: 7px 7px 0 var(--ink);
}

.code-highlight,
#editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 18px;
  border: 0;
  line-height: 1.55;
  font-size: 14px;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

.code-highlight {
  pointer-events: none;
  background: transparent;
  color: #f6e9c9;
}

#editor {
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: #f6e9c9;
  outline: none;
  z-index: 2;
}

#editor::selection {
  background: rgba(226, 75, 47, 0.35);
}

.tok-keyword {
  color: #ffb454;
}

.tok-builtin {
  color: #7dd3fc;
}

.tok-string {
  color: #a6e3a1;
}

.tok-number {
  color: #f9a8d4;
}

.tok-comment {
  color: #7a8493;
}

.tok-pre {
  color: #f87171;
}

.autocomplete {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(310px, calc(100% - 32px));
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--ink);
  background: #fffaf0;
  box-shadow: 6px 6px 0 var(--ink);
  z-index: 5;
}

.autocomplete button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 9px 11px;
  text-align: left;
  cursor: pointer;
}

.autocomplete button:last-child {
  border-bottom: 0;
}

.autocomplete button.active,
.autocomplete button:hover {
  background: var(--ink);
  color: white;
}

.autocomplete strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.autocomplete span {
  color: inherit;
  opacity: 0.72;
  font-size: 12px;
}

.primary {
  height: 42px;
  padding: 0 22px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  box-shadow: 4px 4px 0 var(--ink);
}

.primary.full {
  width: 100%;
  margin-top: 8px;
}

.primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

#statusText {
  color: var(--muted);
}

.result {
  overflow: auto;
  border: 1px solid var(--ink);
  background: var(--panel);
  padding: 14px;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}

.dashboard > div,
.management > div {
  overflow: auto;
  border: 1px solid var(--ink);
  background: rgba(255, 250, 240, 0.72);
  padding: 12px;
}

.dashboard h2,
.management h2 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 15px;
}

.management {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
}

.teacher-only {
  grid-column: 1 / -1;
}

.compact-list {
  display: grid;
  gap: 7px;
}

.compact-list > div,
.history-item,
.assignment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 7px 0;
  color: var(--ink);
}

.assignment-item,
.history-item {
  width: 100%;
  border-right: 0;
  border-left: 0;
  border-bottom: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.compact-list button.text-danger {
  border: 1px solid rgba(186, 51, 41, 0.45);
  background: rgba(186, 51, 41, 0.08);
  color: var(--bad);
  padding: 4px 8px;
  cursor: pointer;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.row-actions button {
  border: 1px solid var(--ink);
  background: rgba(255, 250, 240, 0.8);
  color: var(--ink);
  padding: 4px 8px;
  cursor: pointer;
}

.row-actions button.text-danger {
  border-color: rgba(186, 51, 41, 0.45);
  background: rgba(186, 51, 41, 0.08);
  color: var(--bad);
}

.history-item {
  width: 100%;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

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

.teacher-grid form {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  padding: 10px;
}

.teacher-grid input,
.teacher-grid select {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--ink);
  background: #fffdf7;
  padding: 0 9px;
}

.teacher-grid button {
  height: 34px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.teacher-home {
  min-width: 0;
  padding: 24px;
  overflow: auto;
}

.teacher-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.teacher-hero span {
  color: var(--accent);
  font-weight: 700;
}

.teacher-hero h1 {
  margin: 8px 0 0;
  font-size: 38px;
}

.teacher-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.teacher-hero button {
  border: 1px solid var(--ink);
  background: var(--blue);
  color: white;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}

.teacher-hero button:last-child {
  background: var(--ink);
}

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

.teacher-layout section {
  border: 1px solid var(--ink);
  background: rgba(255, 250, 240, 0.78);
  padding: 14px;
}

.teacher-layout section.wide {
  grid-column: 1 / -1;
}

.teacher-layout h2 {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 16px;
}

.teacher-layout form {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.teacher-layout input,
.teacher-layout select {
  height: 36px;
  border: 1px solid var(--ink);
  background: #fffdf7;
  padding: 0 10px;
}

.teacher-layout button {
  height: 36px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(28, 36, 48, 0.42);
}

.modal {
  width: min(520px, 100%);
  border: 2px solid var(--ink);
  background: var(--panel);
  box-shadow: 9px 9px 0 var(--ink);
  padding: 18px;
}

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

.modal-head h2 {
  margin: 0;
  font-size: 22px;
}

.modal-head button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 22px;
}

.modal-fields {
  display: grid;
  gap: 12px;
}

.modal-fields label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.modal-fields input,
.modal-fields textarea,
.modal-fields select {
  width: 100%;
  border: 1px solid var(--ink);
  background: #fffdf7;
  color: var(--ink);
  padding: 9px 10px;
}

.modal-fields textarea {
  min-height: 90px;
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions button {
  height: 38px;
  border: 1px solid var(--ink);
  background: var(--panel);
  padding: 0 14px;
  cursor: pointer;
}

.modal-actions .primary {
  background: var(--blue);
  color: white;
}

.chapter-row,
.recent-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.recent-row span,
.chapter-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.verdict {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.verdict strong {
  font-size: 34px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.case {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.case-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}

.AC {
  color: var(--good);
}

.WA,
.RE,
.CE,
.TLE,
.MLE,
.OLE,
.SE {
  color: var(--bad);
}

.case pre {
  margin-top: 8px;
  min-height: 0;
  max-height: 150px;
  font-size: 12px;
}

.empty {
  color: var(--muted);
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 300px 1fr;
  }

  .workbench {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .problem-list {
    max-height: 520px;
  }
}

@media (max-width: 760px) {
  .shell {
    display: block;
  }

  .rail,
  .problem-pane,
  .workbench {
    padding: 18px;
  }

  .samples {
    grid-template-columns: 1fr;
  }

  .filters,
  .stats-panel,
  .dashboard,
  .management,
  .teacher-grid,
  .teacher-layout {
    grid-template-columns: 1fr;
  }

  .filter:first-child {
    grid-column: auto;
  }

  #editor {
    min-height: 320px;
  }
}
