:root {
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'Cascadia Mono', 'SF Mono', Consolas, 'Liberation Mono', monospace;

  --bg: #0e1016;
  --bg-elev: #161a22;
  --bg-elev-2: #1d222c;
  --term-bg: #0a0c11;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);

  --ink: #e9e7e2;
  --ink-dim: #a2a5ad;
  --ink-faint: #6f737d;

  --accent: #5bc8a0;
  --accent-soft: rgba(91, 200, 160, 0.14);
  --accent-ink: #07130f;
  --warn: #e0b155;
  --warn-soft: rgba(224, 177, 85, 0.14);
  --danger: #e4756a;
  --danger-soft: rgba(228, 117, 106, 0.14);
  --info: #77a7f0;
  --info-soft: rgba(119, 167, 240, 0.14);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 14px 34px -18px rgba(0, 0, 0, 0.85);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

:root[data-theme='light'] {
  --bg: #f4f2ed;
  --bg-elev: #fffefb;
  --bg-elev-2: #ecebe4;
  --term-bg: #14171e;
  --line: rgba(20, 23, 30, 0.12);
  --line-strong: rgba(20, 23, 30, 0.24);

  --ink: #171a21;
  --ink-dim: #545861;
  --ink-faint: #83878f;

  --accent: #12775a;
  --accent-soft: rgba(18, 119, 90, 0.12);
  --accent-ink: #ffffff;
  --warn: #8a6112;
  --warn-soft: rgba(138, 97, 18, 0.12);
  --danger: #a8382c;
  --danger-soft: rgba(168, 56, 44, 0.12);
  --info: #2f5ea8;
  --info-soft: rgba(47, 94, 168, 0.12);

  --shadow-sm: 0 1px 2px rgba(20, 23, 30, 0.08);
  --shadow-md: 0 14px 34px -20px rgba(20, 23, 30, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
}

code {
  font-family: var(--font-mono);
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 40;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
}

.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.6rem clamp(0.7rem, 0.3rem + 1.4vw, 1.4rem);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand__mark {
  width: 30px;
  height: 30px;
  color: var(--accent);
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand__text b {
  font-size: 1.08rem;
}

.brand__text span {
  font-size: 0.74rem;
  color: var(--ink-faint);
}

.topbar__tools {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.lang {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
}

.lang__btn {
  padding: 0.28rem 0.6rem;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
}

.lang__btn[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease), background 0.18s var(--ease);
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--quiet {
  background: transparent;
}

.btn--icon {
  padding: 0.42rem;
}

.btn--tiny {
  padding: 0.28rem 0.6rem;
  font-size: 0.78rem;
}

.btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn--accent:hover:not(:disabled) {
  filter: brightness(1.08);
  color: var(--accent-ink);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.icon--sm {
  width: 14px;
  height: 14px;
}

:root .btn .icon--moon {
  display: none;
}

:root[data-theme='light'] .btn .icon--sun {
  display: none;
}

:root[data-theme='light'] .btn .icon--moon {
  display: block;
}

.app {
  display: grid;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.9rem;
  padding: 0.9rem clamp(0.6rem, 0.3rem + 1.2vw, 1.4rem);
  max-width: 1560px;
  margin: 0 auto;
  align-items: start;
}

.lesson {
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.lesson__no {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.lesson__title {
  font-size: 1.2rem;
  line-height: 1.25;
  margin-top: 0.2rem;
}

.lesson__lead {
  margin: 0.4rem 0 0;
  font-size: 0.86rem;
  color: var(--ink-dim);
}

.progress {
  height: 4px;
  margin-top: 0.7rem;
  border-radius: 2px;
  background: var(--bg-elev-2);
  overflow: hidden;
}

.progress__bar {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s var(--ease);
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  max-height: 30vh;
  overflow: auto;
}

.step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.28rem 0.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--ink-faint);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.step__no {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 0.66rem;
}

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

.step.is-current {
  background: var(--accent-soft);
  color: var(--ink);
}

.step.is-current .step__no {
  border-color: var(--accent);
  color: var(--accent);
}

.step.is-done {
  color: var(--ink-dim);
}

.step.is-done .step__no {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.step.is-done .step__no::after {
  content: '✓';
  font-size: 0.62rem;
}

.step.is-done .step__no {
  font-size: 0;
}

.step.is-drill .step__cmd {
  font-style: italic;
}

.task {
  padding: 0.8rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
}

.task.is-finished {
  border-left-color: var(--info);
}

.task__text {
  margin: 0;
  font-size: 0.88rem;
  white-space: pre-line;
}

.task__cmd {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.7rem;
  padding: 0.45rem 0.55rem;
  background: var(--term-bg);
  border-radius: var(--radius-sm);
}

.task__cmd-text {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  font-size: 0.82rem;
  color: #d6f5e7;
}

.task__hint {
  margin: 0.6rem 0 0;
  padding: 0.5rem 0.6rem;
  background: var(--info-soft);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--ink-dim);
}

.task__row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.task__done {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--accent);
}

.lesson__nav {
  display: flex;
  gap: 0.4rem;
  margin-top: auto;
}

.lesson__nav .btn:last-child {
  margin-left: auto;
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
}

.zone {
  display: flex;
  flex-direction: column;
  min-height: 232px;
  padding: 0.7rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}

.zone.is-hot {
  border-color: var(--accent);
  animation: zone-pulse 0.9s var(--ease);
}

@keyframes zone-pulse {
  0% {
    box-shadow: 0 0 0 0 var(--accent-soft);
  }
  60% {
    box-shadow: 0 0 0 8px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.zone__head {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed var(--line);
}

.zone__title {
  font-size: 0.86rem;
  letter-spacing: 0.01em;
}

.zone__sub {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zone__body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.55rem;
  overflow: auto;
  max-height: 260px;
}

.zone__empty {
  margin: auto 0;
  font-size: 0.76rem;
  color: var(--ink-faint);
  text-align: center;
  padding: 0.4rem;
}

.zone[data-zone='index']::before,
.zone[data-zone='local']::before,
.zone[data-zone='remote']::before {
  content: '→';
  position: absolute;
  margin-top: 100px;
  margin-left: -1.05rem;
  color: var(--ink-faint);
  font-size: 0.9rem;
  pointer-events: none;
}

.file {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-faint);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  will-change: transform;
}

.file__icon {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--ink-faint);
}

.file__name {
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file__badge {
  margin-left: auto;
  flex: none;
  font-size: 0.64rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.file[data-state='untracked'] {
  border-left-color: var(--danger);
}
.file[data-state='untracked'] .file__badge {
  color: var(--danger);
}

.file[data-state='modified'] {
  border-left-color: var(--warn);
}
.file[data-state='modified'] .file__badge {
  color: var(--warn);
}

.file[data-state='staged'] {
  border-left-color: var(--accent);
}
.file[data-state='staged'] .file__badge {
  color: var(--accent);
}

.file[data-state='clean'] {
  border-left-color: var(--info);
}

.file[data-state='ignored'] {
  opacity: 0.5;
  border-left-style: dashed;
}

.commit {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.38rem 0.5rem 0.38rem 1.4rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  will-change: transform;
}

.commit__dot {
  position: absolute;
  left: 0.5rem;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.commit + .commit::after {
  content: '';
  position: absolute;
  left: calc(0.5rem + 4px);
  top: -0.36rem;
  width: 1px;
  height: 0.36rem;
  background: var(--line-strong);
}

.commit__id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
}

.commit__msg {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.commit__tags {
  margin-left: auto;
  flex: none;
  display: flex;
  gap: 0.25rem;
}

.commit--remote .commit__dot {
  background: var(--info);
  box-shadow: 0 0 0 3px var(--info-soft);
}

.tag {
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--ink-dim);
  white-space: nowrap;
}

.tag--head {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.tag--remote {
  color: var(--info);
  border-color: var(--info);
}

.is-new {
  animation: pop 0.42s var(--ease);
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

.is-moving {
  z-index: 3;
}

.term {
  display: flex;
  flex-direction: column;

  height: clamp(320px, 52vh, 620px);
  background: var(--term-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.term__bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.term__dots {
  display: flex;
  gap: 0.3rem;
}

.term__dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4c515c;
}

.term__dots i:first-child {
  background: #e4756a;
}

.term__dots i:nth-child(2) {
  background: #e0b155;
}

.term__name {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #8b909b;
}

.term__bar .btn {
  margin-left: auto;
  color: #8b909b;
  border-color: rgba(255, 255, 255, 0.16);
  background: transparent;
}

.term__screen {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.7rem 0.8rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.55;
  color: #d7dae1;
  cursor: text;
}

.term__echo {
  margin-top: 0.5rem;
}

.term__meta,
.term__cmd {
  white-space: pre-wrap;
  word-break: break-word;
}

.p-user {
  color: #6ee7b7;
}

.p-env {
  color: #c79bf0;
}

.p-path {
  color: #f0c674;
}

.p-branch {
  color: #7fb2f0;
}

.term__dollar {
  color: #6ee7b7;
}

.term__block {
  margin-top: 0.1rem;
}

.term__row {
  white-space: pre-wrap;
  word-break: break-word;
  animation: row-in 0.18s var(--ease) both;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
}

.term__row--ok {
  color: #6ee7b7;
}

.term__row--err {
  color: #ef8b80;
}

.term__row--warn {
  color: #f0c674;
}

.term__row--dim {
  color: #868d99;
}

.term__row--dir {
  color: #7fb2f0;
}

.term__note {
  margin: 0.45rem 0;
  padding: 0.35rem 0.6rem;
  border-left: 2px solid var(--info);
  background: rgba(119, 167, 240, 0.1);
  color: #b9cdf0;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  animation: note-in 0.28s var(--ease) both;
}

@keyframes note-in {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
}

.term__note--ok {
  border-left-color: #6ee7b7;
  background: rgba(110, 231, 183, 0.1);
  color: #a5e8cd;
}

.term__note--warn {
  border-left-color: #f0c674;
  background: rgba(240, 198, 116, 0.1);
  color: #e8d3a5;
}

.term__line {
  display: flex;
  flex-direction: column;
  margin-top: 0.4rem;
}

.term__prompt {
  white-space: pre-wrap;
  word-break: break-word;
}

.term__line::after {
  content: '';
}

.term__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #e9ecf2;
  font: inherit;
  padding: 0;
  outline: none;
  caret-color: #6ee7b7;
}

.term__line {
  position: relative;
}

.term__line > .term__input {
  padding-left: 1.1rem;
}

.term__line > .term__input + * {
  display: none;
}

.term__line::before {
  content: '$';
  position: absolute;
  left: 0;
  bottom: 0;
  color: #6ee7b7;
}

.term__tip {
  margin: 0;
  padding: 0.4rem 0.7rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: #7d838f;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(6, 8, 12, 0.6);
}

.modal[hidden] {
  display: none;
}

.modal__panel {
  position: relative;
  width: min(760px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 1.3rem;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.modal__close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.3rem;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
}

.modal__lead {
  margin: 0.4rem 0 1rem;
  font-size: 0.86rem;
  color: var(--ink-dim);
}

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.card__btn {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  height: 100%;
  padding: 0.7rem 0.8rem;
  text-align: left;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease);
}

.card__btn:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.card.is-current .card__btn {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.card__no {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.card__done {
  position: absolute;
  align-self: flex-end;
  margin-top: -1.1rem;
  font-size: 0.66rem;
  color: var(--accent);
}

.card__title {
  font-size: 0.95rem;
}

.card__lead {
  font-size: 0.79rem;
  color: var(--ink-dim);
}

.card__meta {
  margin-top: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
}

.cheat {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cheat__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  font-size: 0.82rem;
}

.cheat__cmd {
  font-size: 0.78rem;
  color: var(--accent);
  overflow-x: auto;
  white-space: nowrap;
}

.cheat__what {
  color: var(--ink-dim);
}

.cheat__row.is-locked {
  opacity: 0.45;
}

.cheat__row.is-locked .cheat__cmd {
  color: var(--ink-faint);
}

.footer {
  padding: 1rem;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.76rem;
}

.footer p {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

@media (max-width: 1180px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .lesson {
    grid-row: auto;
  }

  .steps {
    max-height: 22vh;
  }
}

@media (max-width: 760px) {
  .stage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .zone {
    min-height: 190px;
  }

  .zone[data-zone='index']::before,
  .zone[data-zone='local']::before,
  .zone[data-zone='remote']::before {
    display: none;
  }

  .file {
    flex-wrap: wrap;
  }

  .file__badge {
    flex-basis: 100%;
    margin-left: 1.55rem;
  }

  .term {
    height: 60vh;
  }

  .term__screen {
    font-size: 0.74rem;
  }
}

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