:root {
  --paper: #f6f3ec;
  --paper-quiet: #eee9df;
  --ink: #1f2a33;
  --ink-soft: #526070;
  --ink-faint: #7d8791;
  --surface: #fffefd;
  --surface-raised: #fbfaf7;
  --control: #f2eee6;
  --line: rgba(78, 88, 98, 0.22);
  --line-strong: rgba(37, 72, 98, 0.38);
  --blueprint: #245f84;
  --amber: #7a4b19;
  --sage: #50663a;
  --plum: #73516e;
  --danger: #a33c32;
  --focus: #1f6f9b;
  --grid: rgba(72, 92, 111, 0.09);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface-raised);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

button:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(31, 111, 155, 0.28);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(560px, 1fr) 350px;
  height: 100vh;
  overflow: hidden;
}

.side-panel,
.inspector {
  min-height: 0;
  padding: 20px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.brand-block {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(36, 95, 132, 0.35);
  border-radius: var(--radius-md);
  color: var(--blueprint);
  background: #e9f4fa;
  font-weight: 800;
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand-block p {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.35;
}

.panel-section {
  display: grid;
  gap: 10px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section.grow {
  grid-template-rows: auto 1fr auto;
}

.panel-section.compact {
  border-bottom: 0;
}

.section-title,
.eyebrow {
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 750;
}

.primary-btn {
  color: #fff;
  border-color: #245f84;
  background: var(--blueprint);
}

.primary-btn:hover {
  color: #fff;
  border-color: #164461;
  background: #1d526f;
}

.secondary-btn {
  color: var(--blueprint);
  border-color: rgba(36, 95, 132, 0.28);
  background: #eaf4f9;
}

.ghost-btn {
  background: transparent;
}

.danger-btn {
  margin-top: 8px;
  color: #fff;
  border-color: #8f2f28;
  background: var(--danger);
}

.danger-btn:hover {
  color: #fff;
  background: #8f2f28;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.button-grid button {
  min-height: 34px;
  font-weight: 750;
}

.quick-input,
.import-input {
  width: 100%;
  min-height: 230px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--control);
  resize: vertical;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.import-input {
  min-height: 82px;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.topbar h2,
.inspector-head h2 {
  margin-top: 4px;
  font-size: 22px;
  line-height: 1.1;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  background: var(--surface-raised);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle i {
  position: relative;
  width: 34px;
  height: 18px;
  border: 1px solid rgba(82, 96, 112, 0.3);
  border-radius: 999px;
  background: var(--control);
}

.mode-toggle i::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--ink-faint);
  transition: transform 140ms ease, background 140ms ease;
}

.mode-toggle input:checked + i {
  border-color: rgba(36, 95, 132, 0.35);
  background: #eaf4f9;
}

.mode-toggle input:checked + i::after {
  transform: translateX(16px);
  background: var(--blueprint);
}

.toolbar button {
  min-width: 36px;
  height: 34px;
  padding: 0 10px;
  font-weight: 800;
}

.zoom-label {
  min-width: 48px;
  color: var(--ink-soft);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.canvas-shell {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

.diagram-canvas {
  position: relative;
  width: 1800px;
  height: 1200px;
  overflow: hidden;
}

.canvas-scale {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

.relation-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.relation {
  pointer-events: auto;
  cursor: pointer;
}

.relation-hit {
  stroke: transparent;
  stroke-width: 20;
}

.relation-label,
.cardinality {
  fill: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
  pointer-events: none;
}

.cardinality {
  font-family: "JetBrains Mono", Consolas, monospace;
}

.class-card {
  position: absolute;
  width: 260px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 0 rgba(31, 42, 51, 0.03);
}

.class-card:active {
  cursor: grabbing;
}

.class-card.selected {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(31, 111, 155, 0.16);
}

.class-title {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.tone-blueprint .class-title {
  color: var(--blueprint);
  background: #eef6fb;
}

.tone-amber .class-title {
  color: var(--amber);
  background: #fff6e8;
}

.tone-sage .class-title {
  color: var(--sage);
  background: #f2f7ef;
}

.tone-plum .class-title {
  color: var(--plum);
  background: #f7f0f6;
}

.class-compartment {
  min-height: 34px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.class-compartment:last-child {
  border-bottom: 0;
}

.member-row {
  min-height: 22px;
  color: #313b46;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.attribute-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 5px;
}

.member-text {
  min-width: 0;
}

.key-chip {
  display: inline-flex;
  align-items: center;
  min-height: 16px;
  padding: 1px 5px;
  border: 1px solid rgba(36, 95, 132, 0.3);
  border-radius: 4px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 9px;
  font-weight: 850;
  line-height: 1;
}

.key-chip.pk {
  color: var(--blueprint);
  background: #eaf4f9;
}

.key-chip.fk {
  color: var(--amber);
  border-color: rgba(122, 75, 25, 0.3);
  background: #fff4df;
}

.fk-target {
  color: var(--ink-faint);
  font-size: 11px;
}

.member-row.muted {
  color: var(--ink-faint);
  font-style: italic;
}

.inspector-head {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.inspector-body {
  display: grid;
  gap: 14px;
  padding-top: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

.field input,
.field select,
.member-form input,
.member-form select {
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--control);
}

.split-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.member-editor {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-head h3 {
  font-size: 14px;
}

.editor-head button {
  width: 30px;
  height: 30px;
  font-weight: 900;
}

.member-form {
  display: grid;
  grid-template-columns: 98px 1fr;
  gap: 8px;
}

.member-form.simple {
  grid-template-columns: 1fr 34px;
}

.member-form input:nth-of-type(2),
.member-form input:nth-of-type(3) {
  grid-column: 1 / -1;
}

.member-form select:nth-of-type(2),
.member-form .wide-input {
  grid-column: 1 / -1;
}

.member-form.simple .wide-input {
  grid-column: auto;
}

.member-form.simple .mini-danger {
  grid-column: auto;
  min-height: 36px;
}

.mini-danger {
  grid-column: 1 / -1;
  min-height: 28px;
  color: var(--danger);
  border-color: rgba(163, 60, 50, 0.25);
  background: #fff2ee;
  font-weight: 850;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 14px;
  min-height: 260px;
  color: var(--ink-soft);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--blueprint);
  background: #eaf4f9;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-weight: 850;
}

.quiz-page {
  height: 100vh;
  overflow: auto;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

.quiz-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 20px;
  align-items: stretch;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 18px;
}

.quiz-hero h2 {
  margin-top: 6px;
  font-size: 32px;
  line-height: 1.05;
}

.quiz-hero p {
  max-width: 720px;
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.55;
}

.score-panel {
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.score-panel span,
.score-panel small {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

.score-panel strong {
  font-size: 34px;
  line-height: 1;
  color: var(--blueprint);
}

.score-panel button {
  margin-top: 8px;
  min-height: 34px;
  font-weight: 800;
}

.study-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 12px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 18px;
}

.study-card {
  min-height: 132px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.study-card h3 {
  color: var(--blueprint);
  font-size: 14px;
  line-height: 1.2;
}

.study-card p {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.45;
}

.moodle-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 32px;
  align-items: start;
}

.question-nav {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.question-nav h3 {
  margin-top: 2px;
  font-size: 18px;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.question-pill {
  min-width: 0;
  height: 38px;
  padding: 0;
  color: var(--ink-soft);
  font-weight: 850;
  background: var(--surface-raised);
}

.question-pill.current {
  color: #fff;
  border-color: var(--blueprint);
  background: var(--blueprint);
}

.question-pill.done {
  border-color: rgba(80, 102, 58, 0.36);
  color: var(--sage);
  background: #f2f7ef;
}

.question-pill.done.wrong {
  border-color: rgba(163, 60, 50, 0.32);
  color: var(--danger);
  background: #fff2ee;
}

.question-pill.current.done {
  color: #fff;
  background: var(--blueprint);
}

.quiz-status {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.quiz-status.compact {
  padding: 12px;
  background: var(--surface-raised);
}

.quiz-status.compact span,
.quiz-status.compact small {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

.quiz-status.compact strong {
  color: var(--blueprint);
  font-size: 24px;
  line-height: 1;
}

.quiz-status h3 {
  margin-top: 4px;
  font-size: 18px;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--control);
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blueprint);
  transition: width 160ms ease;
}

.question-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.moodle-question {
  min-height: 430px;
  align-content: start;
  padding: 24px;
}

.question-card.correct {
  border-color: rgba(80, 102, 58, 0.42);
}

.question-card.wrong {
  border-color: rgba(163, 60, 50, 0.42);
}

.question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.question-number,
.topic-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
}

.question-number {
  color: var(--blueprint);
  background: #eaf4f9;
}

.topic-chip {
  color: var(--amber);
  background: #fff4df;
}

.question-card h3 {
  font-size: 22px;
  line-height: 1.35;
}

.option-list {
  display: grid;
  gap: 8px;
}

.option-btn {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  text-align: left;
  background: var(--surface-raised);
}

.option-btn.picked {
  border-color: var(--blueprint);
  background: #eaf4f9;
}

.option-btn.answer {
  border-color: rgba(80, 102, 58, 0.45);
  background: #f2f7ef;
}

.option-letter {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--ink-soft);
  background: var(--control);
  font-size: 12px;
  font-weight: 850;
}

.feedback {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  background: var(--paper);
  font-size: 13px;
  line-height: 1.45;
}

.question-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.question-actions button {
  width: auto;
  min-width: 120px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 10;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(31, 42, 51, 0.12);
  font-weight: 750;
}

@media (max-width: 1240px) {
  body {
    min-width: 980px;
  }

  .app-shell {
    grid-template-columns: 270px minmax(520px, 1fr) 320px;
  }
}
