:root {
  --page: #FAFBFC;
  --surface: #FFFFFF;
  --border: #F1F5F9;
  --border-strong: #E2E8F0;
  --heading: #0F172A;
  --body: #334155;
  --label: #64748B;
  --faint: #94A3B8;
  --brand: #3B5FEB;
  --brand-dark: #2541D0;
  --brand-tint: #EEF4FF;
  --brand-tint-strong: #D9E6FF;
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, monospace;
  --font-logo: 'Space Grotesk', 'DM Sans', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 14px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
  position: sticky;
  top: 0;
  backdrop-filter: blur(6px);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-logo);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--heading);
}
.brand span { color: var(--label); font-size: 16px; font-weight: 500; letter-spacing: 0; }
.brand:hover { color: var(--heading); }

#nav { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#nav a:not(.btn) {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--label);
  font-size: 13px;
  font-weight: 500;
}
#nav a:not(.btn):hover { background: #F8FAFC; color: var(--heading); }
/* Header actions follow ignitae's header: gradient CTA, ghost secondary. */
#nav .btn-primary { height: 32px; padding: 0 16px; color: #FFFFFF; }
#nav .btn-primary:hover { filter: brightness(1.25); color: #FFFFFF; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--label); }
.btn-ghost:hover { background: #F8FAFC; color: var(--heading); }

main#app { width: 1200px; max-width: 100%; margin: 0 auto; padding: 32px 24px; }

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
}
.card h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; color: var(--heading); }
.card p { margin: 0; font-size: 13.5px; color: var(--label); line-height: 1.5; }
.card .topics { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #F8FAFC;
  color: var(--label);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary {
  border: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(59, 95, 235, 0.3);
}

.badge {
  padding: 2px 7px;
  border-radius: 6px;
  background: #F8FAFC;
  color: var(--label);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-easy { background: rgba(34, 197, 94, 0.15); color: #16A34A; }
.badge-medium { background: rgba(245, 158, 11, 0.15); color: #D97706; }
.badge-hard { background: rgba(239, 68, 68, 0.15); color: #DC2626; }
.badge-pass { background: rgba(34, 197, 94, 0.15); color: #16A34A; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 24px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 6px 14px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--label);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.pill.active {
  border-color: var(--brand);
  background: linear-gradient(135deg, var(--brand-tint), var(--brand-tint-strong));
  color: var(--brand);
  font-weight: 600;
}
.filters input[type="text"] {
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #F8FAFC;
  font-size: 13px;
  color: var(--body);
  width: 260px;
  font-family: inherit;
}

main#app:has(.workspace) { width: 100%; padding: 0; max-width: 100%; }
.workspace {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr) 360px;
  gap: 0;
  min-height: calc(100vh - 56px);
  background: var(--surface);
}
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; min-height: auto; }
  .workspace-editor { border-right: none !important; }
}

.instructions {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.instructions h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; color: var(--heading); }
.instructions .back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--label); }
.instructions .ex-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.instructions .topic { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.instructions > .btn { align-self: flex-start; margin-top: auto; }

.instructions-details summary {
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--heading);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.instructions-details summary::-webkit-details-marker { display: none; }
.instructions-details summary::before { content: '▸'; display: inline-block; width: 1em; color: var(--label); }
.instructions-details[open] summary::before { content: '▾'; }
.instructions-details[open] summary { border-bottom: none; }
.instructions-details > :not(summary) { margin-top: 8px; }

.workspace-main { display: contents; }
.workspace-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.workspace-results {
  background: var(--page);
  padding: 20px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tab-row { display: flex; align-items: center; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid var(--border-strong); overflow-x: auto; }
.tabs { display: flex; gap: 4px; }
.tab {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  margin-bottom: -1px;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--label);
  cursor: pointer;
}
.tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }
.tab .lock { font-size: 11px; }
.tab-row-actions { margin-left: auto; flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 0 6px 16px; }
.kbd-hint { font-size: 12px; color: var(--faint); white-space: nowrap; }
.kbd { font-family: var(--font-mono); font-size: 11px; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); color: var(--label); }
.tab-row-actions .btn-primary { height: 32px; }
.reset-btn-mobile { display: none; }

.toolbar { padding: 8px 16px 0; }

.editor-host { position: relative; flex: 1; min-height: 0; }
.readonly-chip {
  position: absolute;
  top: 12px;
  right: 16px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--border);
  color: var(--label);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.editor {
  width: 100%;
  height: 100%;
  min-height: 320px;
  resize: none;
  border: none;
  padding: 20px 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
  color: var(--heading);
  background: var(--surface);
}
.editor[readonly] { background: #F8FAFC; }

.results { display: flex; flex-direction: column; gap: 14px; }
.results h4 { margin: 0; font-size: 16px; font-weight: 700; color: var(--heading); }
.results h4.fail { color: #DC2626; }
.results h4.pass { color: #16A34A; }
.progress { height: 6px; border-radius: 9999px; background: var(--border); overflow: hidden; }
.progress-bar { height: 100%; background: #22C55E; }
.test { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px; padding: 8px 10px; border-radius: 10px; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--body); }
.test.pass strong { color: #22C55E; }
.test.fail { flex-direction: column; border-color: rgba(239, 68, 68, 0.35); }
.test.fail strong { color: #EF4444; }
.test .message {
  margin-left: 24px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #FEF2F2;
  color: #B91C1C;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  width: 100%;
}

.console {
  font-family: var(--font-mono);
  font-size: 12px;
  background: #0F172A;
  color: #CBD5E1;
  border-radius: 10px;
  padding: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.error { color: #DC2626; font-size: 13px; white-space: pre-wrap; }

.pass { color: #16A34A; font-weight: 600; }
.fail { color: #DC2626; font-weight: 600; }

.section-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.section-header h2 { margin: 0; }
.section-header .note { font-size: 13px; color: var(--faint); }

.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar-placeholder { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); }

.select-role {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--heading);
  font-size: 13px;
  font-family: inherit;
}

@media (max-width: 1100px) {
  .instructions { border-right: none; border-bottom: 1px solid var(--border); }
  .tab-row { padding: 0 8px; }
  .tab-row-actions { position: sticky; bottom: 0; width: 100%; margin-left: 0; padding: 10px 16px; background: rgba(255, 255, 255, 0.92); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); order: 2; }
  .tab-row-actions .btn-primary { flex: 1; height: 44px; }
  .kbd-hint { display: none; }
  .editor { min-height: 260px; }
  .reset-btn { display: none; }
  .reset-btn-mobile { display: inline-flex; height: 44px; padding: 0 14px; }
}

.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-row label { font-size: 12px; font-weight: 600; color: var(--label); }
.form-row input, .form-row select, .form-row textarea {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
}

.toolbar { display: flex; align-items: center; gap: 8px; }
.toolbar h2 { margin: 0; margin-right: auto; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; color: var(--heading); }

.table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}
.table th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); border-bottom: 1px solid var(--border-strong); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--body); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

.author-edit { display: flex; flex-direction: column; gap: 20px; }
.author-edit h3 { margin: 0; font-size: 16px; font-weight: 700; color: var(--heading); }

.file-block { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px; border-radius: 14px; border: 1px solid var(--border-strong); background: var(--surface); }
.file-block .toolbar input[type="text"], .file-block .toolbar input:not([type]) { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); font-family: var(--font-mono); font-size: 13px; }
.file-block label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--body); }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.two-col h5 { margin: 0 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }
.two-col .editor { min-height: 150px; border-radius: 8px; border: 1px solid var(--border); }

#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--heading);
  color: #FFFFFF;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.toast-error { background: #DC2626; }
