:root {
  /* Light Mode Defaults */
  --primary-color: #2563eb;
  --bg-body: #f8fafc;
  --bg-content: #ffffff;
  --text-main: #334155;
  --text-heading: #1e293b;
  --text-sub: #64748b;
  --border-color: #e2e8f0;
  --toc-hover: #f1f5f9;
  --highlight-bg: #eff6ff;

  /* Scrollbar Colors (Light) */
  --scrollbar-thumb: #cbd5e1;
  --scrollbar-thumb-hover: #94a3b8;

  /* Component Colors */
  --box-bg: #ffffff;
  --box-border: #cbd5e1;
  --tip-border: #f59e0b;
  --quiz-bg: #fff1f2;
  --quiz-border: #fda4af;
  --laugh-bg: linear-gradient(135deg, #a78bfa 0%, #60a5fa 100%);

  /* Diagram Colors */
  --diagram-bg: #f1f5f9;
  --bracket-line: #475569;
}

body.dark-mode {
  /* Dark Mode Defaults */
  --primary-color: #60a5fa;
  --bg-body: #121212;
  --bg-content: #1e1e1e;
  --text-main: #e2e8f0;
  --text-heading: #f1f5f9;
  --text-sub: #94a3b8;
  --border-color: #333333;
  --toc-hover: #2d2d2d;
  --highlight-bg: #2a2a2a;

  /* Scrollbar Colors (Dark) */
  --scrollbar-thumb: #334155;
  --scrollbar-thumb-hover: #475569;

  /* Component Colors */
  --box-bg: #252525;
  --box-border: #404040;
  --tip-border: #d97706;
  --quiz-bg: #252525;
  --quiz-border: #881337;

  /* Diagram Colors */
  --diagram-bg: #252525;
  --bracket-line: #94a3b8;
}

* {
  box-sizing: border-box;
  transition:
    background-color 0.3s,
    color 0.3s;
}

body {
  font-family: "Pretendard", "Noto Sans KR", sans-serif;
  line-height: 1.8;
  color: var(--text-main);
  background-color: var(--bg-body);
  margin: 0;
  display: flex;
  justify-content: center;
}

/* Layout */
.container {
  display: flex;
  max-width: 1400px;
  width: 100%;
  position: relative;
}

main {
  flex: 1;
  padding: 50px 70px;
  background: var(--bg-content);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
  min-width: 0;
}

aside {
  /* width: 280px; */
  width: 330px;
  flex-shrink: 0;
  padding: 20px;
  background: var(--bg-body);
  border-left: 1px solid var(--border-color);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;

  /* Standard Scrollbar for Firefox */
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* Webkit Scrollbar Styling */
aside::-webkit-scrollbar {
  width: 6px;
}
aside::-webkit-scrollbar-track {
  background: transparent;
}
aside::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 10px;
}
aside::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}
/* 1. 기본 상태: 방문하지 않은 링크 */
a:link {
  color: #007bff;
  text-decoration: none; /* 밑줄 제거 */
}

/* 2. 방문한 상태 */
a:visited {
  color: #6610f2;
}

/* 3. 마우스를 올린 상태 */
a:hover {
  color: #0056b3;
  text-decoration: underline; /* 밑줄 표시 */
  cursor: pointer;
}

/* 4. 클릭 중인 상태 */
a:active {
  color: #ff0000;
}

/* 5. 포커스 상태 (키보드 접근성) */
a:focus {
  outline: 2px solid #ffc107;
}

/* TOC */
.toc-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-color);
}
.toc-title {
  font-weight: 800;
  color: var(--text-heading);
  margin: 0;
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc-link {
  display: block;
  text-decoration: none;
  color: var(--text-sub);
  font-size: 0.9rem;
  padding: 6px 12px;
  border-left: 3px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-link:hover {
  background-color: var(--toc-hover);
  color: var(--primary-color);
  /* font-size: 0.6rem; */
  white-space: normal;
  overflow: visible;
}
.toc-link.active {
  color: var(--primary-color);
  border-left-color: var(--primary-color);
  background-color: var(--highlight-bg);
  font-weight: 700;
}
.toc-sub-list {
  padding-left: 15px;
  display: none;
}

/* [Modified] Show sub-list on hover OR when active */
.toc-item:hover > .toc-sub-list,
.toc-item.active-parent > .toc-sub-list {
  display: block;
}

/* Content Styles */
h1 {
  font-size: 2.2rem;
  color: var(--text-heading);
  border-bottom: 4px solid var(--primary-color);
  padding-bottom: 20px;
  margin-bottom: 40px;
}
h2 {
  font-size: 1.6rem;
  color: var(--primary-color);
  margin-top: 60px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}
h3 {
  font-size: 1.2rem;
  color: var(--text-heading);
  margin-top: 30px;
  border-left: 4px solid var(--primary-color);
  padding-left: 10px;
}

p {
  margin-bottom: 10px;
  word-break: keep-all;
}

/* Specific Grammar Blocks */
.example-block {
  background-color: var(--box-bg);
  border: 1px solid var(--box-border);
  padding: 15px;
  border-radius: 6px;
  margin: 10px 0;
}
.example-en {
  font-weight: 600;
  color: var(--text-heading);
  display: block;
  margin-bottom: 4px;
}
.example-ko {
  color: var(--text-sub);
  font-size: 0.95em;
}

.tip-block {
  margin: 15px 0;
  padding: 15px;
  border-left: 4px solid var(--tip-border);
  background-color: var(--box-bg);
  font-size: 0.95em;
}
.tip-icon {
  color: var(--tip-border);
  font-weight: bold;
  margin-right: 5px;
}

.ref-block {
  background-color: var(--highlight-bg);
  padding: 15px;
  border-radius: 6px;
  margin: 15px 0;
  font-size: 0.95em;
}

/* NEW: Diagram Styles */
.diagram-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin: 20px 0;
  padding: 20px;
  background-color: var(--diagram-bg);
  border: 1px solid var(--box-border);
  border-radius: 8px;
  font-family: "Segoe UI", sans-serif;
}
.diagram-part {
  margin: 0 5px;
  font-weight: 600;
  color: var(--text-heading);
}
.bracket-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 2px solid var(--bracket-line);
  padding-left: 12px;
  margin: 0 15px;
  gap: 8px;
}
.bracket-group span {
  position: relative;
  color: var(--text-main);
}
.bracket-group span::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 8px;
  height: 2px;
  background-color: var(--bracket-line);
}

/* Formula Table Style */
.formula-box {
  background-color: var(--box-bg);
  border: 1px solid var(--primary-color);
  border-radius: 8px;
  padding: 10px;
  margin: 20px 0;
  overflow-x: auto;
}
table.formula {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 0.9em;
}
table.formula th,
table.formula td {
  padding: 8px;
  border: 1px solid var(--border-color);
}
table.formula th {
  background-color: var(--highlight-bg);
  color: var(--text-heading);
}

/* Quiz & Humor */
.quiz-section {
  margin-top: 40px;
  padding: 20px;
  border: 2px dashed var(--quiz-border);
  border-radius: 10px;
  background-color: var(--quiz-bg);
}
.myco {
  border: 2px dashed burlywood;
}
.quiz-title {
  color: #be123c;
  font-weight: bold;
  margin-bottom: 15px;
  font-size: 1.1em;
}
.quiz-item {
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 15px;
}

details {
  margin-top: 10px;
  cursor: pointer;
}
summary {
  font-weight: bold;
  color: var(--primary-color);
}
.answer-box {
  margin-top: 10px;
  padding: 10px;
  background: var(--highlight-bg);
  border-radius: 5px;
  font-size: 0.9em;
}

.humor-box {
  background: var(--laugh-bg);
  color: white;
  padding: 20px;
  border-radius: 10px;
  margin: 40px 0;
}
.humor-title {
  font-weight: bold;
  font-size: 1.2em;
  margin-bottom: 10px;
}

/* Utility */
.theme-btn {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: var(--text-heading);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Basic Tables */
table.basic-table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  font-size: 0.95em;
}
table.basic-table th,
table.basic-table td {
  border: 1px solid var(--border-color);
  padding: 8px;
  text-align: left;
}
table.basic-table th {
  background-color: var(--highlight-bg);
  font-weight: bold;
}

/* Mobile */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }
  aside {
    width: 100%;
    height: auto;
    position: static;
    border-bottom: 1px solid var(--border-color);
    max-height: 200px;
  }
  main {
    padding: 20px;
  }
  .diagram-container {
    flex-direction: column;
    align-items: flex-start;
  }
  .bracket-group {
    border-left: 2px solid var(--bracket-line);
    margin: 10px 0;
  }
}
