:root {
  --bg-deep: #0f0f10;
  --bg-page: #141415;
  --bg-card: #19191b;
  --bg-raised: #232325;
  --bg-raised-hover: #2a2a2d;
  --border-hairline: rgba(237, 237, 237, 0.08);
  --border-strong: rgba(237, 237, 237, 0.14);
  --text-primary: #ededed;
  --text-secondary: #a1a1a6;
  --text-muted: #85858b;
  --accent: #e5a93c;
  --accent-hover: #edb753;
  --accent-ink: #141415;
  --accent-soft: rgba(229, 169, 60, 0.14);
  --pass: #4cc38a;
  --pass-soft: rgba(76, 195, 138, 0.15);
  --fail: #e5484d;
  --fail-soft: rgba(229, 72, 77, 0.14);
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  color-scheme: dark;
}

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

code,
pre,
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* Layout shell */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-hairline);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border-hairline);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-name {
  font-size: 16px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 4px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-page);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-hairline);
}

.mode-tab {
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out), transform 120ms var(--ease-out);
}

.mode-tab:hover {
  color: var(--text-primary);
  background: rgba(237, 237, 237, 0.04);
}

.mode-tab:active {
  transform: scale(0.98);
}

.mode-tab.is-active {
  background: var(--bg-raised);
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-count {
  color: var(--accent);
  font-weight: 500;
}

.btn {
  height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-raised);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), transform 120ms var(--ease-out);
}

.btn:hover {
  background: var(--bg-raised-hover);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: rgba(237, 237, 237, 0.05);
  color: var(--text-primary);
  border-color: transparent;
}

/* Workspace grid */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: calc(100vh - 56px);
}

.sidebar {
  background: var(--bg-deep);
  border-right: 1px solid var(--border-hairline);
  padding: 16px 12px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
}

.sidebar-filter {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.filter-chip {
  flex: 1;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border-hairline);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out);
}

.filter-chip:hover {
  color: var(--text-primary);
  background: rgba(237, 237, 237, 0.04);
}

.filter-chip.is-active {
  background: var(--bg-raised);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.nav-section-label {
  margin: 20px 8px 8px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text-muted);
}

.nav-section-label:first-of-type {
  margin-top: 8px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  display: grid;
  grid-template-columns: 20px 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out);
}

.nav-item:hover {
  background: rgba(237, 237, 237, 0.04);
  color: var(--text-primary);
}

.nav-item.is-active {
  background: var(--bg-raised);
  color: var(--text-primary);
  border-color: var(--border-hairline);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.nav-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(237, 237, 237, 0.16);
  justify-self: center;
}

.nav-item.is-done .nav-status-dot {
  background: var(--pass);
}

.nav-item.is-active .nav-status-dot {
  background: var(--accent);
}

.nav-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.nav-title {
  font-size: 13px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main content */
.main-content {
  padding: 24px 32px 48px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.lesson-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.lesson-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.lab-tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.lab-tag.is-pass {
  color: var(--pass);
  background: var(--pass-soft);
  border-color: rgba(76, 195, 138, 0.25);
}

.lesson-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.lesson-goal {
  margin: 8px 0 0;
  font-size: 15px;
  line-height: 22px;
  color: var(--text-secondary);
  max-width: 68ch;
}

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

/* Two-column workbench */
.workbench-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 20px;
  align-items: start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  color: var(--text-muted);
}

.body-copy {
  margin: 0;
  font-size: 14px;
  line-height: 22px;
  color: var(--text-secondary);
}

/* Token keycaps */
.token-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(140px, auto) minmax(0, 1fr);
  align-items: baseline;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-page);
  border: 1px solid var(--border-hairline);
}

.keycap {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  color: var(--accent);
  white-space: nowrap;
  justify-self: start;
}

.token-meaning {
  font-size: 13px;
  line-height: 19px;
  color: var(--text-secondary);
}

/* Bug redline card */
.hint-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-page);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  line-height: 19px;
  color: var(--text-primary);
}

.pipe-toggle-row {
  padding: 8px 16px;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bug-card {
  border-color: rgba(229, 72, 77, 0.28);
  background: linear-gradient(180deg, rgba(229, 72, 77, 0.05) 0%, var(--bg-card) 48%);
}

.bug-code {
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bug-code.is-broken {
  color: #f38b8e;
  border-color: rgba(229, 72, 77, 0.25);
}

.trap-note {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid rgba(229, 169, 60, 0.25);
  font-size: 13px;
  line-height: 20px;
  color: var(--text-primary);
}

/* Terminal runner */
.terminal-card {
  padding: 0;
  overflow: hidden;
}

.terminal-bar {
  padding: 12px 16px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.terminal-cwd {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.terminal-cwd strong {
  color: var(--text-primary);
  font-weight: 500;
}

.terminal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.terminal-input-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-hairline);
  background: var(--bg-page);
}

.terminal-textarea {
  width: 100%;
  min-height: 76px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  resize: vertical;
  outline: none;
  transition: border-color 140ms var(--ease-out);
}

.terminal-textarea:focus {
  border-color: var(--accent);
}

.terminal-controls {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.shortcut-hint {
  font-size: 12px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.terminal-output {
  padding: 16px;
  background: var(--bg-deep);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.out-stdout {
  color: var(--text-primary);
}

.out-stderr {
  color: var(--fail);
}

.out-empty {
  color: var(--text-muted);
}

.verdict-banner {
  padding: 12px 16px;
  border-top: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.verdict-banner.is-pass {
  background: var(--pass-soft);
  color: var(--pass);
}

.verdict-banner.is-fail {
  background: var(--fail-soft);
  color: #f38b8e;
}

/* Pipe stages */
.pipe-stages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pipe-stage {
  border-radius: 8px;
  background: var(--bg-page);
  border: 1px solid var(--border-hairline);
  overflow: hidden;
}

.pipe-stage-head {
  padding: 8px 12px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
}

.pipe-stage-body {
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 160px;
  overflow: auto;
}

/* Fixture file & match inspector */
.fixture-table {
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-deep);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 20px;
}

.fixture-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  border-bottom: 1px solid rgba(237, 237, 237, 0.04);
}

.fixture-row:last-child {
  border-bottom: none;
}

.fixture-row.is-matched {
  background: rgba(76, 195, 138, 0.08);
}

.fixture-ln {
  padding: 4px 8px;
  text-align: right;
  color: var(--text-muted);
  border-right: 1px solid var(--border-hairline);
  user-select: none;
}

.fixture-row.is-matched .fixture-ln {
  color: var(--pass);
}

.fixture-code {
  padding: 4px 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.fixture-row.is-matched .fixture-code {
  color: var(--text-primary);
}

.match-hl {
  background: rgba(76, 195, 138, 0.25);
  color: #ffffff;
  border-radius: 3px;
  padding: 0 2px;
}

.vfs-tree {
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border-hairline);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 20px;
  color: var(--text-secondary);
  white-space: pre;
  overflow-x: auto;
}

/* Git Conflict Lab */
.git-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.git-node {
  padding: 16px;
  border-radius: 8px;
  background: var(--bg-page);
  border: 1px solid var(--border-hairline);
}

.git-node-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.git-node-desc {
  font-size: 13px;
  line-height: 19px;
  color: var(--text-secondary);
}

.conflict-editor {
  width: 100%;
  min-height: 132px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  resize: vertical;
  outline: none;
}

.conflict-editor:focus {
  border-color: var(--accent);
}

/* Exam Mode */
.exam-container {
  max-width: 820px;
  margin: 0 auto;
}

.exam-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 16px;
}

.stat-label {
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  line-height: 1;
  font-weight: 500;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-value.is-accent {
  color: var(--accent);
}

.option-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.option-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-hairline);
  background: var(--bg-page);
  color: var(--text-primary);
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out);
}

.option-btn:hover:not(:disabled) {
  background: var(--bg-raised);
  border-color: var(--border-strong);
}

.option-btn.is-correct {
  background: var(--pass-soft);
  border-color: rgba(76, 195, 138, 0.4);
}

.option-btn.is-wrong {
  background: var(--fail-soft);
  border-color: rgba(229, 72, 77, 0.4);
}

.option-key {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 2px;
}

/* Cheat sheet modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 11, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal-panel {
  width: 100%;
  max-width: 780px;
  max-height: 84vh;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

/* Sprawdzian sheet */
.sheet-container {
  max-width: 920px;
  margin: 0 auto;
}

.sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.sheet-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sheet-trees {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.sheet-tree-box {
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border-hairline);
}

.sheet-tree-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sheet-answer-box {
  width: 100%;
  min-height: 152px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 21px;
  resize: vertical;
  outline: none;
  margin-top: 12px;
}

.sheet-answer-box:focus {
  border-color: var(--accent);
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-page);
  border: 1px solid var(--border-hairline);
}

.check-row.is-ok {
  color: var(--pass);
  border-color: rgba(76, 195, 138, 0.25);
}

.check-row.is-bad {
  color: #f38b8e;
  border-color: rgba(229, 72, 77, 0.25);
}

.cheat-group {
  background: var(--bg-page);
  border: 1px solid var(--border-hairline);
  border-radius: 10px;
  padding: 16px;
}

.cheat-group h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.cheat-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(237, 237, 237, 0.05);
  font-size: 13px;
}

.cheat-row:last-child {
  border-bottom: none;
}

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

@media (max-width: 840px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border-hairline);
  }
  .main-content {
    padding: 20px 16px 40px;
  }
  .git-grid,
  .exam-stats,
  .modal-body,
  .sheet-trees {
    grid-template-columns: 1fr;
  }
  .brand-sub {
    display: none;
  }
}
