:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #17211b;
  --muted: #637066;
  --line: #d9e0da;
  --accent: #176b5b;
  --accent-2: #d84f32;
  --soft: #eef5f1;
  --code-bg: #101815;
  --code-ink: #d7efe5;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 18px;
  max-width: 1680px;
}

.eyebrow,
.zone-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4.8rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  margin-top: 16px;
  font-size: 1rem;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.mode-button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  cursor: pointer;
}

.mode-button:last-child {
  border-right: 0;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(340px, 0.9fr) minmax(320px, 0.8fr);
  gap: 14px;
  max-width: 1680px;
  margin: 0 auto;
  align-items: stretch;
}

.panel {
  display: flex;
  min-height: calc(100vh - 132px);
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

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

select,
textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

select {
  min-width: 150px;
  padding: 9px 10px;
}

.select-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 8px;
  min-width: min(360px, 100%);
}

.select-stack span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.select-stack select {
  width: 100%;
}

.field-label,
.optional-fields span {
  display: block;
  margin: 14px 16px 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.code-wrap {
  position: relative;
  min-height: 350px;
  margin: 0 16px;
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}

#code-highlight,
#code-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 16px;
  border: 0;
  font: 0.92rem/1.55 "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

#code-highlight {
  color: var(--code-ink);
  pointer-events: none;
}

#code-input {
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: #fff;
  outline: none;
}

#code-input::selection {
  background: rgba(255, 255, 255, 0.25);
}

.kw {
  color: #8bd3ff;
}

.fn {
  color: #ffe08a;
}

.num {
  color: #ffb28b;
}

.comment {
  color: #8aa49a;
}

.optional-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px 16px;
}

.optional-fields label {
  min-width: 0;
}

.optional-fields span {
  margin: 12px 0 6px;
}

.optional-fields textarea,
.chat-form textarea {
  width: 100%;
  resize: vertical;
  padding: 10px;
}

.messages {
  flex: 1;
  padding: 16px;
  overflow: auto;
  background: linear-gradient(#ffffff, #f8faf8);
}

.message {
  max-width: 88%;
  margin-bottom: 12px;
  padding: 11px 13px;
  border-radius: var(--radius);
  line-height: 1.45;
}

.message.agent {
  background: var(--soft);
  border: 1px solid #d6e7dd;
}

.message.student {
  margin-left: auto;
  background: #173c35;
  color: #fff;
}

.meta {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.chat-form button {
  align-self: end;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent-2);
  color: #fff;
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 700;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
}

.output-zone.locked {
  background: #fbfcfb;
}

#output-state {
  border-radius: 999px;
  background: #e9eeea;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 0.8rem;
  font-weight: 700;
}

.locked-output {
  display: grid;
  flex: 1;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.final-output {
  padding-bottom: 16px;
}

#corrected-code {
  width: calc(100% - 32px);
  min-height: 360px;
  margin: 0 16px;
  padding: 14px;
  background: var(--code-bg);
  color: var(--code-ink);
  font: 0.9rem/1.55 "Cascadia Code", Consolas, monospace;
  resize: vertical;
}

#learning-summary {
  margin: 8px 16px 0;
  line-height: 1.5;
}

.is-loading {
  opacity: 0.72;
}

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

  .panel {
    min-height: auto;
  }

  .chat-zone,
  .output-zone {
    min-height: 520px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

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

  .mode-switch,
  .select-stack,
  .chat-form,
  .optional-fields {
    grid-template-columns: 1fr;
  }

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

  select {
    width: 100%;
  }

  .code-wrap {
    min-height: 300px;
  }
}
