:root {
  --bg: #f3f4f6;
  --bg-soft: #eceff3;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --surface-emphasis: #f3f6fa;
  --text: #141821;
  --text-sub: #5c6573;
  --line: rgba(20, 24, 33, 0.12);
  --line-strong: rgba(20, 24, 33, 0.2);
  --accent: #0a84ff;
  --accent-strong: #0064d1;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --success: #187e41;
  --danger: #bf1f3c;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 12px 34px rgba(11, 22, 34, 0.1);
  --shadow-soft: 0 6px 18px rgba(11, 22, 34, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease: 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI",
    sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(248, 249, 251, 0.95)),
    linear-gradient(90deg, rgba(130, 143, 159, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(130, 143, 159, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 84px 84px, 84px 84px, auto;
  letter-spacing: 0;
}

.shell {
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 48;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px) saturate(120%);
}

.topbar-left {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(160deg, #1388ff, #0064d1);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 8px 16px rgba(0, 100, 209, 0.22);
}

.topbar-left h1 {
  margin: 0;
  font-size: clamp(19px, 2.1vw, 30px);
  line-height: 1.08;
  font-weight: 670;
  color: #0f1520;
}

.topbar-left p {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--text-sub);
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.status-chip {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.78);
}

.status-chip span {
  font-size: 12px;
  color: var(--text-sub);
}

.status-chip strong {
  font-size: 13px;
  font-weight: 620;
  color: #1a2432;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.student-workbench {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(400px, 1fr);
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.graph-stage {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f7f9fc);
}

.searchbar {
  width: min(540px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

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

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(10, 132, 255, 0.05), rgba(10, 132, 255, 0));
}

.metric-item {
  min-width: 0;
  padding: 9px 12px;
  border-right: 1px solid var(--line);
}

.metric-item:last-child {
  border-right: 0;
}

.metric-item span {
  display: block;
  font-size: 12px;
  color: var(--text-sub);
}

.metric-item strong {
  display: block;
  margin-top: 5px;
  font-size: 27px;
  font-weight: 660;
  line-height: 1.1;
}

.graph-canvas {
  min-height: 0;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(10, 132, 255, 0.03), rgba(10, 132, 255, 0.01)),
    linear-gradient(rgba(56, 86, 122, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 86, 122, 0.06) 1px, transparent 1px),
    #fbfcff;
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.selected-line {
  min-height: 52px;
  max-height: 86px;
  overflow: auto;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px 10px;
  background: #fcfdff;
}

.tag {
  border: 1px solid rgba(10, 132, 255, 0.28);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  color: #0456ab;
  background: var(--accent-soft);
}

.learning-dock {
  min-height: 0;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  overflow: hidden;
}

.dock-tabs {
  min-width: 0;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px;
  background: linear-gradient(180deg, #f3f6fb, #fafbfc);
}

.dock-tab {
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 42px;
  padding: 8px 8px;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 620;
  color: var(--text-sub);
  text-align: center;
  cursor: pointer;
  transition:
    color var(--ease),
    border-color var(--ease),
    background var(--ease),
    transform var(--ease);
}

.dock-tab:hover {
  color: #16345b;
  border-color: rgba(10, 132, 255, 0.22);
}

.dock-tab.active {
  color: #ffffff;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 16px rgba(0, 100, 209, 0.24);
}

.dock-content,
.teacher-pane-wrap {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px;
}

.dock-pane {
  display: none;
}

.dock-pane.active {
  display: block;
  animation: fade-in 220ms ease;
}

.dock-pane h2 {
  margin: 0 0 10px;
  font-size: 19px;
  font-weight: 650;
}

.dock-pane h3 {
  margin: 15px 0 8px;
  font-size: 14px;
  color: #2f3a49;
}

.plain-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-emphasis);
  padding: 10px;
  font-size: 14px;
  line-height: 1.58;
}

.plain-box.empty {
  color: var(--text-sub);
}

.result-item,
.review-item,
.node-item,
.source-item,
.latest-item,
.provider-item {
  padding: 10px 0;
  border-top: 1px dashed color-mix(in srgb, var(--line-strong) 52%, transparent);
}

.result-item:first-child,
.review-item:first-child,
.node-item:first-child,
.source-item:first-child,
.latest-item:first-child,
.provider-item:first-child {
  border-top: 0;
}

.quick-link {
  border: 0;
  padding: 0;
  font: inherit;
  color: #005ebf;
  background: transparent;
  text-decoration: underline;
  cursor: pointer;
}

.inline-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.mini-text {
  font-size: 12px;
  color: var(--text-sub);
}

.input,
.textarea,
.btn,
.select {
  font: inherit;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  background: #ffffff;
  color: var(--text);
}

.textarea {
  min-height: 116px;
  resize: vertical;
  line-height: 1.52;
}

.textarea.tall {
  min-height: 220px;
}

.select {
  width: 148px;
}

.btn {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  min-height: 40px;
  padding: 7px 13px;
  font-size: 14px;
  font-weight: 620;
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform var(--ease),
    border-color var(--ease),
    filter var(--ease);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.secondary {
  background: #f6f8fb;
  color: #2a3f5a;
}

.btn.primary {
  border-color: transparent;
  color: #ffffff;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 16px rgba(0, 100, 209, 0.22);
}

.btn:disabled {
  opacity: 0.62;
  cursor: wait;
  transform: none;
}

.input:focus,
.textarea:focus,
.select:focus,
.btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 48%, transparent);
  outline-offset: 1px;
}

.source-list {
  margin-top: 10px;
  font-size: 13px;
  color: #475668;
}

.correct {
  color: var(--success);
  font-weight: 700;
}

.wrong {
  color: var(--danger);
  font-weight: 700;
}

.teacher-shell .topbar-right {
  gap: 10px;
}

.teacher-studio {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.teacher-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  overflow: hidden;
}

.teacher-tabs {
  border-right: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px;
  flex-direction: row;
  gap: 8px;
}

.teacher-tabs .dock-tab {
  min-height: 38px;
  min-width: 126px;
  font-size: 13px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.editor-zone {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  padding: 11px;
}

.editor-zone h2 {
  margin: 0;
  font-size: 16px;
}

.editor-zone p {
  margin: 6px 0 8px;
  font-size: 12px;
  color: var(--text-sub);
}

.teacher-side {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  overflow: auto;
}

.control-zone {
  padding: 12px;
}

.control-zone h2 {
  margin: 0 0 10px;
  font-size: 19px;
}

.label {
  display: block;
  margin-top: 10px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 620;
}

.overview-strip {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-emphasis);
}

.overview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-top: 1px solid var(--line);
}

.overview-row:first-child {
  border-top: 0;
}

.student-preview {
  margin-top: 10px;
  width: 100%;
  height: min(72vh, 860px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.provider-pill {
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 620;
}

.provider-pill.ok {
  color: #1d6f35;
  background: rgba(30, 139, 79, 0.12);
}

.provider-pill.no {
  color: #8f2d39;
  background: rgba(191, 31, 60, 0.11);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(13, 20, 31, 0.36);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(460px, 92vw);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(18px) saturate(110%);
  box-shadow: 0 24px 66px rgba(12, 20, 31, 0.28);
}

.modal-panel h3 {
  margin: 0;
  font-size: 22px;
}

.modal-panel p {
  margin: 8px 0 12px;
  font-size: 14px;
  color: var(--text-sub);
}

.modal-error {
  margin-top: 10px;
  border: 1px solid rgba(191, 31, 60, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(191, 31, 60, 0.1);
  color: #8f2d39;
  padding: 9px;
  font-size: 13px;
}

.hidden {
  display: none;
}

.toast-host {
  position: fixed;
  right: 14px;
  bottom: calc(14px + var(--safe-bottom));
  z-index: 92;
  display: grid;
  gap: 8px;
}

.toast {
  min-width: 220px;
  max-width: 360px;
  border: 1px solid rgba(10, 132, 255, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(10, 132, 255, 0.12);
  color: #0a56a8;
  padding: 10px 12px;
  box-shadow: var(--shadow-soft);
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast.error {
  border-color: rgba(191, 31, 60, 0.3);
  background: rgba(191, 31, 60, 0.12);
  color: #8f2d39;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1280px) {
  .student-workbench {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(340px, 50vh) minmax(0, 1fr);
  }

  .teacher-studio {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

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

  .teacher-side {
    max-height: 40vh;
  }
}

@media (max-width: 920px) {
  .topbar {
    min-height: auto;
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-left {
    width: 100%;
  }

  .topbar-left h1 {
    font-size: clamp(18px, 5vw, 24px);
  }

  .topbar-left p {
    font-size: 12px;
  }

  .topbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .status-chip {
    flex: 1;
    justify-content: space-between;
    min-width: 0;
  }

  body[data-role="student"] .shell {
    padding-bottom: calc(78px + var(--safe-bottom));
  }

  body[data-role="student"] .student-workbench {
    gap: 10px;
    padding: 10px 10px 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 42vh) minmax(0, 1fr);
  }

  body[data-role="student"] .graph-stage {
    border-radius: 12px;
  }

  body[data-role="student"] .stage-toolbar {
    padding: 9px;
  }

  body[data-role="student"] .searchbar {
    width: 100%;
  }

  body[data-role="student"] .toolbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  body[data-role="student"] .toolbar-actions .btn {
    width: 100%;
  }

  body[data-role="student"] .metric-strip {
    grid-template-columns: repeat(4, minmax(118px, 1fr));
    overflow-x: auto;
    scrollbar-width: none;
  }

  body[data-role="student"] .metric-strip::-webkit-scrollbar {
    display: none;
  }

  body[data-role="student"] .metric-item {
    min-width: 118px;
    border-bottom: 0;
  }

  body[data-role="student"] .metric-item strong {
    font-size: 22px;
  }

  body[data-role="student"] .selected-line {
    min-height: 46px;
    max-height: 72px;
  }

  body[data-role="student"] .learning-dock {
    display: block;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    background: transparent;
  }

  body[data-role="student"] .learning-dock .dock-tabs {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--safe-bottom));
    z-index: 72;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: blur(16px) saturate(120%);
    box-shadow: 0 16px 34px rgba(8, 17, 28, 0.2);
  }

  body[data-role="student"] .learning-dock .dock-tab {
    min-height: 46px;
    min-width: 0;
    border-radius: 10px;
    padding: 5px 3px;
    font-size: 11px;
    font-weight: 640;
  }

  body[data-role="student"] .dock-content {
    height: 100%;
    padding: 0 0 calc(90px + var(--safe-bottom));
  }

  body[data-role="student"] .dock-pane {
    min-height: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    padding: 12px;
    box-shadow: var(--shadow-soft);
  }

  body[data-role="student"] .dock-pane h2 {
    font-size: 18px;
  }

  body[data-role="teacher"] .teacher-studio {
    overflow: auto;
    gap: 10px;
    padding: 10px;
  }

  body[data-role="teacher"] .teacher-main {
    min-height: 68vh;
  }

  body[data-role="teacher"] .teacher-tabs {
    padding: 7px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  body[data-role="teacher"] .teacher-tabs .dock-tab {
    min-width: 0;
  }

  body[data-role="teacher"] .teacher-pane-wrap {
    padding: 10px;
  }

  body[data-role="teacher"] .editor-zone {
    padding: 10px;
  }

  body[data-role="teacher"] .textarea.tall {
    min-height: 176px;
  }

  body[data-role="teacher"] .teacher-side {
    max-height: none;
  }

  body[data-role="teacher"] .student-preview {
    height: min(58vh, 640px);
  }

  body[data-role="teacher"] .topbar-right {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  body[data-role="teacher"] .topbar-right .btn {
    width: 100%;
  }

  .inline-tools {
    gap: 7px;
  }

  .input,
  .textarea,
  .select,
  .btn {
    min-height: 42px;
  }

  .select {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .logo-mark {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .topbar-left p {
    display: none;
  }

  body[data-role="student"] .student-workbench {
    grid-template-rows: minmax(232px, 40vh) minmax(0, 1fr);
  }

  body[data-role="student"] .searchbar {
    grid-template-columns: 1fr;
  }

  body[data-role="student"] .searchbar .btn {
    width: 100%;
  }

  body[data-role="student"] .learning-dock .dock-tabs {
    left: 8px;
    right: 8px;
    gap: 3px;
    padding: 5px;
  }

  body[data-role="student"] .learning-dock .dock-tab {
    min-height: 43px;
    font-size: 10px;
    letter-spacing: 0;
  }

  body[data-role="teacher"] .modal-panel {
    width: 94vw;
    padding: 14px;
  }

  .toast {
    min-width: 0;
    width: min(92vw, 360px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
