/* Grammar Layout - Split View */
.grammar-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  /* 화면 높이에 맞춰 고정하되, 최소 높이 보장 */
  height: calc(100vh - 140px); 
  min-height: 600px;
}

@media (min-width: 768px) {
  .grammar-layout {
    flex-direction: row;
    align-items: stretch;
  }
}

/* Sidebar (Accordion Menu) */
.grammar-sidebar {
  flex: 0 0 320px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;

  /* 스크롤 문제 해결: Flex 대신 Block 사용 및 높이 100% 강제 */
  display: block; 
  height: 100%;
  overflow-y: auto;

  padding: 1rem;
  /* gap 대신 자식 요소 margin 사용 */
}

@media (max-width: 767px) {
  .grammar-layout {
    height: auto; /* 모바일에서는 높이 제한 해제 */
  }

  .grammar-sidebar {
    flex: none;
    height: auto;
    max-height: 300px; /* 모바일에서는 스크롤 영역 제한 */
  }
}

/* Content Area */
.grammar-content-area {
  flex: 1;
  overflow-y: auto;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  position: relative;
  height: 100%; /* 부모 높이에 맞춤 */
}

/* Content Fade-in Animation - REMOVED */
/* .grammar-content-area.fade-in {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
} */

/* Accordion Items */
.acc-category {
  margin-bottom: 0.5rem; /* 사이드바 gap 대체 */
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-primary);
  overflow: hidden;
}

.acc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  cursor: pointer;
  /* transition: background-color 0.2s ease; - REMOVED */
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1rem;
  user-select: none;
}

.acc-header:hover {
  background-color: var(--bg-tertiary);
}

.acc-header.active {
  background-color: rgba(3, 102, 214, 0.15);
  color: var(--accent-primary);
}

.acc-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.acc-icon {
  /* transition: transform 0.3s ease; - REMOVED */
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

.acc-header.expanded .acc-icon {
  transform: rotate(180deg);
}

/* Accordion Body */
.acc-body {
  display: none;
  background-color: rgba(0, 0, 0, 0.02);
  border-top: 1px solid var(--border-color);
}

.acc-body.show {
  display: block;
  /* animation: slideDown 0.2s ease-out; - REMOVED */
}

/* @keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
} - REMOVED */

/* Group Items within Category */
.acc-group {
  padding: 0.25rem 0;
}

.acc-group-header {
  padding: 0.6rem 1rem 0.6rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  /* transition: color 0.2s ease; - REMOVED */
}

.acc-group-header:hover {
  color: var(--accent-primary);
}

/* [추가] 그룹 헤더 활성 상태 스타일 - 더 진하게 */
.acc-group-header.active {
  color: var(--accent-primary);
  font-weight: 700;
  background-color: rgba(3, 102, 214, 0.15);
  border-left: 3px solid var(--accent-primary);
  padding-left: 1.2rem;
}

.acc-group-body {
  display: none;
  padding: 0.25rem 0 0.5rem 0;
}

.acc-group-body.show {
  display: block;
}

/* Unit Items (Leaf Nodes) */
.acc-unit-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 1rem 0.6rem 2.2rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  /* transition: all 0.2s; - REMOVED */
}

.acc-unit-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.acc-unit-btn.active {
  background-color: rgba(3, 102, 214, 0.1);
  color: var(--accent-primary);
  border-left-color: var(--accent-primary);
  font-weight: 600;
}

/* Detail View Elements */
.grammar-detail-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.grammar-detail-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.grammar-detail-description {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

/* Example Box Styles */
.grammar-example {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  border-radius: 8px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  /* transition: transform 0.2s ease, box-shadow 0.2s ease; - REMOVED */
}

.grammar-example:hover {
  /* transform: translateX(2px); - REMOVED */
  box-shadow: var(--shadow-sm);
  border-color: var(--accent-primary);
}

.grammar-example-text {
  flex: 1;
}

.grammar-example-korean {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.grammar-example-romanization {
  font-size: 0.9rem;
  color: var(--text-tertiary);
  font-style: italic;
  margin-bottom: 0.25rem;
}

.grammar-example-ipa {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  font-family: monospace;
  opacity: 0.8;
}

.grammar-example-translation {
  margin-top: 0.4rem;
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.grammar-example-speak {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: var(--accent-tertiary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  /* transition: all 0.2s ease; - REMOVED */
  margin-top: 0.25rem;
}

.grammar-example-speak:hover {
  /* transform: scale(1.1); - REMOVED */
  opacity: 0.9;
}

.grammar-empty, .grammar-error {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Scrollbar Styling for Sidebar */
.grammar-sidebar::-webkit-scrollbar {
  width: 6px;
}
.grammar-sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.grammar-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}
.grammar-sidebar::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-tertiary);
}

/* Dark Theme Adjustments */
[data-theme="dark"] .acc-header.active {
  background-color: rgba(88, 101, 242, 0.25);
}
[data-theme="dark"] .acc-group-header.active {
  background-color: rgba(88, 101, 242, 0.25);
}
[data-theme="dark"] .acc-unit-btn.active {
  background-color: rgba(88, 101, 242, 0.2);
}
[data-theme="dark"] .grammar-example {
  background-color: rgba(255, 255, 255, 0.03);
}