/* -- Reset ------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* -- Variables -------------------------------------------------------- */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --max-width: 1100px;
  --code-bg: #f1f5f9;
}

[data-theme="dark"] {
  --bg: #111111;
  --bg-alt: #1a1a1a;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #2d2d2d;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-light: #1e293b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --code-bg: #1e293b;
}

/* -- Base ------------------------------------------------------------- */
html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

h1,
h2,
h3 {
  line-height: 1.3;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.5rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

h3 {
  font-size: 1.15rem;
}

/* -- Navigation ------------------------------------------------------- */
.site-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1.5rem;
  width: 100%;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  white-space: nowrap;
}

.logo:hover {
  color: var(--accent);
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 0.95rem;
  white-space: nowrap;
}

.nav-links a:hover {
  color: var(--text);
}

.theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s;
}

.theme-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

[data-theme="light"] .icon-moon,
:root:not([data-theme]) .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-moon {
  display: block;
}

.lang-switch {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  flex-direction: column;
  gap: 4px;
}

.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

/* -- Hero ------------------------------------------------------------- */
.hero {
  text-align: center;
  padding: 4rem 0 3rem;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.hero-sub {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 2rem;
  line-height: 1.7;
}

/* -- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.2s;
}

.btn:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-outline:hover {
  background: var(--accent-light);
  color: var(--accent-hover);
}

/* -- Section cards (homepage) ----------------------------------------- */
.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.section-card {
  display: block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.section-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  color: var(--text);
}

.section-card h3 {
  margin-bottom: 0.5rem;
}

.section-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* -- Philosophy ------------------------------------------------------- */
.philosophy {
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 2rem;
  margin: 2rem 0;
}

.philosophy h2 {
  margin-top: 0;
}

.philosophy-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-left: 1.25rem;
}

.philosophy-list li {
  color: var(--text-muted);
}

/* -- Page header ------------------------------------------------------ */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  margin-bottom: 0.5rem;
}

.page-header p {
  color: var(--text-muted);
  font-size: 1.05rem;
}

/* -- Phase sections --------------------------------------------------- */
.phase {
  margin-bottom: 3rem;
}

.phase h2 {
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
}

.phase-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.phase-analogy {
  color: var(--accent);
  font-style: italic;
  font-size: 0.9rem;
  margin-top: 0.25rem;
  margin-bottom: 1rem;
}

/* -- Lesson cards ----------------------------------------------------- */
.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.lesson-card {
  display: block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

a.lesson-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  color: var(--text);
}

div.lesson-card.coming-soon {
  opacity: 0.55;
}

.lesson-id {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.lesson-card h3 {
  margin-bottom: 0.4rem;
}

.lesson-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  background: var(--border);
  color: var(--text-muted);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.5rem;
}

/* -- Theory cards ----------------------------------------------------- */
.theory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.theory-card {
  display: block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

a.theory-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  color: var(--text);
}

.theory-card h3 {
  margin-bottom: 0.4rem;
}

.theory-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.theory-analogy {
  font-style: italic;
  color: var(--accent);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* -- Video grid ------------------------------------------------------- */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(400px, 100%), 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
  max-width: 720px;
}

.video-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.video-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
}

.video-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-card h3 {
  padding: 1rem 1.25rem 0.25rem;
}

.video-card p {
  padding: 0 1.25rem 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* -- Resource cards --------------------------------------------------- */
.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.resource-card {
  display: block;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.resource-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  color: var(--text);
}

.resource-card h3 {
  margin-bottom: 0.5rem;
}

.resource-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.resource-url {
  font-size: 0.8rem;
  color: var(--accent);
}

/* -- Community -------------------------------------------------------- */
.community {
  text-align: center;
  padding: 3rem 0;
  margin-top: 2rem;
  border-top: 1px solid var(--border);
}

.community h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.community p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* -- Lesson page ------------------------------------------------------ */
.lesson {
  max-width: 780px;
  margin: 0 auto;
}

.lesson-breadcrumb {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.lesson-pager {
  display: flex;
  gap: 1.5rem;
}

.lesson h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.lesson h2 {
  font-size: 1.35rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.lesson p {
  margin-bottom: 1rem;
}

.lesson-intro {
  font-size: 1.1rem;
  color: var(--text-muted);
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin-bottom: 1.5rem;
}

.lesson ul,
.lesson ol {
  margin: 0.75rem 0 1rem 1.5rem;
}

.lesson li {
  margin-bottom: 0.35rem;
}

.lesson pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.lesson code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.lesson :not(pre) > code {
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

.lesson .mermaid {
  margin: 1.5rem 0;
  text-align: center;
}

.lesson blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  color: var(--text-muted);
  font-style: italic;
}

.lesson .takeaways {
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-top: 2rem;
}

.lesson .takeaways h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

/* -- Footer ----------------------------------------------------------- */
footer {
  text-align: center;
  padding: 2rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.footer-links a {
  color: var(--text-muted);
}

.footer-links a:hover {
  color: var(--text);
}

/* -- Responsive ------------------------------------------------------- */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 1.75rem;
  }

  .hero-sub {
    font-size: 1rem;
  }

  .site-nav {
    gap: 0.5rem;
  }

  .logo {
    margin-right: auto;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    gap: 0;
    padding: 0.5rem 1.5rem 1rem;
    z-index: 10;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    padding: 0.4rem 0;
  }

  .site-nav {
    position: relative;
  }

  .menu-btn {
    display: flex;
  }

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

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

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

  .lesson-breadcrumb {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }
}
