/* ==========================================================================
   📚 연 콘텐츠 공용 상단 툴바 위젯 - aha-toolbar.css (학습과학/교과서 공용)
   ========================================================================== */

/* 툴바 기본 레이아웃 */
.top-toolbar {
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  height: 56px;
  background-color: rgba(253, 251, 247, 0.96); /* 밝은 아이보리 한지 톤 */
  border-bottom: 1px solid #e7dfd3;
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* 브랜드(좌), 메뉴(중), 액션(우) 3분할 */
  align-items: center;
  padding: 0 16px;
  box-sizing: border-box;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  font-family: 'Noto Sans KR', sans-serif;
}

.toolbar-brand {
  justify-self: start;
  font-family: 'Outfit', 'Nanum Myeongjo', serif;
  font-weight: 800;
  font-size: 1.1rem;
  color: #4a3e2e;
  letter-spacing: -0.01em;
}

.menu-center-btn {
  justify-self: center;
}

.toolbar-actions {
  justify-self: end;
  display: flex;
  gap: 12px;
}

.toolbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.toolbar-btn:hover {
  background-color: rgba(74, 62, 46, 0.06);
}

.plain-svg {
  fill: #4a3e2e;
  transition: fill 0.2s;
}

/* 오버레이 패널 공통 */
.toolbar-panel {
  position: fixed;
  top: 0;
  height: 100vh;
  width: 320px;
  background-color: #fdfbf7;
  border-left: 1px solid #e7dfd3;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 20px;
  box-sizing: border-box;
  font-family: 'Noto Sans KR', sans-serif;
}

#panel-menu {
  left: 0;
  border-left: none;
  border-right: 1px solid #e7dfd3;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.08);
  transform: translateX(-100%);
}

#panel-options {
  right: 0;
  transform: translateX(100%);
}

.toolbar-panel.panel-hidden {
  /* hidden 상태 */
}

#panel-menu:not(.panel-hidden) {
  transform: translateX(0);
}

#panel-options:not(.panel-hidden) {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e7dfd3;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.panel-header h3 {
  margin: 0;
  color: #4a3e2e;
  font-size: 1.2rem;
  font-family: 'Nanum Myeongjo', serif;
  font-weight: 700;
}

.btn-close-panel {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: #8c7d6b;
  cursor: pointer;
}

/* 메뉴 리스트 */
.menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-list li {
  margin-bottom: 12px;
}

.menu-list a {
  text-decoration: none;
  color: #5c4e3c;
  font-size: 1.05rem;
  display: block;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
  font-weight: 500;
}

.menu-list a:hover {
  background-color: rgba(74, 62, 46, 0.05);
  color: #1a0f00;
}

.menu-list hr {
  border: 0;
  border-top: 1px solid #e7dfd3;
  margin: 16px 0;
}

/* 옵션 설정 스타일 */
.options-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.option-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #4a3e2e;
  font-size: 1rem;
}

.option-item.flex-col {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.option-btn-toggle {
  background-color: #e7dfd3;
  border: none;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: bold;
  color: #5c4e3c;
  transition: background-color 0.2s, color 0.2s;
}

.option-btn-toggle.active {
  background-color: #4a3e2e;
  color: #fdfbf7;
}

.zoom-controls {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-zoom {
  flex: 1;
  background-color: #f5f1e9;
  border: 1px solid #e7dfd3;
  padding: 8px 4px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #5c4e3c;
  transition: all 0.2s;
  font-family: 'Noto Sans KR', sans-serif;
  font-weight: 500;
}

.btn-zoom.active {
  background-color: #4a3e2e;
  border-color: #4a3e2e;
  color: #fdfbf7;
}

/* 🔍 검색 오버레이 레이아웃 */
.search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(26, 15, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 3000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 80px;
  box-sizing: border-box;
}

.search-overlay.panel-hidden {
  display: none;
}

.search-container {
  width: 90%;
  max-width: 600px;
  background-color: #fdfbf7;
  border: 1px solid #e7dfd3;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}

.search-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e7dfd3;
  background-color: #f5f1e9;
}

#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 1.1rem;
  color: #4a3e2e;
  padding: 4px 0;
  font-family: 'Noto Sans KR', sans-serif;
}

.search-close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: #8c7d6b;
  cursor: pointer;
  padding: 0 8px;
}

.search-results-list {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-placeholder {
  color: #8c7d6b;
  text-align: center;
  padding: 24px 0;
  font-family: 'Noto Sans KR', sans-serif;
}

.search-result-item {
  padding: 12px;
  border-radius: 6px;
  background-color: #fdfbf7;
  border: 1px solid #f0e9dd;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: block;
  font-family: 'Noto Sans KR', sans-serif;
}

.search-result-item:hover {
  background-color: #f5f1e9;
  border-color: #d8cebe;
}

.search-result-title {
  font-weight: 700;
  color: #4a3e2e;
  margin-bottom: 4px;
}

.search-result-context {
  font-size: 0.9rem;
  color: #6e604f;
  line-height: 1.4;
}

/* 🌓 다크모드 반전 트릭 (CSS Filter) */
body.dark-mode {
  filter: invert(1) hue-rotate(180deg);
  background-color: #000; /* 역전 시 깨끗한 암실 구현 */
}

/* 다크모드 시 미디어 자료, 동영상(iframe), 캔버스 등 재반전으로 화질 보존 */
body.dark-mode iframe,
body.dark-mode video,
body.dark-mode img,
body.dark-mode .plain-svg,
body.dark-mode .keep-color,
body.dark-mode .cover-container,
body.dark-mode header.magazine-cover,
body.dark-mode footer {
  filter: invert(1) hue-rotate(180deg);
}

/* 🔍 글자 크기 줌 제어 (사파리 등 모바일 표준 호환) */
body.zoom-small p,
body.zoom-small blockquote,
body.zoom-small td,
body.zoom-small th,
body.zoom-small li,
body.zoom-small .time-stamp {
  font-size: 0.9em !important;
}
body.zoom-normal p,
body.zoom-normal blockquote,
body.zoom-normal td,
body.zoom-normal th,
body.zoom-normal li,
body.zoom-normal .time-stamp {
  /* 기본 크기 유지 */
}
body.zoom-large p,
body.zoom-large blockquote,
body.zoom-large td,
body.zoom-large th,
body.zoom-large li,
body.zoom-large .time-stamp {
  font-size: 1.22em !important;
}

/* 검색 하이라이트 애니메이션 */
.search-highlight {
  animation: highlight-pulse 2s ease;
  border-radius: 4px;
}

@keyframes highlight-pulse {
  0% {
    background-color: rgba(230, 180, 80, 0.4);
    box-shadow: 0 0 10px rgba(230, 180, 80, 0.3);
  }
  100% {
    background-color: transparent;
    box-shadow: none;
  }
}

/* 인쇄 시 툴바 숨김 */
@media print {
  .top-toolbar,
  .toolbar-panel,
  .search-overlay {
    display: none !important;
  }
}
