/* ============================================================
   もふねこのHDL実験ノート — Style v5.0 (Clean & Modern Structure)
   Zenn/Stripe-like Premium Light Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+JP:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --header-height: 64px;
  --sidebar-width: 280px;

  /* Color Palette (Mofuneko Identity) */
  --bg-color:         #f8fafc;
  --surface-color:    #ffffff;
  --border-color:     #e2e8f0;
  
  --text-main:        #0f172a;
  --text-sub:         #334155;
  --text-muted:       #64748b;
  
  --primary:          #63b3ed; /* Mofuneko Blue (ears) */
  --primary-hover:    #4299e1; 
  --accent-purple:    #9f7aea; /* Mofuneko Purple (nose) */
  --accent-pink:      #fc8181; /* Mofuneko Pink (cheeks) */
  --brand-gradient:   linear-gradient(135deg, var(--primary), var(--accent-purple));
  
  --code-bg:          #0f1117; /* Mofuneko Dark */
  --code-text:        #e2e8f0;
  --code-inline-bg:   #eff6ff;
  --code-inline-text: #0f172a;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  font-size: 16px;
  color: var(--text-main);
  background-color: var(--bg-color);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   GLOBAL HEADER
   ============================================================ */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
  display: flex;
  align-items: center;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.logo-mark {
  font-size: 1.4rem;
  display: inline-block;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.header-logo a:hover .logo-mark {
  transform: scale(1.2) rotate(15deg);
}
.logo-text {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-badge {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  margin-left: 0.5rem;
  letter-spacing: 0.05em;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.header-nav a {
  text-decoration: none;
  color: var(--text-sub);
  font-size: 0.95rem;
  font-weight: 600;
  transition: color 0.2s;
}

.header-nav a:hover { color: var(--primary); }
.header-nav .external-link {
  display: flex; align-items: center; gap: 0.2rem;
  background: var(--primary);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.header-nav .external-link:hover { background: var(--primary-hover); color: white; }

/* ============================================================
   LAYOUT CONTAINER
   ============================================================ */
.hdl-container {
  display: flex;
  min-height: 100vh;
  padding-top: var(--header-height);
  max-width: 1400px;
  margin: 0 auto;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  flex-shrink: 0;
  padding: 1.5rem 1rem 3rem;
  border-right: 1px solid var(--border-color);
  background: transparent;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.sidebar nav { flex: 1; }

.sidebar .category {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.85rem; font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 1.2rem 0.75rem 0.5rem;
  cursor: pointer; user-select: none;
  transition: color 0.2s;
}
.sidebar .category:hover { color: var(--text-main); }
.sidebar .category::after { content: '▾'; font-size: 0.8rem; transition: transform 0.25s ease; }
.sidebar .category.collapsed::after { transform: rotate(-90deg); }

.sidebar ul {
  list-style: none; padding: 0;
  overflow: hidden; transition: max-height 0.3s ease, opacity 0.25s ease;
  max-height: 800px; opacity: 1;
}
.sidebar ul.collapsed { max-height: 0; opacity: 0; }
.sidebar li { margin-bottom: 2px; }

.sidebar a {
  display: block; padding: 0.5rem 0.75rem;
  color: var(--text-sub); text-decoration: none;
  font-size: 0.95rem; font-weight: 500;
  border-radius: 6px;
  transition: background-color 0.15s, color 0.15s;
  line-height: 1.5;
}
.sidebar a:hover { background-color: #e2e8f0; color: var(--text-main); }
.sidebar a.active {
  background-color: #eff6ff;
  color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.content {
  flex-grow: 1;
  padding: 2.5rem 3rem 4rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   ARTICLE (The Document)
   ============================================================ */
article {
  background: var(--surface-color);
  padding: 3.5rem 4rem;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  border: 1px solid var(--border-color);
}

/* Headings */
article h1 {
  font-size: 2.2rem; font-weight: 800;
  color: var(--text-main);
  margin-bottom: 2rem; padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  line-height: 1.3; letter-spacing: -0.02em;
}

article h2 {
  font-size: 1.45rem; font-weight: 700; color: var(--text-main);
  margin-top: 3rem; margin-bottom: 1.25rem;
  padding-left: 1rem;
  border-left: 4px solid var(--primary);
  line-height: 1.4; letter-spacing: -0.01em;
}

article h3 {
  font-size: 1.15rem; font-weight: 700; color: var(--text-main);
  margin-top: 2rem; margin-bottom: 0.75rem;
  display: flex; align-items: center; gap: 0.5rem;
}
article h3::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--primary); flex-shrink: 0;
}

article h4 {
  font-size: 1rem; font-weight: 700; color: var(--text-sub);
  margin-top: 1.5rem; margin-bottom: 0.5rem;
}

/* Body Text */
article p { margin-bottom: 1.25rem; color: var(--text-sub); }
article ul, article ol { margin-bottom: 1.5rem; padding-left: 1.75rem; color: var(--text-sub); }
article li { margin-bottom: 0.5rem; }
article strong, article b { color: var(--text-main); font-weight: 700; }
article a {
  color: var(--primary); text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
article a:hover { border-bottom-color: var(--primary); }

/* Images */
article img {
  max-width: 100%; height: auto; border-radius: 8px;
  margin: 2rem auto; display: block;
  box-shadow: var(--shadow-md); border: 1px solid var(--border-color);
}

/* Code */
article code {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 0.85em;
  background: var(--code-inline-bg); color: var(--code-inline-text);
  padding: 0.2em 0.4em; border-radius: 4px; font-weight: 500;
}
article pre {
  background: var(--code-bg) !important;
  border-radius: 12px; padding: 1.5rem !important;
  overflow-x: auto; margin: 1.75rem 0;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
  position: relative;
}
article pre::before {
  content: ''; position: absolute; top: 0; left: 0; bottom: 0; width: 4px;
  background: var(--accent-purple); border-radius: 12px 0 0 12px;
}
article pre code {
  background: transparent !important; color: var(--code-text) !important;
  padding: 0 !important; font-size: 0.9rem; font-weight: 400;
}

/* Tables */
article table {
  width: 100%; border-collapse: collapse; margin: 2rem 0;
  font-size: 0.9rem; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border-color);
}
article th {
  background: #f1f5f9; color: var(--text-main); font-weight: 700;
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color);
  text-align: left;
}
article td {
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color);
  color: var(--text-sub); vertical-align: top;
}
article tr:last-child td { border-bottom: none; }

/* Callout Boxes */
.callout {
  padding: 1.25rem 1.5rem; border-radius: 12px; margin: 1.75rem 0;
  font-size: 0.95rem; border-left: 4px solid; line-height: 1.7;
}
.callout.point  { background: #eff6ff; border-color: var(--primary); color: #1e3a8a; }
.callout.check  { background: #f0fdf4; border-color: #22c55e; color: #14532d; }
.callout.warn   { background: #fffbeb; border-color: #f59e0b; color: #78350f; }
.callout.danger { background: #fef2f2; border-color: #ef4444; color: #7f1d1d; }
.callout strong { font-weight: 700; color: inherit; }

/* TOC Box */
.toc-box {
  background: #f8fafc; border: 1px solid var(--border-color);
  border-radius: 12px; padding: 1.5rem; margin-bottom: 2.5rem;
}
.toc-box h4 { margin-top: 0; color: var(--text-main); font-size: 1.05rem; }
.toc-box ol { margin-bottom: 0; padding-left: 1.5rem; }
.toc-box li { margin-bottom: 0.25rem; }

/* Article Navigation (Prev/Next) */
.article-nav {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 4rem; padding-top: 2rem; border-top: 1px solid var(--border-color);
}
.article-nav a {
  display: flex; align-items: center; padding: 1rem 1.5rem;
  background: #f8fafc; border: 1px solid var(--border-color);
  border-radius: 8px; font-weight: 600; font-size: 0.9rem;
  color: var(--text-sub); transition: all 0.2s;
  width: 48%; text-decoration: none;
}
.article-nav a:hover {
  background: white; border-color: var(--primary);
  color: var(--primary); box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

/* ============================================================
   GLOBAL FOOTER
   ============================================================ */
.site-footer {
  max-width: 860px;
  width: 100%;
  margin: 3rem auto 0;
  padding: 3rem 0 2rem;
  border-top: 1px solid var(--border-color);
}
.footer-inner {
  display: flex; justify-content: space-between; gap: 2rem;
  margin-bottom: 2rem; flex-wrap: wrap;
}
.footer-brand .footer-logo {
  font-weight: 800; font-size: 1.1rem; color: var(--text-main);
  margin-bottom: 0.5rem;
}
.footer-brand p { color: var(--text-muted); font-size: 0.85rem; max-width: 300px; }
.footer-links { display: flex; gap: 1.5rem; }
.footer-links a { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; font-weight: 500; }
.footer-links a:hover { color: var(--primary); }
.footer-bottom {
  text-align: center; color: var(--text-muted); font-size: 0.8rem;
}

/* ============================================================
   READING PROGRESS BAR
   ============================================================ */
.reading-progress {
  position: fixed; top: var(--header-height); left: 0; right: 0; height: 3px;
  background: var(--brand-gradient);
  transform-origin: left; transform: scaleX(0);
  z-index: 900; transition: transform 0.1s linear;
}

/* ============================================================
   HOME PAGE SPECIFICS (Mofuneko Vibe)
   ============================================================ */
.home-hero {
  background: linear-gradient(135deg, #e8f0fe 0%, #d2e3fc 100%);
  border-radius: 20px;
  margin-bottom: 3rem; color: var(--text-main);
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center;
  padding: 3rem; gap: 3rem;
}
.hero-text-content {
  flex: 1; position: relative; text-align: left; z-index: 2;
  display: flex; flex-direction: column; justify-content: center;
}
.hero-image-container {
  flex: 1.2; position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
}
.hero-banner-image {
  width: 100%; height: auto; display: block;
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.home-hero::before {
  content: ''; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='rgba(255,255,255,0.15)' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 11c1.656 0 3-1.79 3-4s-1.344-4-3-4-3 1.79-3 4 1.344 4 3 4zM7 11c1.104 0 2-1.343 2-3S8.104 5 7 5 5 6.343 5 8s.896 3 2 3zM17 11c1.104 0 2-1.343 2-3s-.896-3-2-3-2 1.343-2 3 .896 3 2 3zM12 13c-3.313 0-6 2.686-6 6s2.687 6 6 6 6-2.686 6-6-2.687-6-6-6z'/%3E%3C/svg%3E");
  background-size: 60px 60px; pointer-events: none; z-index: 0;
}
.hero-text-content::after {
  content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(circle at center, rgba(159,122,234,0.15) 0%, transparent 60%);
  pointer-events: none; z-index: -1;
}
.home-hero h2 {
  font-size: 2.2rem; font-weight: 800; color: var(--text-main);
  margin-top: 0; margin-bottom: 1rem; border: none; padding: 0;
  line-height: 1.3; letter-spacing: -0.03em;
  position: relative; z-index: 1;
}
.home-hero p {
  color: var(--text-sub); font-size: 1.15rem;
  max-width: 600px; margin: 0 auto;
  position: relative; z-index: 1;
}

.course-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem; margin-top: 1.5rem;
}
.course-card {
  background: white; border: 1px solid var(--border-color);
  border-radius: 12px; padding: 1.5rem; display: block; text-decoration: none;
  transition: all 0.2s; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.course-card::after {
  content: '🐾'; position: absolute;
  bottom: -10px; right: -5px; font-size: 4rem;
  opacity: 0; transform: rotate(-15deg);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.course-card:hover::after {
  opacity: 0.05; transform: rotate(-15deg) scale(1.1);
}
.course-card:hover {
  transform: translateY(-4px); box-shadow: var(--shadow-md);
  border-color: #bfdbfe;
}
.course-card-badge {
  display: inline-block; font-size: 0.65rem; font-weight: 700;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.75rem;
}
.badge-L { background: #eff6ff; color: #2563eb; }
.badge-E { background: #f0fdf4; color: #16a34a; }
.badge-C { background: #fdf2f8; color: #db2777; }
.badge-O { background: #fffbeb; color: #d97706; }
.badge-S { background: #f5f3ff; color: #7c3aed; }
.badge-T { background: #ecfeff; color: #0891b2; }

.course-card h3 { font-size: 1rem; font-weight: 700; color: var(--text-main); margin: 0 0 0.5rem; }
.course-card h3::before { display: none; }
.course-card p { font-size: 0.85rem; color: var(--text-muted); margin: 0; line-height: 1.6; }

.home-stats { display: flex; gap: 1.25rem; margin: 2rem 0; flex-wrap: wrap; }
.stat-item {
  background: white; border: 1px solid var(--border-color);
  border-radius: 12px; padding: 1.25rem; text-align: center; flex: 1; min-width: 120px;
}
.stat-number { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.4rem; font-weight: 600; }

/* ============================================================
   MOBILE RESPONSIVENESS
   ============================================================ */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4); z-index: 1050; backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }
.sidebar-toggle {
  display: none; position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  width: 56px; height: 56px;
  background: var(--brand-gradient); color: white;
  border: none; border-radius: 50%; cursor: pointer;
  z-index: 1060; font-size: 1.5rem;
  align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
  transition: transform 0.2s;
}
.sidebar-toggle:hover { transform: scale(1.05); }

@media (max-width: 768px) {
  .home-hero { flex-direction: column-reverse; padding: 2rem 1.5rem; gap: 1.5rem; }
  .hero-image-container { width: 100%; }
  .hero-text-content { padding: 0; text-align: center; }
  .home-hero h2 { font-size: 1.8rem; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100vh; z-index: 1100;
    background: white; transform: translateX(-100%); transition: transform 0.3s ease;
    width: 280px; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 1.5rem 1rem 3rem; }
  article { padding: 2rem 1.5rem; border-radius: 12px; }
  .home-hero h2 { font-size: 1.8rem; }
}

@media (max-width: 480px) {
  article h1 { font-size: 1.6rem; }
  .course-grid { grid-template-columns: 1fr; }
  .article-nav { flex-direction: column; }
  .article-nav a { width: 100%; text-align: center; justify-content: center; }
  .footer-inner { flex-direction: column; gap: 1rem; text-align: center; }
  .footer-links { justify-content: center; }
}

/* ============================================================
   MOFUNEKO CHAT UI (Beginner Empathy)
   ============================================================ */
.mofuneko-chat {
  display: flex; gap: 1rem; align-items: flex-start;
  margin: 2rem 0; padding: 1.5rem;
  background: var(--bg-color); border-radius: 16px;
  border: 2px dashed #bfdbfe;
}
.chat-icon {
  flex-shrink: 0; width: 64px; height: 64px;
  background: white; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm); overflow: hidden;
  border: 2px solid var(--primary);
}
.chat-icon img { width: 100%; height: 100%; object-fit: cover; }
.chat-bubble {
  background: white; padding: 1.25rem 1.5rem;
  border-radius: 0 16px 16px 16px;
  box-shadow: var(--shadow-sm); position: relative;
  font-size: 0.95rem; color: var(--text-main); font-weight: 500;
  line-height: 1.7; width: 100%;
}
.chat-bubble::before {
  content: ''; position: absolute; top: 0; left: -10px;
  border-width: 0 10px 10px 0; border-style: solid;
  border-color: transparent white transparent transparent;
}
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble strong { color: var(--accent-pink); }

/* Golden Route (Beginner Path) */
.golden-route {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 2px solid #fde68a; border-radius: 16px;
  padding: 2rem; margin: 3rem 0; box-shadow: var(--shadow-md);
}
.golden-route h3 { margin-top: 0; color: #b45309; font-size: 1.3rem; }
.golden-route ul { list-style: none; padding: 0; margin-bottom: 0; }
.golden-route li {
  position: relative; padding-left: 2.5rem; margin-bottom: 1.25rem;
  font-weight: 600; color: #78350f;
}
.golden-route li::before {
  content: '🐾'; position: absolute; left: 0; top: 0;
  font-size: 1.2rem;
}
.golden-route a {
  display: inline-block; background: white; padding: 0.25rem 0.75rem;
  border-radius: 6px; border: 1px solid #fcd34d;
  color: #b45309; text-decoration: none; font-size: 0.9rem;
  transition: all 0.2s; margin-left: 0.5rem;
}
.golden-route a:hover {
  background: #fef3c7; transform: translateY(-2px); box-shadow: var(--shadow-sm);
}
