/* ==========================================================================
   리눅스 커널 정리 /with MINZKN - Core Styles
   Layout, Typography, Components
   ========================================================================== */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-heading);
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2em;
  margin-bottom: 0.75em;
}

h1 { font-size: 2rem; border-bottom: 2px solid var(--accent-primary); padding-bottom: 0.4em; margin-top: 0; }
h2 { font-size: 1.6rem; border-bottom: 1px solid var(--border-primary); padding-bottom: 0.3em; }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.1rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.9rem; color: var(--text-secondary); }

h2 .section-anchor,
h3 .section-anchor,
h4 .section-anchor {
  color: var(--text-muted);
  text-decoration: none;
  margin-left: 0.3em;
  opacity: 0;
  transition: opacity 0.2s;
  font-weight: 400;
}

h2:hover .section-anchor,
h3:hover .section-anchor,
h4:hover .section-anchor {
  opacity: 1;
}

p {
  margin-bottom: 1em;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

strong { font-weight: 600; }
em { font-style: italic; }

ul, ol {
  margin-bottom: 1em;
  padding-left: 1.8em;
}

li {
  margin-bottom: 0.3em;
}

li > ul, li > ol {
  margin-top: 0.3em;
  margin-bottom: 0.3em;
}

blockquote {
  border-left: 4px solid var(--accent-primary);
  background: var(--bg-secondary);
  padding: 1em 1.2em;
  margin: 1em 0;
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}

blockquote p:last-child {
  margin-bottom: 0;
}

hr {
  border: none;
  border-top: 1px solid var(--border-primary);
  margin: 2em 0;
}

/* ---------- Monospace / Code ---------- */
code, pre, kbd, samp, .mono {
  font-family: "D2Coding", "D2 Coding", "Fira Code", "Source Code Pro", "Consolas", monospace;
}

code {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
  border: 1px solid var(--border-code);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-code);
  border-radius: 8px;
  padding: 1.2em;
  margin: 1em 0;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.88rem;
  position: relative;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: var(--text-primary);
}

pre .line-numbers {
  color: var(--text-muted);
  user-select: none;
  margin-right: 1em;
  text-align: right;
  min-width: 2em;
  display: inline-block;
}

kbd {
  background: var(--bg-kbd);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  padding: 0.1em 0.5em;
  font-size: 0.85em;
  box-shadow: inset 0 -1px 0 var(--border-primary);
}

/* Syntax highlighting classes */
.kw { color: var(--syntax-keyword); }
.str { color: var(--syntax-string); }
.cmt { color: var(--syntax-comment); font-style: italic; }
.fn { color: var(--syntax-function); }
.num { color: var(--syntax-number); }
.type { color: var(--syntax-type); }
.macro { color: var(--syntax-macro); }
.pp { color: var(--syntax-preprocessor); }

/* ---------- Code block label ---------- */
pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.2em 0.8em;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-bottom-left-radius: 6px;
  border-top-right-radius: 7px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- 3-Column Grid Layout ---------- */
.page-wrapper {
  display: grid;
  grid-template-columns: 260px 1fr 220px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header header"
    "nav    main   toc"
    "footer footer footer";
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- Header ---------- */
.site-header {
  grid-area: header;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  padding: 0 1.5em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.8em;
}

.header-logo {
  width: 32px;
  height: 32px;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-heading);
  white-space: nowrap;
}

.header-title a {
  color: inherit;
  text-decoration: none;
}

.header-title .title-accent {
  color: var(--accent-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.8em;
}

/* ---------- Search ---------- */
.search-container {
  position: relative;
}

.search-input {
  background: var(--bg-search);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.4em 0.8em 0.4em 2.2em;
  color: var(--text-primary);
  font-size: 0.9rem;
  width: 240px;
  outline: none;
  transition: border-color 0.2s, width 0.3s;
}

.search-input:focus {
  border-color: var(--border-active);
  width: 320px;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 0.7em;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 0 0 8px 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  display: none;
  box-shadow: var(--shadow-lg);
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 0.6em 1em;
  border-bottom: 1px solid var(--border-secondary);
  cursor: pointer;
  transition: background 0.15s;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-heading);
}

.search-result-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.2em;
}

.search-no-results {
  padding: 1em;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Theme Switcher ---------- */
.theme-switcher {
  position: relative;
}

.theme-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.4em 0.7em;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4em;
  transition: border-color 0.2s;
}

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

.theme-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 0.4em 0;
  min-width: 180px;
  z-index: 200;
  display: none;
  box-shadow: var(--shadow-lg);
}

.theme-dropdown.active {
  display: block;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.5em 1em;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.theme-option:hover {
  background: var(--bg-hover);
}

.theme-option.active {
  color: var(--accent-primary);
  font-weight: 600;
}

.theme-option .theme-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-primary);
  flex-shrink: 0;
}

/* ---------- Mobile Menu Toggle ---------- */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.3em;
  line-height: 1;
}

/* ---------- Side Navigation ---------- */
.side-nav {
  grid-area: nav;
  background: var(--bg-nav);
  border-right: 1px solid var(--border-primary);
  padding: 1.2em 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  margin-bottom: 0.8em;
}

.nav-section-title {
  padding: 0.4em 1.2em;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.nav-link {
  display: block;
  padding: 0.35em 1.2em 0.35em 1.6em;
  font-size: 0.9rem;
  color: var(--text-nav);
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-left 0.15s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-nav-active);
  text-decoration: none;
}

.nav-link.active {
  background: var(--bg-active);
  color: var(--text-nav-active);
  border-left-color: var(--accent-primary);
  font-weight: 600;
}

/* ---------- Main Content ---------- */
.main-content {
  grid-area: main;
  padding: 2em 2.5em;
  min-width: 0;
  max-width: 100%;
}

.content-header {
  margin-bottom: 2em;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1em;
}

.breadcrumb a {
  color: var(--text-secondary);
}

.breadcrumb .separator {
  color: var(--text-muted);
}

.page-description {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-top: 0.5em;
  line-height: 1.6;
}

/* ---------- Right-side TOC ---------- */
.toc-sidebar {
  grid-area: toc;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 1.5em 1em;
  border-left: 1px solid var(--border-primary);
  background: var(--bg-toc);
}

.toc-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1em;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list li {
  margin-bottom: 0.2em;
}

.toc-list a {
  display: block;
  padding: 0.2em 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 0.8em;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.4;
}

.toc-list a:hover {
  color: var(--text-nav-active);
  text-decoration: none;
}

.toc-list a.active {
  color: var(--text-nav-active);
  border-left-color: var(--accent-primary);
  font-weight: 600;
}

.toc-list .toc-h3 {
  padding-left: 1.6em;
  font-size: 0.78rem;
}

.toc-list .toc-h4 {
  padding-left: 2.4em;
  font-size: 0.75rem;
}

/* ---------- Inline TOC (for mobile / within content) ---------- */
.inline-toc {
  display: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1em 1.5em;
  margin-bottom: 2em;
}

.inline-toc-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 0.8em;
}

.inline-toc .toc-list a {
  font-size: 0.88rem;
}

/* ---------- Home Icon ---------- */
.home-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 1.4rem;
  text-decoration: none;
  flex-shrink: 0;
  line-height: 1;
}

.home-icon:hover {
  text-decoration: none;
  opacity: 0.8;
}

/* ---------- Footer ---------- */
.site-footer {
  grid-area: footer;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-primary);
  padding: 1.5em 2em;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

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

.footer-license {
  margin-top: 0.3em;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-license a {
  color: var(--text-secondary);
}

.footer-powered {
  margin-top: 0.5em;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-powered a {
  color: var(--text-secondary);
}

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2em;
  margin: 1.5em 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  padding: 1.4em;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-primary);
}

.card a {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-icon {
  font-size: 1.8rem;
  margin-bottom: 0.5em;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 0.4em;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
  flex-grow: 1;
}

.card-tags {
  display: flex;
  gap: 0.4em;
  flex-wrap: wrap;
  margin-top: 0.8em;
}

.tag {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 0.15em 0.6em;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ---------- Tables ---------- */
.table-responsive {
  overflow-x: auto;
  margin: 1em 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.92rem;
}

th, td {
  padding: 0.6em 1em;
  border: 1px solid var(--border-primary);
  text-align: left;
}

th {
  background: var(--bg-table-header);
  font-weight: 600;
  color: var(--text-heading);
}

tr:nth-child(even) {
  background: var(--bg-table-stripe);
}

/* ---------- Info / Warning / Tip Boxes ---------- */
.info-box {
  border-radius: 8px;
  padding: 1em 1.2em;
  margin: 1.2em 0;
  border-left: 4px solid;
  display: flex;
  gap: 0.8em;
}

.info-box .box-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  line-height: 1.5;
}

.info-box .box-content p:last-child {
  margin-bottom: 0;
}

.info-box.info {
  background: var(--info-bg-info);
  border-color: var(--accent-info);
}

.info-box.warning {
  background: var(--info-bg-warning);
  border-color: var(--accent-warning);
}

.info-box.danger {
  background: var(--info-bg-danger);
  border-color: var(--accent-danger);
}

.info-box.tip {
  background: var(--accent-glow);
  border-color: var(--accent-primary);
}

/* ---------- Diagrams (Inline SVG) ---------- */
.diagram-container {
  background: var(--diagram-bg);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1.5em;
  margin: 1.5em 0;
  overflow-x: auto;
  text-align: center;
}

.diagram-container svg {
  max-width: 100%;
  height: auto;
}

.diagram-container svg text {
  fill: var(--diagram-text);
  font-family: "D2Coding", monospace;
  font-size: 13px;
}

.diagram-container svg rect,
.diagram-container svg .box {
  fill: var(--diagram-fill);
  stroke: var(--diagram-stroke);
  stroke-width: 2;
}

.diagram-container svg .box-accent {
  fill: var(--diagram-fill);
  stroke: var(--diagram-accent);
  stroke-width: 2;
}

.diagram-container svg line,
.diagram-container svg polyline,
.diagram-container svg path.arrow {
  stroke: var(--diagram-arrow);
  stroke-width: 1.5;
  fill: none;
}

.diagram-container svg marker path {
  fill: var(--diagram-arrow);
}

.diagram-caption {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.8em;
  font-style: italic;
}

/* ---------- ASCII Art ---------- */
.ascii-art {
  background: var(--bg-code);
  border: 1px solid var(--border-code);
  border-radius: 8px;
  padding: 1.2em;
  margin: 1em 0;
  overflow-x: auto;
  font-family: "D2Coding", monospace;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--accent-primary);
  white-space: pre;
}

/* ---------- Hero Section ---------- */
.hero {
  background: var(--bg-hero);
  border-bottom: 1px solid var(--border-primary);
  padding: 3em 2.5em;
  text-align: center;
}

.hero h1 {
  font-size: 2.4rem;
  border: none;
  margin-bottom: 0.3em;
  padding: 0;
}

.hero .subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 2em;
}

.hero .doc-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: -0.5em auto 2em;
  letter-spacing: 0.02em;
}

.hero .doc-meta strong {
  color: var(--accent-primary);
  font-weight: 600;
}

/* ---------- Section separators ---------- */
.section-divider {
  display: flex;
  align-items: center;
  gap: 1em;
  margin: 2.5em 0 1.5em;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.section-divider::before,
.section-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border-primary);
}

/* ---------- Previous/Next Navigation ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  margin-top: 3em;
  padding-top: 1.5em;
  border-top: 1px solid var(--border-primary);
}

.page-nav a {
  display: flex;
  flex-direction: column;
  padding: 0.8em 1.2em;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
  max-width: 48%;
}

.page-nav a:hover {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
  text-decoration: none;
}

.page-nav .nav-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.page-nav .nav-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-link);
}

.page-nav .next {
  text-align: right;
  margin-left: auto;
}

/* ---------- Back to Top ---------- */
.back-to-top {
  position: fixed;
  bottom: 2em;
  right: 2em;
  background: var(--accent-primary);
  color: var(--bg-primary);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
}

.back-to-top:hover {
  transform: translateY(-2px);
}

/* ---------- Ads container ---------- */
.ad-container {
  margin: 2em 0;
  text-align: center;
  min-height: 90px;
}

/* ---------- Mobile Nav Overlay ---------- */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 90;
}

.nav-overlay.active {
  display: block;
}

/* ---------- Focus Visible ---------- */
:focus-visible {
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
}

/* ---------- Selection ---------- */
::selection {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

/* ---------- Beginner Guide Section ---------- */
.beginner-guide {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  padding: 1.5em 2em;
  margin: 1.5em 0 2em;
}
.beginner-guide h2 {
  font-size: 1.3rem;
  margin-top: 1.5em;
  border-bottom: 1px dashed var(--border-primary);
  padding-bottom: 0.3em;
}
.beginner-guide h2:first-of-type { margin-top: 0.5em; }
.beginner-guide .info-box { margin: 0.8em 0; }
.beginner-guide .info-box:first-child { margin-top: 0; }
.beginner-summary ul { list-style: none; padding-left: 0; }
.beginner-summary ul li {
  padding: 0.4em 0 0.4em 1.4em;
  position: relative;
}
.beginner-summary ul li::before {
  content: "\2713"; position: absolute; left: 0;
  color: var(--accent-primary); font-weight: bold;
}
.beginner-steps ol { counter-reset: step-counter; list-style: none; padding-left: 0; }
.beginner-steps ol li {
  counter-increment: step-counter;
  padding: 0.8em 0 0.8em 2.8em;
  position: relative;
  border-bottom: 1px solid var(--border-secondary, var(--border-primary));
}
.beginner-steps ol li:last-child { border-bottom: none; }
.beginner-steps ol li::before {
  content: counter(step-counter);
  position: absolute; left: 0; top: 0.8em;
  width: 2em; height: 2em; border-radius: 50%;
  background: var(--accent-primary); color: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem;
}
.beginner-steps ol li p {
  margin: 0.3em 0 0;
  color: var(--text-secondary);
}

/* ---------- Print ---------- */
@media print {
  .side-nav, .toc-sidebar, .site-header, .site-footer,
  .theme-switcher, .search-container, .back-to-top,
  .mobile-menu-toggle, .page-nav, .ad-container {
    display: none !important;
  }
  .page-wrapper {
    display: block;
  }
  .main-content {
    padding: 0;
  }
  body {
    color: #000;
    background: #fff;
  }
}
