:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --ink: #172033;
  --muted: #5e6b7d;
  --line: #d8dee8;
  --teal: #0f766e;
  --teal-2: #e6f4f1;
  --blue: #2457c5;
  --amber: #b45309;
  --red: #b42318;
  --green: #16794c;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover {
  border-color: #9aa8bc;
}

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

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

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 118, 110, 0.2);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.brand-notice {
  color: #9a3412;
  font-weight: 650;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 10px;
  flex: 0 0 auto;
}

.stat-strip div {
  min-width: 78px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: right;
}

.stat-strip strong {
  display: block;
  font-size: 20px;
  line-height: 1;
}

.stat-strip span {
  color: var(--muted);
  font-size: 12px;
}

.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 0;
  min-height: 0;
}

.question-panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-height: calc(100vh - 89px);
  display: flex;
  flex-direction: column;
}

.search-row {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.search-row input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
}

.search-row input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.topic-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.topic-tabs button {
  white-space: nowrap;
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
}

.topic-tabs button.active {
  background: var(--teal-2);
  color: var(--teal);
  border-color: rgba(15, 118, 110, 0.35);
}

.question-list {
  overflow: auto;
  padding: 8px;
}

.question-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
}

.question-item.active {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--teal-2);
}

.question-item.passed .status-dot {
  background: var(--green);
}

.question-item.failed .status-dot {
  background: var(--red);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b8c2d2;
}

.question-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.35;
}

.question-item span {
  color: var(--muted);
  font-size: 12px;
}

.level-pill {
  color: var(--amber);
  font-size: 12px;
}

.work-area {
  min-width: 0;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.2fr);
  gap: 16px;
  align-content: start;
}

.problem-panel,
.editor-panel,
.solution-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.problem-panel,
.solution-panel {
  padding: 18px;
}

.problem-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.problem-meta span,
#sourceNote {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

#questionTitle {
  margin: 0 0 12px;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

#questionPrompt {
  margin: 0 0 16px;
  line-height: 1.75;
  color: #263247;
}

.spec-grid,
.example-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.spec-grid div,
.example-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-2);
  min-width: 0;
}

h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.spec-grid p {
  margin: 0;
  line-height: 1.65;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.example-grid pre,
.judge-output,
.solution-code {
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-heading {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 16px;
}

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

.icon-actions button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.editor-wrap {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  min-height: 360px;
  border-bottom: 1px solid var(--line);
  background: #101826;
}

.line-numbers {
  padding: 14px 10px;
  color: #7d8da6;
  text-align: right;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
  user-select: none;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

#codeEditor {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: 0;
  outline: none;
  padding: 14px;
  background: transparent;
  color: #eef4ff;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
  tab-size: 4;
}

.run-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.run-row button {
  min-height: 38px;
  padding: 0 14px;
  font-weight: 650;
}

.primary {
  color: #ffffff;
  border-color: var(--teal);
  background: var(--teal);
}

.primary:hover {
  border-color: #0b5e58;
  background: #0b5e58;
}

.secondary {
  background: var(--panel-2);
}

.runner-status {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.runner-status.ok {
  color: var(--green);
}

.runner-status.error {
  color: var(--red);
}

.judge-output {
  min-height: 160px;
  max-height: 340px;
  overflow: auto;
  padding: 14px;
  background: #f7f8fb;
  color: #1b2738;
  font-size: 13px;
  line-height: 1.6;
}

.solution-panel {
  grid-column: 1 / -1;
}

.solution-panel[hidden] {
  display: none;
}

.solution-code {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101826;
  color: #eef4ff;
  overflow: auto;
  font-size: 14px;
  line-height: 1.6;
}

.line-explanation {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.line-note {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.line-note code {
  color: var(--blue);
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
}

.line-note p {
  margin: 0;
  line-height: 1.65;
}

.alternative-solutions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.alternative-solutions h3,
.alternative-card h4 {
  margin: 0;
  color: var(--ink);
}

.alternative-solutions h3 {
  font-size: 18px;
}

.alternative-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.alternative-card h4 {
  font-size: 15px;
}

.alternative-card pre {
  max-height: 300px;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: #0f172a;
  color: #e5edf8;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
}

.alternative-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.case-pass {
  color: var(--green);
  font-weight: 700;
}

.case-fail {
  color: var(--red);
  font-weight: 700;
}

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

@media (max-width: 900px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .stat-strip {
    width: 100%;
  }

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

  .question-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .question-list {
    max-height: 330px;
  }

  .work-area {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 14px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .brand p {
    font-size: 13px;
  }

  .stat-strip {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .stat-strip div {
    min-width: 0;
    text-align: left;
  }

  .spec-grid,
  .example-grid {
    grid-template-columns: 1fr;
  }

  .editor-wrap {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .line-note {
    grid-template-columns: 1fr;
  }
}
