:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --ink: #1d2433;
  --muted: #657087;
  --panel: #ffffff;
  --line: #dce2ee;
  --accent: #0f8b8d;
  --accent-dark: #096b6d;
  --warn: #c15f18;
  --danger: #bf3434;
  --success: #227447;
  --code-bg: #151821;
  --code-ink: #edf2ff;
  --note-bg: #fff7df;
  --note-border: #ecc75f;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #20283a;
  color: #fff;
  padding: 24px 18px;
}

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

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: #ffd166;
  color: #20283a;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span:last-child {
  margin-top: 3px;
  color: #b8c3d9;
  font-size: 13px;
}

.info-stack {
  display: grid;
  gap: 10px;
}

.info-stack section {
  min-height: 74px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #eef4ff;
  padding: 12px;
}

.info-stack span {
  color: #ffd166;
  font-size: 13px;
  font-weight: 700;
}

.info-stack strong {
  line-height: 1.35;
}

.workspace {
  padding: 24px;
  min-width: 0;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.15;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-button,
.run-button,
.nav-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 44px;
  height: 44px;
  background: #e8edf6;
  color: var(--ink);
  font-size: 22px;
}

.run-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.nav-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: #e8edf6;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.run-button:hover,
.icon-button:hover,
.nav-button:hover {
  filter: brightness(0.96);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-strip > div {
  min-height: 72px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.exercise-brief {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
}

.exercise-brief[hidden] {
  display: none;
}

.exercise-brief h2 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.3;
}

.exercise-brief p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.coding-area {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.editor-stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.editor-card,
.output-panel,
.learning-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.editor-toolbar,
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 50px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.editor-toolbar span,
.panel-header span {
  color: var(--muted);
  font-size: 13px;
}

.traffic {
  display: flex;
  gap: 6px;
}

.traffic span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff6b6b;
}

.traffic span:nth-child(2) {
  background: #ffd166;
}

.traffic span:nth-child(3) {
  background: #5ec77e;
}

.editor-grid {
  display: grid;
  grid-template-columns: 48px minmax(360px, 1fr) minmax(220px, 320px);
  height: min(68vh, 720px);
  min-height: 520px;
  background: var(--code-bg);
  overflow: hidden;
}

.line-numbers,
#codeInput,
.code-highlights,
.annotations {
  margin: 0;
  padding: 18px 0;
  font: 15px/24px Consolas, "Courier New", monospace;
}

.line-numbers {
  color: #738099;
  text-align: right;
  user-select: none;
  overflow: hidden;
  height: 100%;
  min-height: 0;
  padding-right: 8px;
}

.line-number-row {
  height: 24px;
  line-height: 24px;
}

.code-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: transparent;
}

.code-highlights {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: transparent;
  pointer-events: none;
  white-space: pre;
  z-index: 0;
}

.highlight-line {
  min-height: 24px;
  padding: 0 14px;
  min-width: max-content;
}

.highlight-line.has-error {
  background: rgba(191, 52, 52, 0.34);
  box-shadow: inset 4px 0 0 #ff6b6b;
}

.error-column {
  background: rgba(255, 210, 77, 0.72);
  border-bottom: 2px solid #ffd24d;
}

.virtual-column {
  display: inline-block;
  min-width: 9px;
}

.matched-brace {
  background: rgba(94, 199, 126, 0.78);
  border: 1px solid #5ec77e;
  border-radius: 3px;
}

#codeInput {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding-left: 14px;
  padding-right: 14px;
  background: transparent;
  color: var(--code-ink);
  caret-color: var(--code-ink);
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

.annotations {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  background: #1d2230;
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

.annotation-line {
  min-height: 24px;
  padding: 0 10px;
  color: transparent;
}

.annotation-line.has-note {
  color: #362a08;
}

.note-pill {
  display: inline-block;
  max-width: 100%;
  margin-right: 6px;
  padding: 2px 8px;
  border: 1px solid var(--note-border);
  border-radius: 8px;
  background: var(--note-bg);
  color: #382b06;
  font: 13px/18px "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  white-space: normal;
}

.note-pill.warning {
  border-color: #efb84a;
  background: #fff4d6;
}

.note-pill.error {
  border-color: #f0a1a1;
  background: #ffe7e7;
  color: #651c1c;
}

.run-button:disabled {
  cursor: wait;
  opacity: 0.74;
}

.output-panel {
  min-height: 320px;
  display: grid;
  gap: 12px;
}

.io-card {
  border-bottom: 1px solid var(--line);
}

.learning-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.1fr);
  gap: 0;
}

.chat-card {
  min-width: 0;
}

.chat-card:first-child {
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr) auto;
}

.learning-panel .chat-card + .chat-card {
  border-left: 1px solid var(--line);
}

.compact-header {
  min-height: 42px;
}

.io-textarea,
.runtime-output,
.chat-textarea {
  width: 100%;
  min-height: 86px;
  margin: 0;
  border: 0;
  outline: 0;
  padding: 12px 14px;
  background: #f8fafc;
  color: var(--ink);
  font: 14px/21px Consolas, "Courier New", monospace;
  resize: vertical;
}

.io-textarea {
  border-bottom: 1px solid var(--line);
}

.runtime-output {
  max-height: 150px;
  overflow: auto;
  white-space: pre-wrap;
}

.chat-textarea {
  min-height: 92px;
  border-bottom: 1px solid var(--line);
}

.ask-button {
  width: calc(100% - 24px);
  min-height: 38px;
  margin: 10px 12px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.ask-button:hover {
  filter: brightness(0.96);
}

.advice-box {
  min-height: 169px;
  padding: 14px;
  color: var(--ink);
  line-height: 1.6;
  background: #f8fafc;
}

.advice-box p {
  margin: 0 0 10px;
}

.advice-box p:last-child {
  margin-bottom: 0;
}

.advice-box strong {
  color: var(--accent-dark);
}

.output-box {
  height: 360px;
  padding: 16px;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.diagnostic-card {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid #f0a1a1;
  border-radius: 8px;
  background: #fff5f5;
  color: var(--ink);
  white-space: normal;
}

.diagnostic-card:last-child {
  margin-bottom: 0;
}

.diagnostic-card h2 {
  margin: 0 0 8px;
  color: var(--danger);
  font-size: 16px;
  line-height: 1.35;
}

.diagnostic-card p {
  margin: 7px 0;
}

.diagnostic-card strong {
  color: #651c1c;
}

.knowledge-point {
  padding-top: 8px;
  border-top: 1px solid #f4cccc;
}

.output-box.success {
  color: var(--success);
}

.output-box.error {
  color: var(--danger);
}

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

  .sidebar {
    padding: 16px;
  }

  .info-stack {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .coding-area,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .exercise-brief {
    flex-direction: column;
  }

  .learning-panel {
    grid-template-columns: 1fr;
  }

  .learning-panel .chat-card + .chat-card {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .editor-grid {
    grid-template-columns: 42px minmax(280px, 1fr);
  }

  .annotations {
    grid-column: 1 / -1;
    min-height: 120px;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 16px;
  }

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

  .actions {
    justify-content: space-between;
  }

  .run-button {
    flex: 1;
    justify-content: center;
  }

  .info-stack {
    grid-template-columns: 1fr;
  }
}
