* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg0-hard: #0a1320;
  --bg0: #111a25;
  --bg1: #182535;
  --bg2: #213448;
  --bg3: #2f4a67;
  --bg4: #3d5f83;
  --fg0: #ffffff;
  --fg1: #e6effa;
  --fg2: #c8dbf3;
  --fg3: #9db8d9;
  --fg4: #7e9ac0;
  --red: #fb4934;
  --green: #6fdbf0;
  --yellow: #fabd2f;
}

[data-theme='light'] {
  --bg0-hard: #e8f0fa;
  --bg0: #f6f9ff;
  --bg1: #eef3fb;
  --bg2: #d5e2f2;
  --bg3: #b6c9df;
  --bg4: #8da9ca;
  --fg0: #102033;
  --fg1: #15263a;
  --fg2: #29415e;
  --fg3: #4b6788;
  --fg4: #6d87a6;
  --green: #2397b2;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: radial-gradient(circle at top right, #16263a, var(--bg0-hard));
  color: var(--fg1);
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

header {
  background: var(--bg0);
  border-bottom: 1px solid var(--bg2);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.logo-mark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  display: none;
}

.logo-text {
  font-family: 'MuseoModerno', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--green);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--bg1);
  border: 1px solid var(--bg2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--fg2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg4);
}

.status-dot.connecting {
  background: var(--yellow);
}

.status-dot.connected {
  background: var(--green);
}

.status-dot.error {
  background: var(--red);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--fg3);
}

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

.header-tool-btn {
  color: var(--fg1);
  text-decoration: none;
  border: 1px solid var(--bg3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.header-tool-btn:hover {
  background: var(--bg2);
}

.header-link {
  color: var(--fg1);
  text-decoration: none;
  border: 1px solid var(--bg3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.header-link:hover {
  background: var(--bg2);
}

.main-content {
  display: flex;
  gap: 8px;
  flex: 1;
  padding: 8px;
  min-height: 0;
}

.panel {
  min-height: 0;
  border: 1px solid var(--bg2);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.challenge-panel {
  flex: 0 0 24%;
}

.editor-panel {
  flex: 0 0 34%;
}

.terminal-panel {
  flex: 1;
}

.panel-resizer {
  width: 6px;
  border-radius: 4px;
  background: linear-gradient(to bottom, var(--bg3), var(--bg2));
  cursor: col-resize;
  flex-shrink: 0;
}

.panel-resizer:hover {
  background: linear-gradient(to bottom, var(--green), var(--bg3));
}

.panel-header {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg1);
  border-bottom: 1px solid var(--bg2);
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--fg1);
  letter-spacing: 0.03em;
}

.panel-subtitle {
  font-size: 11px;
  color: var(--fg3);
}

.challenge-panel {
  background: var(--bg0);
}

.challenge-content {
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.challenge-nav {
  display: grid;
  gap: 8px;
}

.challenge-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-chip {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--bg3);
  background: var(--bg1);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--fg2);
}

.progress-chip.all-done {
  border-color: var(--green);
  color: var(--green);
}

.progress-timeline {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 8px;
}

.timeline-step {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg3);
  background: var(--bg0);
  flex: 0 0 auto;
}

.timeline-dot.done {
  background: var(--green);
  border-color: var(--green);
}

.timeline-dot.active {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(250, 189, 47, 0.2);
}

.timeline-label {
  font-size: 11px;
  color: var(--fg3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-label.done {
  color: var(--fg2);
}

.timeline-label.active {
  color: var(--yellow);
}

.challenge-link {
  width: 100%;
  border: 1px solid var(--bg3);
  background: var(--bg1);
  color: var(--fg2);
  border-radius: 6px;
  padding: 8px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
}

.challenge-link:hover,
.challenge-link.active {
  border-color: var(--green);
  background: var(--bg2);
}

.challenge-link:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.challenge-title {
  flex: 1;
}

.challenge-check-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.challenge-check-icon path {
  fill: var(--green);
}

.challenge-meta {
  font-size: 12px;
  color: var(--fg3);
}

.challenge-description {
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg2);
}

.challenge-objective {
  border: 1px solid var(--bg2);
  background: var(--bg1);
  border-radius: 6px;
  padding: 10px;
}

.challenge-objective h3 {
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--fg1);
}

.challenge-objective p {
  font-size: 13px;
  color: var(--fg2);
  line-height: 1.45;
}

.challenge-steps {
  border: 1px solid var(--bg2);
  background: var(--bg1);
  border-radius: 6px;
  padding: 10px;
}

.challenge-steps h3 {
  font-size: 12px;
  margin-bottom: 8px;
  color: var(--fg1);
}

.challenge-steps ol {
  padding-left: 18px;
  color: var(--fg2);
  font-size: 13px;
  line-height: 1.5;
}

.challenge-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 6px 12px;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg1);
  cursor: pointer;
  font-family: inherit;
}

.btn:hover {
  background: var(--bg3);
}

.btn.primary {
  background: var(--green);
  color: #08131f;
  border-color: var(--green);
}

.btn.primary:hover {
  background: #88e3f5;
}

.editor-panel {
  background: var(--bg0);
}

.file-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg0);
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--bg2);
  flex-shrink: 0;
}

.file-tab {
  padding: 6px 10px;
  border: 1px solid var(--bg2);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--bg1);
  color: var(--fg3);
  font-size: 12px;
  cursor: pointer;
}

.file-tab.active {
  background: var(--bg0);
  color: var(--fg0);
  border-bottom: 2px solid var(--green);
}

.editor-container {
  flex: 1;
  min-height: 0;
}

#editor {
  width: 100%;
  height: 100%;
}

.terminal-panel {
  background: var(--bg0);
}

.terminal-actions {
  display: flex;
  gap: 8px;
}

.terminal-wrapper {
  flex: 1;
  min-height: 0;
  padding: 8px;
  position: relative;
  background: var(--bg0);
}

#terminal {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: var(--bg0);
}

#terminal .xterm,
#terminal .xterm-viewport,
#terminal .xterm-screen {
  background: var(--bg0) !important;
}

.loading {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: var(--fg3);
  gap: 12px;
  padding: 16px;
}

.loading-card {
  border: 1px solid var(--bg2);
  border-radius: 8px;
  background: var(--bg1);
  padding: 12px;
}

.skeleton-row {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg2), var(--bg3), var(--bg2));
  background-size: 200% 100%;
  animation: shimmer 1.2s ease infinite;
}

.skeleton-row + .skeleton-row {
  margin-top: 8px;
}

.skeleton-row.short {
  width: 40%;
}

.skeleton-row.mid {
  width: 62%;
}

.loading-caption {
  font-size: 12px;
  color: var(--fg3);
}

.loading.hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--bg1);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--fg1);
  font-size: 12px;
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 50;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.mobile-view-switcher {
  display: none;
}

.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 12, 18, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 70;
}

.command-palette-overlay[hidden] {
  display: none;
}

.command-palette {
  width: min(620px, calc(100vw - 24px));
  border: 1px solid var(--bg3);
  border-radius: 12px;
  background: var(--bg0);
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

.command-palette-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bg2);
  font-size: 12px;
  color: var(--fg2);
}

.command-palette-hint {
  color: var(--fg3);
  font-size: 11px;
}

.command-palette-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--bg2);
  background: var(--bg0);
  color: var(--fg1);
  padding: 11px 12px;
  outline: none;
  font-size: 13px;
  font-family: inherit;
}

.command-palette-list {
  max-height: 320px;
  overflow: auto;
}

.command-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--bg2);
  background: transparent;
  color: var(--fg1);
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.command-item:last-child {
  border-bottom: 0;
}

.command-item:hover,
.command-item.active {
  background: var(--bg1);
}

.command-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.command-kbd {
  color: var(--fg3);
  font-size: 11px;
}

.command-empty {
  padding: 14px 12px;
  color: var(--fg3);
  font-size: 12px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@media (max-width: 1200px) {
  .challenge-panel {
    flex-basis: 30%;
  }

  .editor-panel {
    flex-basis: 33%;
  }
}

@media (max-width: 980px) {
  .main-content {
    display: block;
    padding-top: 18px;
  }

  .header-right {
    display: flex;
    gap: 6px;
  }

  .header-link {
    padding: 4px 8px;
  }

  .status-indicator {
    display: none;
  }

  .logo-text {
    display: none;
  }

  .logo-mark {
    display: block;
  }

  .panel-resizer {
    display: none;
  }

  .mobile-view-switcher {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 6px;
    padding: 0 8px 14px;
  }

  .mobile-switch-btn {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--bg3);
    background: var(--bg1);
    color: var(--fg1);
    font-size: 12px;
    font-family: inherit;
    font-weight: 700;
  }

  .mobile-switch-btn.active {
    border-color: var(--green);
    color: var(--green);
  }

  .panel {
    display: none;
    height: calc(100vh - 152px);
    margin-top: 14px;
  }

  body.mobile-view-challenge .challenge-panel,
  body.mobile-view-editor .editor-panel,
  body.mobile-view-terminal .terminal-panel {
    display: flex;
  }
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg1);
}

::-webkit-scrollbar-thumb {
  background: var(--bg3);
  border-radius: 4px;
}
