@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
  /* JavaScript brand palette */
  --js-yellow: #f7df1e;
  --js-yellow-hover: #e6c800;
  --js-yellow-light: #fef9c3;
  --js-yellow-soft: #fffbeb;
  --js-black: #323330;
  --js-charcoal: #1e1e1c;

  --bg: #fffdf5;
  --surface: #ffffff;
  --surface-2: #fff9e6;
  --text: var(--js-black);
  --muted: #5c5c58;
  --border: #ebe4c8;
  --border-strong: #ddd39a;

  --primary: var(--js-yellow);
  --primary-hover: var(--js-yellow-hover);
  --primary-text: var(--js-black);
  --primary-soft: var(--js-yellow-light);
  --accent: #b8860b;

  --ok: #15803d;
  --bad: #dc2626;
  --shadow: 0 1px 3px rgba(50, 51, 48, 0.06);
  --shadow-lg: 0 12px 40px rgba(50, 51, 48, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --max: 1120px;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

.container {
  width: min(var(--max), 92%);
  margin: 0 auto;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  padding: 0.5rem 0.8rem;
  background: var(--js-yellow);
  color: var(--js-black);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  z-index: 9999;
}

/* Header — scrolls with page (not fixed) */
.site-header {
  position: relative;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.nav-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0;
  flex-wrap: wrap;
}

.nav-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
  order: 2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  order: 3;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle-bar {
  display: block;
  width: 20px;
  height: 2px;
  margin: 0 auto;
  background: var(--js-black);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.site-header.nav-open .nav-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.site-header.nav-open .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}

.site-header.nav-open .nav-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  order: 1;
  flex-shrink: 0;
}

.brand:hover { color: inherit; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--js-yellow);
  color: var(--js-black);
  flex-shrink: 0;
  box-shadow: 0 2px 0 var(--js-yellow-hover);
  transition: background 0.15s, transform 0.15s;
}

a.brand:hover .brand-mark {
  background: var(--js-yellow-hover);
  transform: scale(1.03);
}

#site-title, .brand h1, .site-name {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--js-black);
}

#site-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0;
  padding: 0;
}

.nav-list a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.35rem 0;
  transition: color 0.15s;
  display: inline-block;
}

.nav-list a:hover,
.nav-list a:focus { color: var(--js-black); }

.language-select-wrap {
  display: block;
  flex-shrink: 0;
}

.language-select-wrap select {
  min-width: 7.5rem;
  max-width: 11rem;
}

select, input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
}

select:focus, input:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--js-yellow-light);
  border-color: var(--js-yellow-hover);
}

/* Hero */
.hero {
  padding: 3.5rem 0 2.5rem;
  background: linear-gradient(180deg, var(--js-yellow-soft) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

.hero-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1.4fr 1fr;
  align-items: start;
}

.hero-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--js-black);
  background: var(--js-yellow);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-strong);
}

.hero h2 {
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.12;
  margin: 0 0 0.75rem;
  letter-spacing: -0.03em;
  font-weight: 700;
  color: var(--js-black);
}

.hero p, .section-text {
  color: var(--muted);
  margin-top: 0;
}

.hero-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.1rem;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--js-yellow);
  color: var(--js-black);
  border-color: var(--js-yellow-hover);
  box-shadow: 0 2px 0 var(--js-yellow-hover);
}

.btn-primary:hover {
  background: var(--js-yellow-hover);
  box-shadow: 0 3px 0 #c9b800;
}

.btn-secondary {
  background: var(--surface);
  color: var(--js-black);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--js-yellow-soft);
  border-color: var(--js-yellow-hover);
}

/* Cards */
.card, .stats-card, .lesson-card, .exercise-item,
.quiz-form fieldset,
.category-card, .blog-card, .library-card, .lesson-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats-card {
  padding: 1.25rem;
  border-top: 3px solid var(--js-yellow);
}

.stats-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
}

.stats-card p {
  margin: 0.4rem 0;
  font-size: 0.95rem;
}

/* Sections */
.section { padding: 3rem 0; }

.section-alt {
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.section-head {
  margin-bottom: 1.75rem;
  max-width: 640px;
}

.section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--js-black);
}

.section h3,
.page-hero h2,
.game-wrap h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.35rem, 4vw, 1.65rem);
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--js-black);
}

.section h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.section-text { margin-bottom: 0; }

.cards, .category-grid, .blog-grid, .library-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.lesson-card, .category-card, .blog-card, .library-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.lesson-card:hover, .category-card:hover, .library-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.lesson-card h3, .category-card h3, .library-card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.lesson-card p, .library-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  flex: 1;
}

.lesson-card .btn, .library-card .btn {
  margin-top: 0.5rem;
  align-self: flex-start;
}

/* Tags */
.tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--js-yellow-light);
  color: var(--js-black);
  width: fit-content;
  border: 1px solid var(--border-strong);
}

.tag-beginner { background: #ecfccb; color: #3f6212; border-color: #bef264; }
.tag-intermediate { background: var(--js-yellow-light); color: #854d0e; border-color: #fde047; }
.tag-advanced { background: #ffedd5; color: #c2410c; border-color: #fdba74; }

/* Playground */
.playground-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

#codeInput {
  width: 100%;
  max-width: 100%;
  min-height: 240px;
  resize: vertical;
  color: #ffffff;
  background: #000000;
  border: 1px solid #323330;
  padding: 1rem;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.85rem;
  margin: 0.5rem 0 0.75rem;
  line-height: 1.5;
  caret-color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

#codeInput::placeholder {
  color: #888888;
}

#codeOutput {
  min-height: 300px;
  padding: 1rem;
  overflow: auto;
  white-space: pre-wrap;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.85rem;
  color: #ffffff;
  background: #000000;
  border: 1px solid #323330;
  border-radius: var(--radius);
  margin: 0;
  box-shadow: var(--shadow);
}

label { font-weight: 500; font-size: 0.9rem; }

/* Exercises */
.exercise-list { display: grid; gap: 1rem; }
.exercise-item { padding: 1.25rem; }
.exercise-item input { width: 100%; max-width: 100%; margin: 0.6rem 0; }
.exercise-result { font-weight: 600; font-size: 0.9rem; margin: 0.5rem 0 0; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* Quiz */
.quiz-form { display: grid; gap: 0.85rem; }
.quiz-form fieldset {
  padding: 1rem 1.1rem;
  border: none;
  margin: 0;
}
.quiz-form legend {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}
.quiz-form label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.45rem;
  font-weight: 400;
  cursor: pointer;
}

.quiz-form input[type="radio"] {
  accent-color: var(--js-yellow-hover);
}

/* Libraries */
.library-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: #fff;
  flex-shrink: 0;
}

.library-card-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.library-card pre {
  background: #000000;
  color: #ffffff;
  border: 1px solid #323330;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.78rem;
  overflow-x: auto;
  margin: 0.5rem 0 0;
  font-family: "JetBrains Mono", Consolas, monospace;
}

.library-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Category / Blog */
.category-card a, .blog-card a {
  color: var(--js-black);
  text-decoration: none;
  font-weight: 600;
}

.category-card a:hover, .blog-card a:hover { color: var(--accent); }

.category-icon { font-size: 1.5rem; line-height: 1; }
.blog-card { padding: 1.25rem; }

/* Pages */
.page-hero {
  padding: 2.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--js-yellow-soft) 0%, var(--surface) 100%);
}

.lesson-detail {
  margin-bottom: 1rem;
  padding: 1.25rem;
}

.lesson-detail pre, .article-body pre {
  background: #000000;
  color: #ffffff;
  border: 1px solid #323330;
  padding: 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.85rem;
}

.lesson-steps {
  margin: 0.75rem 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.lesson-steps li { margin-bottom: 0.35rem; }

.article-body {
  max-width: 720px;
  line-height: 1.75;
}

.article-body h2 { letter-spacing: -0.02em; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  color: var(--muted);
  font-size: 0.9rem;
  background: var(--js-yellow-soft);
}

.site-footer p { margin: 0.25rem 0; }

/* FAQ */
details {
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  background: var(--surface);
}

details[open] {
  border-color: var(--border-strong);
  background: var(--js-yellow-soft);
}

summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
}

details p {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Game */
.game-wrap { display: grid; gap: 1rem; }

#gameCanvas {
  width: 100%;
  max-width: 720px;
  background: var(--js-charcoal);
  border: 2px solid var(--js-yellow);
  border-radius: var(--radius);
  display: block;
  cursor: pointer;
  touch-action: none;
}

#gameCanvas:focus {
  outline: 2px solid var(--js-yellow);
  outline-offset: 2px;
}

.game-concept-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.game-concept-grid .category-card a {
  font-weight: 600;
  color: var(--js-black);
}

.game-controls {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  max-width: 220px;
}

.game-controls-row {
  display: flex;
  gap: 0.5rem;
}

.game-btn {
  min-width: 3rem;
  min-height: 3rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--js-yellow);
  color: var(--js-black);
  cursor: pointer;
}

.game-btn:active {
  transform: scale(0.96);
}

code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.88em;
  background: var(--js-yellow-light);
  color: var(--js-black);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
}

@media (max-width: 1024px) {
  .nav-toggle {
    display: flex;
  }

  .nav-wrap {
    align-items: center;
    flex-wrap: wrap;
  }

  .brand {
    flex: 1;
    min-width: 0;
    order: 1;
  }

  .brand h1,
  #site-title {
    font-size: clamp(0.95rem, 3.5vw, 1.05rem);
  }

  #site-subtitle {
    font-size: 0.72rem;
    line-height: 1.3;
  }

  .header-actions {
    order: 3;
  }

  .nav-panel {
    order: 4;
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.25rem 0 0;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    justify-content: flex-start;
  }

  .site-header.nav-open .nav-panel {
    display: flex;
  }

  .nav-list {
    flex-direction: column;
    gap: 0;
    width: 100%;
  }

  .nav-list li {
    border-bottom: 1px solid var(--border);
  }

  .nav-list li:last-child {
    border-bottom: none;
  }

  .nav-list a {
    display: block;
    padding: 0.75rem 0.25rem;
    font-size: 1rem;
    min-height: 44px;
    line-height: 1.4;
  }

  .language-select-wrap select {
    min-width: 6.5rem;
    max-width: 9rem;
    min-height: 44px;
  }
}

@media (max-width: 900px) {
  .hero-grid,
  .playground-grid {
    grid-template-columns: 1fr;
  }

  .cards,
  .category-grid,
  .blog-grid,
  .library-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    padding: 2.25rem 0 1.75rem;
  }

  .section {
    padding: 2.25rem 0;
  }

  .page-hero {
    padding: 1.75rem 0 0.75rem;
  }

  .hero-actions .btn {
    flex: 1 1 auto;
    min-width: min(100%, 10rem);
  }

  #codeInput,
  #codeOutput {
    min-height: 200px;
    font-size: 0.8rem;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar .btn {
    width: 100%;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
  }

  pre,
  .lesson-detail pre,
  .article-body pre,
  .library-card pre {
    font-size: 0.78rem;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 480px) {
  .container {
    width: min(var(--max), 96%);
  }

  .hero h2 {
    font-size: 1.75rem;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 0.75rem;
  }

  .language-select-wrap select {
    min-width: 5.5rem;
    max-width: 7.5rem;
    font-size: 0.85rem;
    padding: 0.45rem 0.5rem;
  }

  .stats-card {
    padding: 1rem;
  }

  .lesson-card,
  .category-card,
  .library-card,
  .blog-card,
  .exercise-item {
    padding: 1rem;
  }

  .game-controls {
    max-width: 100%;
  }

  .game-btn {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
}
