/* Formula Student Korea 차량기술규정 스타일 */

/* 로컬 폰트 */
@font-face {
  font-family: 'Noto Sans KR';
  font-weight: 400;
  font-style: normal;
  src: url('fonts/NotoSansKR-Regular.woff2') format('woff2');
  font-display: swap;
}

@font-face {
  font-family: 'Noto Sans KR';
  font-weight: 700;
  font-style: normal;
  src: url('fonts/NotoSansKR-Bold.woff2') format('woff2');
  font-display: swap;
}

:root {
  --primary-color: #1a365d;
  --secondary-color: #2c5282;
  --accent-color: #3182ce;
  --border-color: #d8dce0;
  --bg-light: #f0f2f4;
  --bg-header: #e4e7eb;
  --bg-body: #f8f9fa;
  --text-color: #1a202c;
  --text-muted: #5a6570;
  --toc-width: 280px;
  --table-stripe: #f0f2f4;
  --table-hover: #e4e7eb;
  --shadow-color: rgba(0, 0, 0, 0.1);
}

/* 다크 모드 */
[data-theme="dark"] {
  --primary-color: #c8c8c8;
  --secondary-color: #a0a0a0;
  --accent-color: #6cb6d9;
  --border-color: #484848;
  --bg-light: #262626;
  --bg-header: #303030;
  --bg-body: #1e1e1e;
  --text-color: #c0c0c0;
  --text-muted: #808080;
  --table-stripe: #262626;
  --table-hover: #333333;
  --shadow-color: rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: 'Noto Sans KR', sans-serif;
  margin: 0;
  padding: 0;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--bg-body);
  font-size: 15px;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* TOC Sidebar */
#toc {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--toc-width);
  height: 100vh;
  background-color: var(--bg-light);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 100;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.toc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 1.1em;
  font-weight: 700;
  color: var(--primary-color);
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-header);
  position: sticky;
  top: 0;
}

/* 목차 닫기 버튼 (데스크탑에서 숨김) */
#toc-close {
  display: none;
  width: 32px;
  height: 32px;
  background-color: transparent;
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1em;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}

#toc-close:hover {
  background-color: var(--bg-light);
}

.toc-content {
  padding: 12px 0;
  display: flex;
  flex-direction: column;
}

.toc-content a {
  display: block;
  padding: 6px 16px;
  color: var(--text-color);
  text-decoration: none;
  font-size: 0.85em;
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.toc-content a:hover {
  background-color: var(--bg-header);
  border-left-color: var(--accent-color);
}

.toc-content a.toc-chapter {
  font-family: 'Noto Sans KR', sans-serif;
  font-weight: 600;
  color: var(--primary-color);
  padding-top: 12px;
  padding-bottom: 8px;
  margin-top: 4px;
}

.toc-content a.toc-section {
  padding-left: 24px;
  color: var(--text-muted);
  font-size: 0.8em;
}

.toc-content a.toc-section:hover {
  color: var(--text-color);
}

.toc-content a.active {
  color: var(--accent-color);
  font-weight: 600;
}

.toc-content a.toc-chapter.active {
  color: var(--accent-color);
}

/* TOC Toggle Button */
#toc-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background-color: var(--primary-color);
  color: var(--bg-body);
  border: none;
  border-radius: 6px;
  width: 40px;
  height: 40px;
  font-size: 1.2em;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-color);
}

#toc-toggle:hover {
  background-color: var(--secondary-color);
}

/* 다크 모드 토글 버튼 */
#theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 200;
  background-color: var(--bg-header);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  width: 40px;
  height: 40px;
  font-size: 1.2em;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-color);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

#theme-toggle:hover {
  background-color: var(--bg-light);
}

[data-theme="dark"] #toc-toggle {
  color: var(--bg-light);
}

/* Main Content */
#content {
  max-width: 960px;
  padding: 40px 24px;
  overflow-x: hidden;
  /* Center content in the space right of TOC */
  margin-left: max(var(--toc-width), calc((100vw - 960px) / 2));
  margin-right: auto;
}

/* 제목 스타일 */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Noto Sans KR', sans-serif;
  color: var(--primary-color);
  margin-top: 2em;
  margin-bottom: 0.8em;
  line-height: 1.4;
}

h1 {
  font-size: 1.75em;
  padding-bottom: 0.5em;
  border-bottom: 3px solid var(--primary-color);
  margin-top: 2.5em;
}

h1:first-of-type {
  margin-top: 1em;
}

h2 {
  font-size: 1.35em;
  padding-left: 12px;
  border-left: 4px solid var(--accent-color);
  margin-top: 1.8em;
}

h3 {
  font-size: 1.15em;
  color: var(--secondary-color);
}

/* 문서 헤더 */
.center, div.center {
  text-align: center;
  padding: 30px 20px;
  margin-bottom: 30px;
}

.center p {
  margin: 0;
  line-height: 1.8;
  text-align: center;
}

/* 문서 헤더 내 span 기본 스타일 */
.center span {
  font-size: inherit;
  font-weight: inherit;
}

/* 문서 제목 (첫 번째 span만) */
.center > p > span:first-child {
  display: inline;
  font-size: 2em;
  font-weight: bold;
  font-family: 'Noto Sans KR', sans-serif;
  color: var(--text-color);
}

/* 단락 */
p {
  margin: 0.5em 0;
  text-align: justify;
}

/* 목록 스타일 */
ol {
  list-style: none;
  counter-reset: item;
  padding-left: 1.5em;
  margin: 0.6em 0;
}

ol > li {
  counter-increment: item;
  margin-bottom: 0.4em;
  padding-left: 1.8em;
  position: relative;
}

ol > li::before {
  content: counter(item, decimal-enclosed-circle);
  position: absolute;
  left: 0;
  top: 0;
  color: var(--text-color);
}

/* 2단계 목록 */
ol ol {
  counter-reset: subitem;
  margin-top: 0.3em;
  margin-bottom: 0.3em;
}

ol ol > li {
  counter-increment: subitem;
  padding-left: 1.5em;
  margin-bottom: 0.3em;
}

ol ol > li::before {
  content: counter(subitem) ".";
  color: var(--text-color);
}

/* 3단계 목록 */
ol ol ol {
  counter-reset: subsubitem;
}

ol ol ol > li {
  counter-increment: subsubitem;
}

ol ol ol > li::before {
  content: counter(subsubitem, hangul-consonant) ".";
  color: var(--text-color);
}

/* 순서 없는 목록 */
ul {
  padding-left: 1.5em;
  margin: 0.8em 0;
}

ul li {
  margin-bottom: 0.4em;
}

/* 이미지와 그림 */
figure {
  text-align: center;
  margin: 1.5em auto;
  padding: 0;
}

figure img {
  max-width: 100%;
  height: auto;
}

figcaption {
  font-weight: bold;
  margin-top: 0.5em;
  color: var(--text-color);
  font-family: 'Noto Sans KR', sans-serif;
  font-size: 0.9em;
}

/* 테이블 */
table {
  border-collapse: collapse;
  width: 100%;
  max-width: 100%;
  margin: 1.5em 0;
  font-size: 0.95em;
  box-shadow: 0 1px 3px var(--shadow-color);
  border-radius: 8px;
}

thead {
  background-color: var(--primary-color);
  color: var(--bg-body);
}

[data-theme="dark"] thead {
  background-color: var(--bg-header);
  color: var(--text-color);
}

th {
  padding: 12px 16px;
  text-align: center;
  font-weight: 600;
  font-family: 'Noto Sans KR', sans-serif;
}

td {
  padding: 10px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

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

tbody tr:hover {
  background-color: var(--table-hover);
}

/* 수식 */
.math, mjx-container {
  overflow-x: auto;
  padding: 0.5em 0;
  max-width: 100%;
}

/* 강조 */
strong, b {
  color: var(--primary-color);
}

em, i {
  color: var(--secondary-color);
}

/* 구분선 */
hr {
  border: none;
  border-top: 2px solid var(--border-color);
  margin: 2em 0;
}

/* description list */
dl {
  margin: 1em 0;
  padding-left: 1em;
}

dt {
  font-weight: bold;
  color: var(--secondary-color);
  margin-top: 0.8em;
}

dd {
  margin-left: 1.5em;
  margin-bottom: 0.5em;
}

/* 인용구/블록 */
blockquote {
  margin: 1.5em 0;
  padding: 1em 1.5em;
  border-left: 4px solid var(--accent-color);
  background-color: var(--bg-light);
  border-radius: 0 8px 8px 0;
}

/* 링크 */
a {
  color: var(--accent-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* 참조 링크 */
a.ref-link, a[href^="#"] {
  color: var(--accent-color);
}

a.ref-link:hover, a[href^="#"]:hover {
  text-decoration: underline;
}

/* 앵커 타겟 하이라이트 */
:target {
  animation: highlight 2s ease-out;
}

@keyframes highlight {
  0% { background-color: rgba(255, 230, 0, 0.4); }
  100% { background-color: transparent; }
}

/* 밑줄 (양식) */
u {
  text-decoration: none;
  border-bottom: 1px solid var(--text-color);
  padding-bottom: 2px;
  min-width: 100px;
  display: inline-block;
}

/* 코드 블록 */
code, pre {
  font-family: 'D2Coding', 'Consolas', monospace;
  background-color: var(--bg-light);
  border-radius: 4px;
  transition: background-color 0.3s ease;
}

code {
  padding: 2px 6px;
  font-size: 0.9em;
}

pre {
  padding: 1em;
  overflow-x: auto;
  border: 1px solid var(--border-color);
}

/* 다크 모드 이미지 */
[data-theme="dark"] figure img {
  opacity: 0.9;
  filter: brightness(0.95);
}

/* 텍스트 선택 링크 버튼 */
#share-selection {
  display: none;
  position: absolute;
  z-index: 300;
  background-color: var(--primary-color);
  color: var(--bg-body);
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85em;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-color);
  white-space: nowrap;
  font-family: 'Noto Sans KR', sans-serif;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

#share-selection:hover {
  background-color: var(--secondary-color);
  transform: translateY(-1px);
}

#share-selection.copied {
  background-color: #38a169;
}

[data-theme="dark"] #share-selection {
  background-color: #404040;
  color: #e0e0e0;
}

[data-theme="dark"] #share-selection:hover {
  background-color: #505050;
}

/* 이전 위치로 돌아가기 버튼 */
#back-to-position {
  display: none;
  align-items: center;
  gap: 6px;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 300;
  background-color: var(--primary-color);
  color: var(--bg-body);
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 0.9em;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--shadow-color);
  font-family: 'Noto Sans KR', sans-serif;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.15s ease;
}

#back-to-position.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#back-to-position:hover {
  background-color: var(--secondary-color);
}

#back-to-position:active {
  transform: translateX(-50%) translateY(2px);
}

/* 하이라이트된 텍스트 */
.text-highlight {
  background-color: #fef08a;
  padding: 2px 0;
  border-radius: 2px;
}

[data-theme="dark"] .text-highlight {
  background-color: #505050;
  color: #ffffff;
}

/* 반응형 - 태블릿 */
@media (max-width: 1024px) {
  body {
    overflow-x: hidden;
  }

  #toc {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: none;
  }

  #toc.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }

  /* 목차가 열리면 외부 토글 버튼 숨김 */
  #toc.open ~ #toc-toggle {
    opacity: 0;
    pointer-events: none;
  }

  #toc-toggle {
    display: block;
    transition: opacity 0.2s ease;
  }

  /* 목차 내부 닫기 버튼 표시 */
  #toc-close {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #theme-toggle {
    right: 12px;
  }

  #content {
    margin-left: 0;
    padding-top: 60px;
  }

  #back-to-position {
    bottom: 20px;
  }
}

/* 반응형 - 모바일 */
@media (max-width: 768px) {
  #content {
    padding: 60px 16px 20px;
    font-size: 14px;
    max-width: 100vw;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  #toc {
    width: 260px;
  }

  #back-to-position {
    bottom: 16px;
    padding: 10px 14px;
    font-size: 0.85em;
  }

  h1 {
    font-size: 1.5em;
    margin-top: 1.5em;
  }

  h2 {
    font-size: 1.25em;
    padding-left: 8px;
    margin-top: 1.2em;
  }

  .center span {
    font-size: 1.5em;
  }

  /* 최상위 목록 들여쓰기 제거 */
  #content > ol,
  #content > ul {
    padding-left: 0;
  }

  ol > li {
    padding-left: 1.4em;
  }

  ol ol > li {
    padding-left: 1.2em;
  }

  ul {
    padding-left: 1.2em;
  }

  table {
    font-size: 0.8em;
    width: 100%;
    max-width: calc(100vw - 32px);
    display: block;
    overflow-x: auto;
  }

  tbody, thead, tr, th, td {
    display: revert;
  }

  th, td {
    padding: 6px 8px;
  }

  figure img {
    max-width: 100%;
  }

  figure {
    margin: 1em 0;
  }

  dl {
    padding-left: 0.5em;
  }

  dd {
    margin-left: 1em;
  }
}

/* 인쇄 스타일 */
@media print {
  #toc, #toc-toggle, #theme-toggle, #back-to-position, #share-selection {
    display: none !important;
  }

  #content {
    margin-left: 0;
    max-width: none;
    padding: 0;
    font-size: 11pt;
  }

  h1, h2 {
    page-break-after: avoid;
  }

  figure, table {
    page-break-inside: avoid;
  }

  a {
    color: var(--text-color);
  }
}

/* 한글 원문자 카운터 */
@counter-style decimal-enclosed-circle {
  system: fixed;
  symbols: "①" "②" "③" "④" "⑤" "⑥" "⑦" "⑧" "⑨" "⑩"
           "⑪" "⑫" "⑬" "⑭" "⑮" "⑯" "⑰" "⑱" "⑲" "⑳";
}

@counter-style hangul-consonant {
  system: fixed;
  symbols: "가" "나" "다" "라" "마" "바" "사" "아" "자" "차" "카" "타" "파" "하";
}
