:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #141a22;
  --panel-2: #1a2330;
  --panel-3: #202b3a;
  --ink: #f4f8ff;
  --muted: #9aa8ba;
  --line: #2b384a;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --warn: #ffbf69;
  --bad: #ff6b6b;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.26);
  --shadow-soft: 0 10px 26px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(18, 27, 39, 0.92), rgba(11, 15, 22, 0.98)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.026) 0 1px, transparent 1px 48px),
    var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

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

button:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.9);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  padding: 20px 18px;
  border-right: 1px solid var(--line);
  background: rgba(13, 17, 23, 0.9);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.025);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border: 1px solid rgba(96, 165, 250, 0.52);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(59, 130, 246, 0.2), rgba(34, 211, 238, 0.1));
  color: #d7eafe;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 12px 26px rgba(37, 99, 235, 0.12);
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  color: #ffffff;
  font-size: 19px;
  line-height: 1.2;
}

.brand p,
.progress-panel small,
.source,
.status-pill,
#autosave,
#runState {
  color: var(--muted);
  font-size: 13px;
}

.progress-panel {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(26, 35, 48, 0.92), rgba(19, 25, 35, 0.96));
  box-shadow: var(--shadow-soft);
}

.account-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 26, 34, 0.86);
}

.account-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-meta strong {
  overflow: hidden;
  color: #f4f8ff;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-meta span {
  color: #93c5fd;
  font-size: 12px;
  white-space: nowrap;
}

.account-form {
  display: grid;
  gap: 8px;
}

.account-form[hidden] {
  display: none;
}

.account-form input {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #0b0f14;
  color: var(--ink);
}

.account-form input:focus {
  border-color: rgba(96, 165, 250, 0.85);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

.account-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#logoutBtn[hidden] {
  display: none;
}

#progressText {
  display: block;
  font-size: 23px;
  font-weight: 800;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #080b10;
}

.bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.36);
}

.level-list {
  display: grid;
  flex: 1;
  grid-auto-rows: minmax(72px, max-content);
  gap: 9px;
  align-content: start;
  min-height: 0;
  overflow: auto;
}

.level-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 0;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 26, 34, 0.9);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.level-item:hover:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.6);
  background: rgba(28, 39, 54, 0.96);
}

.level-item:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.level-item.active {
  border-color: rgba(96, 165, 250, 0.95);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(32, 43, 58, 0.96));
  box-shadow: inset 4px 0 0 var(--accent), var(--shadow-soft);
}

.level-item.passed {
  border-color: rgba(34, 211, 238, 0.68);
}

.level-no {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #0c1118;
  color: #dbeafe;
  font-weight: 800;
}

.level-title {
  min-width: 0;
}

.level-title strong {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}

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

.badge {
  color: #60a5fa;
  font-size: 12px;
  font-weight: 700;
}

.text-button,
.secondary,
.primary,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
}

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

.secondary:hover:not(:disabled),
.text-button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.72);
  background: var(--panel-3);
}

.primary {
  border-color: rgba(96, 165, 250, 0.95);
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  color: #f8fbff;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.28);
}

.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #7bb7ff, #2f6feb);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.sidebar-pager {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.icon-button {
  display: grid;
  place-items: center;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.sidebar-pager .icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.main {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr) 188px;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  padding: 20px 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  margin-top: 3px;
  color: #ffffff;
  font-size: 29px;
  letter-spacing: 0;
}

.status-pill {
  min-width: 96px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 26, 34, 0.9);
  text-align: center;
}

.status-pill.pass {
  border-color: rgba(34, 211, 238, 0.72);
  color: #b9f7ff;
}

.status-pill.fail {
  border-color: rgba(255, 107, 107, 0.75);
  color: #ffd0d0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.problem,
.ide,
.console {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(20, 26, 34, 0.94);
  box-shadow: var(--shadow);
}

.problem {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  padding: 18px;
  overflow: auto;
}

.section-heading {
  color: #bfdbfe;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.problem p,
.io-grid dd,
.hint-box {
  color: #d7e0ea;
  line-height: 1.78;
}

#task {
  white-space: pre-wrap;
}

.io-grid {
  display: none;
  gap: 10px;
  margin: 0;
}

.io-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111822;
}

.io-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.io-grid dd {
  margin: 5px 0 0;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.actions button {
  flex: 1;
}

.hint-box {
  padding: 14px;
  border: 1px solid rgba(255, 191, 105, 0.45);
  border-radius: 8px;
  background: rgba(255, 191, 105, 0.1);
}

.ide {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  overflow: hidden;
}

.editor-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #0b0f14;
}

.monaco-editor-host {
  display: none;
  width: 100%;
  height: 100%;
}

.editor-shell.monaco-ready .monaco-editor-host {
  display: block;
}

.editor-shell.monaco-ready #editor,
.editor-shell.monaco-ready .error-layer {
  display: none;
}

.monaco-editor,
.monaco-editor-background,
.monaco-editor .margin {
  background: #0b0f14 !important;
}

.monaco-error-line {
  background: rgba(255, 107, 107, 0.18) !important;
  box-shadow: inset 4px 0 0 var(--bad);
}

.error-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.error-line {
  position: absolute;
  right: 0;
  left: 0;
  border-left: 4px solid var(--bad);
  background: rgba(255, 107, 107, 0.18);
}

.editor-toolbar,
.runbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(24, 32, 44, 0.98), rgba(18, 24, 34, 0.98));
}

.runbar {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  background: rgba(15, 21, 30, 0.98);
}

#editor {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  padding: 18px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #f0f6fc;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 15px;
  line-height: 1.55;
  tab-size: 4;
}

.console {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.console .section-heading {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(24, 32, 44, 0.98), rgba(18, 24, 34, 0.98));
}

#consoleOutput {
  margin: 0;
  overflow: auto;
  padding: 16px;
  color: #dbe7f3;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #55657a;
  background-clip: padding-box;
}

::-webkit-scrollbar-track {
  background: transparent;
}

.finish {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 8, 12, 0.72);
}

.finish[hidden] {
  display: none;
}

.finish-panel {
  width: min(520px, 100%);
  padding: 28px;
  border: 1px solid rgba(96, 165, 250, 0.65);
  border-radius: 8px;
  background: #151b24;
  box-shadow: var(--shadow);
}

.finish-panel h2 {
  margin-bottom: 10px;
}

.finish-panel p {
  margin-bottom: 18px;
  color: #d7e0ea;
  line-height: 1.8;
}

.answer-dialog {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 10, 16, 0.78);
}

.answer-dialog[hidden] {
  display: none;
}

.answer-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  width: min(860px, 92vw);
  height: min(720px, 88vh);
  padding: 18px;
  border: 1px solid rgba(96, 165, 250, 0.68);
  border-radius: 10px;
  background: #141a22;
  box-shadow: var(--shadow);
}

.answer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.answer-header h2 {
  margin-top: 4px;
  font-size: 22px;
}

.answer-header .icon-button {
  width: 38px;
  min-height: 38px;
}

.answer-panel p {
  color: #d7e0dc;
  line-height: 1.7;
}

#answerCode {
  margin: 0;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0f14;
  color: #f0f6f3;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .workspace {
    grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  }

  .main {
    padding: 16px;
  }
}

@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    width: 100%;
    max-width: 100vw;
    padding: 18px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .level-list {
    grid-template-rows: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .account-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .account-meta strong,
  .account-meta span {
    max-width: 100%;
  }

  .main {
    grid-template-rows: auto auto minmax(220px, auto);
    width: 100%;
    max-width: 100vw;
    height: auto;
    overflow: hidden;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-pill {
    min-width: 0;
  }

  .topbar h2 {
    font-size: 24px;
  }

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

  .problem,
  .ide,
  .console {
    min-height: 320px;
  }

  .ide {
    min-height: 520px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #resetCodeBtn {
    grid-column: 1 / -1;
  }
}
