:root {
  color-scheme: light;
  --bg: #f6f8fc;
  --bg-strong: #edf2fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe3ef;
  --accent: #4f46e5;
  --accent-strong: #3730a3;
  --accent-soft: #eef2ff;
  --ok: #15803d;
  --danger: #dc2626;
  --shadow: 0 22px 70px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 12px 32px rgba(15, 23, 42, 0.06);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --topbar-height: 78px;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-strong: #10182b;
  --panel: #121a2d;
  --panel-soft: #17223a;
  --text: #e5edff;
  --muted: #9aa8c2;
  --line: #26344f;
  --accent: #8b9cff;
  --accent-strong: #c7d2fe;
  --accent-soft: rgba(139, 156, 255, 0.14);
  --ok: #58d68d;
  --danger: #f87171;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, 0.12), transparent 34rem),
    linear-gradient(180deg, var(--bg-strong), var(--bg) 22rem),
    var(--bg);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    'Noto Sans KR',
    sans-serif;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--topbar-height);
  padding: 0.9rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 16px;
  color: #ffffff;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  box-shadow: var(--shadow-soft);
  font-size: 1.1rem;
  font-weight: 900;
}

.brand-copy strong,
.brand-copy small {
  display: block;
}

.brand-copy strong {
  letter-spacing: -0.03em;
}

.brand-copy small {
  margin-top: 0.15rem;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.progress-pill {
  display: grid;
  gap: 0.45rem;
  width: min(260px, 42vw);
  padding: 0.72rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
}

.progress-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.progress-info strong {
  color: var(--text);
  font-size: 0.86rem;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #06b6d4);
  transition: width 0.35s ease;
}

.app-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 2.4vw, 2rem);
}

.hero-card,
.sidebar,
.lesson-card,
.lab-card,
.preview-card,
.output-card {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 1.4rem;
  margin-bottom: 1rem;
  padding: clamp(1.2rem, 2.6vw, 2rem);
  border-radius: var(--radius-xl);
}

.hero-card h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(1.7rem, 3.2vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.055em;
}

.hero-desc {
  max-width: 820px;
  margin: 0.9rem 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 0.7rem;
}

.hero-stats div {
  min-width: 92px;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-soft);
}

.hero-stats strong,
.hero-stats span {
  display: block;
}

.hero-stats strong {
  font-size: 1.35rem;
  letter-spacing: -0.04em;
}

.hero-stats span {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: calc(var(--topbar-height) + 1rem);
  max-height: calc(100vh - var(--topbar-height) - 2rem);
  overflow: auto;
  padding: 1rem;
  border-radius: var(--radius-lg);
}

.side-head h2,
.lab-head h2,
.preview-modal-head h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

.side-head p:not(.eyebrow),
.lab-head p:not(.eyebrow) {
  margin: 0.5rem 0 1rem;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.92rem;
}

.eyebrow {
  margin: 0 0 0.38rem;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.11em;
}

.search-box {
  display: grid;
  gap: 0.42rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.search-box input,
.stdin-box textarea {
  width: 100%;
  color: var(--text);
  background: var(--panel-soft);
  outline: none;
}

.search-box input {
  padding: 0.82rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.search-box input:focus,
.stdin-box textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.lesson-list {
  display: grid;
  gap: 0.58rem;
  margin: 1rem 0;
}

.lesson-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.72rem;
  width: 100%;
  padding: 0.82rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  background: var(--panel);
  text-align: left;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}

.lesson-item:hover,
.lesson-item.active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.lesson-num {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.78rem;
  font-weight: 900;
}

.lesson-name {
  min-width: 0;
}

.lesson-name strong,
.lesson-name small {
  display: block;
}

.lesson-name strong {
  overflow: hidden;
  font-size: 0.94rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-name small {
  margin-top: 0.2rem;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.done-dot {
  color: var(--ok);
  font-weight: 900;
  opacity: 0;
}

.lesson-item.done .done-dot {
  opacity: 1;
}

.main-stack {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.lesson-card,
.lab-card {
  padding: clamp(1rem, 2vw, 1.35rem);
  border-radius: var(--radius-lg);
}

.crumb {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.lesson-title-row,
.lab-head,
.result-head,
.run-row,
.preview-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
}

.lesson-title-row {
  align-items: flex-start;
}

.lesson-title-row h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2.8vw, 2.15rem);
  line-height: 1.16;
  letter-spacing: -0.045em;
}

.lesson-body {
  margin-top: 1.2rem;
  line-height: 1.72;
}

.lesson-body h3 {
  margin: 1.2rem 0 0.45rem;
  font-size: 1.04rem;
}

.lesson-body p {
  margin: 0.45rem 0;
  color: var(--muted);
}

.lesson-body code,
.check-card code {
  padding: 0.14rem 0.38rem;
  border-radius: 0.45rem;
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.lesson-body .note {
  margin-top: 0.85rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  color: var(--text);
  background: var(--panel-soft);
}

.lesson-body ol,
.lesson-body ul {
  padding-left: 1.2rem;
}

.lesson-body li {
  margin: 0.42rem 0;
}

.check-card {
  margin-top: 1.2rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-soft);
}

.check-card h3 {
  margin: 0 0 0.65rem;
}

.check-card ul {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.65;
}

.lab-head {
  align-items: flex-start;
  margin-bottom: 1rem;
}

.toolbar-actions,
.preview-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(460px, 1.08fr) minmax(360px, 0.92fr);
  gap: 1rem;
  align-items: stretch;
}

.editor-column {
  display: grid;
  min-width: 0;
}

.editor {
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #1e1e1e;
}

.stdin-box {
  margin-top: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-soft);
}

.stdin-box summary {
  padding: 0.82rem 1rem;
  color: var(--muted);
  cursor: pointer;
}

.stdin-box textarea {
  display: block;
  min-height: 86px;
  resize: vertical;
  padding: 0.9rem 1rem;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.run-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin: 0.9rem 0;
}

.preview-card,
.output-card {
  min-height: 280px;
  padding: 0.92rem;
  border-radius: var(--radius-md);
  background: var(--panel-soft);
}

.preview-card {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr);
}

.result-head {
  margin-bottom: 0.72rem;
}

.result-head h3 {
  margin: 0;
  font-size: 1rem;
}

.status-text {
  color: var(--muted);
  font-size: 0.86rem;
}

iframe {
  width: 100%;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #111827;
}

pre {
  min-height: 210px;
  max-height: 280px;
  margin: 0;
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--panel);
  white-space: pre-wrap;
  word-break: break-word;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font-weight: 850;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}

.primary-button {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 22%, transparent);
}

.secondary-button {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}

.ghost-button,
.icon-button {
  color: var(--text);
  background: var(--panel-soft);
  border-color: var(--line);
}

.wide {
  width: 100%;
}

.small {
  padding: 0.48rem 0.72rem;
  font-size: 0.82rem;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: var(--shadow-soft);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.58;
  cursor: wait;
  transform: none;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: clamp(0.7rem, 2vw, 1.4rem);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.24s ease,
    visibility 0.24s ease;
}

.preview-modal[aria-hidden='false'] {
  opacity: 1;
  visibility: visible;
}

.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(10px);
}

.preview-modal-card {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1280px, 100%);
  height: min(820px, 94vh);
  padding: clamp(0.9rem, 2vw, 1.2rem);
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: 0 26px 100px rgba(0, 0, 0, 0.34);
  transform: translateY(16px) scale(0.965);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-modal[aria-hidden='false'] .preview-modal-card {
  transform: translateY(0) scale(1);
}

.preview-modal-head {
  margin-bottom: 0.75rem;
}

.preview-modal-card iframe {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.reveal-up {
  animation: reveal-up 0.45s ease both;
}

@keyframes reveal-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    position: static;
    max-height: none;
  }

  .lesson-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .preview-card {
    grid-template-rows: auto minmax(320px, 1fr);
  }
}

@media (max-width: 760px) {
  :root {
    --topbar-height: auto;
  }

  .topbar {
    position: static;
    align-items: stretch;
    padding: 0.85rem;
  }

  .brand-copy small {
    display: none;
  }

  .top-actions,
  .lesson-title-row,
  .lab-head,
  .result-head,
  .preview-modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .progress-pill {
    width: 100%;
  }

  .app-shell {
    padding: 0.85rem;
  }

  .hero-card {
    grid-template-columns: 1fr;
    border-radius: var(--radius-lg);
  }

  .hero-card h1 {
    font-size: 1.75rem;
  }

  .hero-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .hero-stats div {
    min-width: 0;
    padding: 0.72rem;
  }

  .hero-stats strong {
    font-size: 1.05rem;
  }

  .hero-stats span {
    font-size: 0.74rem;
  }

  .lesson-list {
    grid-template-columns: 1fr;
  }

  .lesson-card,
  .lab-card,
  .sidebar {
    border-radius: 18px;
    padding: 0.9rem;
  }

  .toolbar-actions,
  .preview-actions,
  .run-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .toolbar-actions button,
  .preview-actions button,
  .run-row button,
  .lesson-title-row button,
  .icon-button {
    width: 100%;
  }

  .editor {
    min-height: 56vh;
  }

  iframe {
    min-height: 300px;
  }

  pre {
    max-height: 240px;
  }

  .preview-modal {
    padding: 0;
  }

  .preview-modal-card {
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }
}

@media (max-width: 420px) {
  .hero-stats,
  .toolbar-actions,
  .preview-actions,
  .run-row {
    grid-template-columns: 1fr;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }
}
