:root {
  --ink: #162033;
  --muted: #687386;
  --line: #dfe4ec;
  --panel: #ffffff;
  --soft: #f5f7fa;
  --accent: #3157d5;
  --accent-dark: #2444b2;
  --accent-soft: #edf1ff;
  --success: #20a56b;
  --left-pane: 68%;
  color-scheme: light;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e9edf3;
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(560px, var(--left-pane)) 10px minmax(330px, 1fr);
  width: 100vw;
  height: 100vh;
  background: var(--panel);
}

.circuit-pane,
.tutor-pane {
  min-width: 0;
  min-height: 0;
}

.circuit-pane {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 48px;
  background: #eef2f7;
}

.tutor-pane {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto auto auto auto auto;
  background: #f9fafc;
  border-left: 1px solid #edf0f4;
}

.tutor-header { grid-row: 1; }
.messages { grid-row: 2; }
.lesson-card { grid-row: 3; }
.upload-preview { grid-row: 4; }
.generation-card { grid-row: 5; }
.context-strip { grid-row: 6; }
.composer { grid-row: 7; }

.pane-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.pane-header h1,
.pane-header h2 {
  margin: 1px 0 0;
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.eyebrow {
  margin: 0;
  color: #8791a2;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.15em;
}

.brand-mark {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--ink);
}

.brand-mark span {
  position: absolute;
  width: 6px;
  height: 6px;
  border: 2px solid #fff;
  border-radius: 50%;
}

.brand-mark span:nth-child(1) { left: 7px; top: 7px; }
.brand-mark span:nth-child(2) { right: 6px; top: 14px; }
.brand-mark span:nth-child(3) { left: 8px; bottom: 6px; }

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  content: "";
  height: 2px;
  background: #8ea2ff;
  transform-origin: left center;
}

.brand-mark::before {
  left: 12px;
  top: 12px;
  width: 14px;
  transform: rotate(27deg);
}

.brand-mark::after {
  left: 12px;
  bottom: 11px;
  width: 14px;
  transform: rotate(-27deg);
}

.circuit-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c4cad5;
  box-shadow: 0 0 0 4px #f0f2f5;
}

.status-dot.ready {
  background: var(--success);
  box-shadow: 0 0 0 4px #e5f6ef;
}

.circuit-stage {
  min-height: 0;
  margin: 14px 14px 0;
  overflow: hidden;
  border: 1px solid #d8dde6;
  border-radius: 12px 12px 0 0;
  background: #fff;
  box-shadow: 0 12px 32px rgba(34, 45, 67, 0.08);
}

.circuit-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.circuit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 14px 12px;
  padding: 0 14px;
  border: 1px solid #d8dde6;
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  box-shadow: 0 10px 24px rgba(34, 45, 67, 0.05);
}

.circuit-footer strong {
  margin-left: 8px;
  color: var(--ink);
  font-size: 12px;
}

.footer-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.footer-hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.splitter {
  position: relative;
  z-index: 5;
  cursor: col-resize;
  background: #e7eaf0;
}

.splitter span {
  position: absolute;
  left: 3px;
  top: 50%;
  width: 4px;
  height: 42px;
  border-radius: 4px;
  background: #b8c0cd;
  transform: translateY(-50%);
}

.splitter:hover span,
.workspace.resizing .splitter span {
  background: var(--accent);
}

.tutor-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, #4266df, #243faa);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 0 7px 18px rgba(49, 87, 213, 0.24);
}

.llm-status {
  margin-left: auto;
  padding: 4px 8px;
  border: 1px solid #d8def5;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #4b61ba;
  font-size: 10px;
  font-weight: 700;
}

.llm-status.ready {
  border-color: #bfe5d1;
  background: #ecfaf3;
  color: #248157;
}

.llm-status.error {
  border-color: #f0c7c7;
  background: #fff1f1;
  color: #b44747;
}

.context-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 14px 0;
  padding: 10px 12px;
  border: 1px solid #dbe1f6;
  border-radius: 10px;
  background: var(--accent-soft);
}

.context-strip > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.context-label {
  color: #7380a8;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.context-strip strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.context-strip button {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(49, 87, 213, 0.1);
  color: #5a6ba9;
  cursor: pointer;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 20px 16px 12px;
  scroll-behavior: smooth;
}

.message {
  max-width: 92%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 13px;
  font-size: 13px;
  line-height: 1.65;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
}

.message-label {
  margin-bottom: 4px;
  color: #7a8497;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.agent-message {
  border: 1px solid #e0e4eb;
  border-top-left-radius: 4px;
  background: #fff;
  box-shadow: 0 5px 14px rgba(39, 51, 74, 0.05);
}

.agent-message.thinking p::after {
  content: "";
  display: inline-block;
  width: 16px;
  height: 4px;
  margin-left: 7px;
  border-radius: 4px;
  background: linear-gradient(90deg, #9aa5bc 25%, transparent 25% 40%, #9aa5bc 40% 65%, transparent 65% 80%, #9aa5bc 80%);
  animation: thinking-pulse 1s ease-in-out infinite;
}

@keyframes thinking-pulse {
  50% { opacity: 0.35; }
}

.user-message {
  margin-left: auto;
  border-bottom-right-radius: 4px;
  background: var(--ink);
  color: #fff;
}

.user-message .message-label {
  color: #aeb7c7;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 16px;
}

.quick-actions button {
  padding: 8px 10px;
  border: 1px solid #d8deea;
  border-radius: 9px;
  background: #fff;
  color: #465167;
  font-size: 11px;
  cursor: pointer;
}

.quick-actions button:hover {
  border-color: #aab8ef;
  color: var(--accent);
}

.lesson-card {
  margin: 0 14px 12px;
  padding: 14px;
  border: 1px solid #dce2ee;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(39, 51, 74, 0.07);
}

.lesson-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.lesson-heading span {
  color: #7d8799;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lesson-heading h3 {
  margin: 3px 0 0;
  font-size: 14px;
}

.lesson-progress {
  width: 74px;
  height: 4px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 4px;
  background: #edf0f5;
}

.lesson-progress span {
  display: block;
  width: 25%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.lesson-card > p {
  margin: 12px 0 9px;
  color: #4d586d;
  font-size: 12px;
  line-height: 1.6;
}

.equation {
  min-height: 34px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 7px 7px 0;
  background: #f4f6fc;
  color: #283a7b;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.lesson-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.lesson-controls button {
  min-height: 34px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.lesson-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.secondary-button {
  border: 1px solid #dce1ea;
  background: #fff;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.upload-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 10px;
  padding: 9px;
  border: 1px solid #dde2eb;
  border-radius: 10px;
  background: #fff;
}

.upload-preview img {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  object-fit: cover;
  background: #eef1f5;
}

.upload-preview div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.upload-preview strong,
.upload-preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-preview strong { font-size: 11px; }
.upload-preview span { color: var(--muted); font-size: 10px; }

.generation-card {
  margin: 10px 14px 0;
  padding: 12px;
  border: 1px solid #cfd9ff;
  border-radius: 12px;
  background: linear-gradient(145deg, #f5f7ff, #eef2ff);
  box-shadow: 0 8px 20px rgba(49, 87, 213, 0.08);
}

.generation-heading,
.generation-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.generation-heading > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.generation-heading span,
.generation-meta {
  color: var(--muted);
  font-size: 9px;
}

.generation-heading strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.generation-mode {
  flex: none;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(49, 87, 213, 0.1);
  color: var(--accent) !important;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.generation-card p {
  margin: 9px 0 6px;
  color: #3b455a;
  font-size: 11px;
  line-height: 1.55;
}

.generation-controls {
  justify-content: flex-end;
  margin-top: 10px;
}

.generation-controls button {
  min-width: 88px;
}

.composer {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: end;
  gap: 8px;
  margin: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer textarea {
  width: 100%;
  max-height: 112px;
  min-height: 38px;
  resize: none;
  padding: 9px 11px;
  border: 1px solid #d7dde7;
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  font-size: 12px;
  line-height: 18px;
}

.composer textarea:focus {
  border-color: #99a9e5;
  box-shadow: 0 0 0 3px rgba(49, 87, 213, 0.09);
}

.composer textarea:disabled,
.send-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.upload-button,
.send-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
}

.upload-button {
  border: 1px solid #d8dee8;
  background: #f7f8fa;
  color: #58647a;
  font-size: 20px;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.send-button {
  border: 0;
  background: var(--ink);
  color: #fff;
  font-size: 18px;
}

.send-button:hover {
  background: #27344b;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(520px, 58vh) minmax(480px, 1fr);
    width: 100%;
    height: auto;
    min-height: 100vh;
  }

  .splitter {
    display: none;
  }

  .circuit-pane {
    min-height: 520px;
  }

  .tutor-pane {
    min-height: 480px;
  }
}
