:root {
  /* Eye-Comfort Warm Palette */
  --bg-app: #f5f5f0;
  /* Warm light beige/grey */
  --bg-paper: #fafaf9;
  /* Warm off-white (Stone-50) */
  --text-primary: #44403c;
  /* Warm dark gray (Stone-700) */
  --text-secondary: #78716c;
  /* Warm medium gray (Stone-500) */
  --text-tertiary: #a8a29e;
  /* Stone-400 */

  /* Brand Colors - Sage/Nature inspired */
  --primary-color: #578e7e;
  /* Sage Green */
  --primary-hover: #437063;
  /* Darker Sage */
  --primary-strong: #2f6d58;
  /* Deep Sage for active highlights */
  --primary-light: #eef5f3;
  /* Very light sage */

  /* Grading Colors - Muted */
  --success-color: #4d7c74;
  /* Muted Teal/Green */
  --success-bg: #f0fdf4;
  --error-color: #be123c;
  /* Rose-700 (Softer than pure red) */
  --error-bg: #fff1f2;

  /* UI Elements */
  --border-color: #e7e5e4;
  /* Stone-200 */
  --focus-ring: rgba(87, 142, 126, 0.4);
  /* Sage focus ring */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Shadows - Warmer tint */
  --shadow-sm: 0 1px 2px 0 rgba(68, 64, 60, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(68, 64, 60, 0.08), 0 2px 4px -1px rgba(68, 64, 60, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(68, 64, 60, 0.08), 0 4px 6px -2px rgba(68, 64, 60, 0.04);

  /* Typography */
  --font-sans: 'Pretendard Variable', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  --font-hand: 'Caveat', cursive;

  /* Layout */
  --header-height: 70px;
  --container-width: 840px;
}

/* Base Reset */
* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  scrollbar-gutter: stable both-edges;
}

/* Layout Structure */
.render-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header - Simplified */
.render-header {
  position: fixed;
  top: var(--common-header-offset, 0);
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  height: 4px;
  width: 100%;
}

.render-header__content {
  max-width: var(--container-width);
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.render-header__title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.render-header__progress-bar {
  position: absolute;
  inset: 0;
  height: 4px;
  background: transparent;
}

.progress-fill {
  height: 100%;
  background: var(--primary-color);
  transition: width 0.3s ease;
}

/* Main Content */
.render-container {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 40px 24px 100px;
  gap: 40px;
  position: relative;
}

/* Admin TOC Floating Button */
.toc-edit-fab {
  position: fixed;
  bottom: 24px;
  left: 16px;
  z-index: 180;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--primary-color);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.toc-edit-fab .material-icons {
  font-size: 18px;
}

body.is-admin .toc-edit-fab {
  display: inline-flex;
}

@media (max-width: 768px) {
  .toc-edit-fab {
    bottom: 20px;
    left: 12px;
    padding: 9px 10px;
  }
}

.render-sidebar {
  position: relative;
  width: 240px;
  flex-shrink: 0;
  display: none;
  transition: width 0.25s ease;
  /* Hidden on small screens by default */
}

@media (min-width: 1024px) {
  .render-sidebar {
    display: block;
  }
}

/* Sidebar Toggle Button */
.sidebar-toggle {
  position: fixed;
  top: calc(var(--header-height, 60px) + 8px);
  left: 226px;
  z-index: 200;
  width: 32px;
  height: 32px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: left 0.25s ease, background 0.15s ease;
}

@media (min-width: 1024px) {
  .sidebar-toggle {
    display: flex;
  }
}

.sidebar-toggle:hover {
  background: var(--primary-hover);
}

.sidebar-toggle .material-icons {
  font-size: 20px;
  transition: transform 0.25s ease;
}

/* Collapsed State */
.render-sidebar.collapsed {
  width: 48px;
}

.sidebar-toggle.collapsed {
  left: 34px;
}

.render-sidebar.collapsed .render-sidebar__inner {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.render-sidebar__inner {
  position: sticky;
  top: calc(var(--header-height) + 40px);
  max-height: calc(100vh - var(--header-height) - 80px);
  overflow-y: auto;
  padding-right: 10px;
}

/* Sidebar Title (Moved from Header) */
.render-sidebar__file-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 24px 0;
  line-height: 1.4;
  word-break: keep-all;
}

.render-sidebar__title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-tertiary);
  margin: 0 0 12px 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* TOC - Simplified & Clean */
/* TOC - Modern 2-Level Design */
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-sublist {
  list-style: none;
  padding: 0;
  margin: 4px 0 8px 0;
  display: none;
  flex-direction: column;
  gap: 2px;
}

/* Show sublist when expanded */
.toc-item.expanded>.toc-sublist {
  display: flex;
}

/* Common Link Styles */
.toc-link-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toc-toggle,
.toc-toggle-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.toc-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.toc-toggle .material-icons {
  font-size: 18px;
  transition: transform 0.2s ease;
}

/* Rotate icon when expanded */
.toc-item.expanded>.toc-link-wrapper>.toc-toggle .material-icons {
  transform: rotate(180deg);
}

.toc-toggle-placeholder {
  cursor: default;
}

.toc-link {
  display: block;
  text-decoration: none;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  line-height: 1.4;
  border-radius: var(--radius-sm);
  flex: 1;
  min-width: 0;
}

.toc-link--disabled {
  color: var(--text-tertiary);
  pointer-events: none;
}

.toc-link:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.03);
}

/* Level 1 Styles */
.toc-item.level-1>.toc-link-wrapper {
  margin-bottom: 2px;
  padding-right: 8px;
}

.toc-item.level-1>.toc-link-wrapper>.toc-link {
  font-size: 1rem;
  font-weight: 600;
  padding: 8px 4px;
  color: var(--text-primary);
}

.toc-item.level-1>.toc-link-wrapper>.toc-link:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* Level 2 Styles */
.toc-item.level-2 {
  position: relative;
}

.toc-item.level-2>.toc-link {
  font-size: 0.9rem;
  padding: 6px 12px 6px 28px;
  /* Indentation */
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  /* Marker placeholder */
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-left: 12px;
  /* Visual offset for the border */
}

.toc-item.level-2>.toc-link:hover {
  color: var(--text-primary);
  background: var(--primary-light);
}

/* Active State - Level 2 */
.toc-item.level-2.active>.toc-link {
  color: #fff;
  font-weight: 600;
  background: var(--primary-strong);
  border-left-color: var(--primary-strong);
}

/* Active State - Level 1 (if selected directly) */
.toc-item.level-1.active>.toc-link-wrapper>.toc-link {
  color: #fff;
  background: var(--primary-strong);
}

.render-content {
  flex: 1;
  width: 100%;
  min-width: 0;
  /* Prevent flex overflow */
  padding: 0;
  /* Padding moved to container */
}

/* Header Hide on Scroll - render 페이지 전용 */
body.header-hidden .render-header {
  top: 0;
  transition: top 0.3s ease;
}

body.header-hidden .tooltip-bar {
  top: 4px;
}

/* Tooltip Bar - 오버레이 스타일 */
.tooltip-bar {
  position: fixed;
  top: var(--header-height, 60px);
  z-index: 1000;
  display: flex;
  align-items: center;
  background: var(--primary-color);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(-100%);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.tooltip-bar.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.tooltip-bar__text {
  flex: 8;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tooltip-bar__close {
  flex: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  white-space: nowrap;
}

.tooltip-bar__close:hover {
  color: #fff;
}

.tooltip-bar__close .material-icons {
  font-size: 18px;
}

@media (max-width: 768px) {
  .tooltip-bar {
    padding: 10px 12px;
  }
  .tooltip-bar__text {
    font-size: 0.8rem;
  }
}

.render-content__inner {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 60px;
  min-height: 60vh;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

/* Questions */
.question-item {
  padding-bottom: 60px;
  position: relative;
  padding-left: 0;
  animation: fadeIn 0.3s ease forwards;
  opacity: 0;
  box-sizing: border-box;
  width: 100%;
}

.question-item:nth-child(1) {
  animation-delay: 0.1s;
}

.question-item:nth-child(2) {
  animation-delay: 0.2s;
}

.question-item:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bg-app);
}

.question-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.question-number {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--primary-color);
  background: var(--primary-light);
  padding: 4px 12px;
  border-radius: var(--radius-md);
  line-height: 1;
}

.question-text {
  font-size: 1.05rem;
  line-height: 2;
  color: var(--text-primary);
  font-weight: 400;
}

/* Inputs */
.input-inline-wrapper {
  display: inline-flex;
  align-items: baseline;
  max-width: 100%;
  vertical-align: baseline;
  overflow: hidden;
}

.input-inline-wrapper .input-blank {
  max-width: 100%;
}

.input-blank {
  display: inline-block;
  min-width: 60px;
  padding: 0 2px;
  margin: 0 2px;
  border: none;
  border-bottom: 2px solid #d6d3d1;
  /* Stone-300 */
  border-radius: 0;
  background: transparent;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  box-shadow: none;
  line-height: 1.6;
  vertical-align: baseline;
}

.input-blank:focus {
  background: rgba(87, 142, 126, 0.05);
  /* Very subtle primary tint */
  border-bottom-color: var(--primary-color);
  box-shadow: none;
}

.input-blank.correct {
  border-bottom-color: var(--success-color);
  color: var(--success-color);
  background: transparent;
}

.input-blank.incorrect {
  border-bottom-color: var(--error-color);
  color: var(--error-color);
  background: transparent;
  text-decoration: line-through;
}

/* New style for revealed answer (text filled in input) */
.input-blank.input-blank--revealed-text {
  color: #ef4444;
  /* Red-500 */
  border-bottom-color: #ef4444;
  font-weight: 700;
  animation: flashRed 0.5s ease;
}

@keyframes flashRed {
  0% {
    background-color: rgba(239, 68, 68, 0.1);
  }

  100% {
    background-color: transparent;
  }
}

/* Legacy styles for compatibility if needed, but we are moving away from overlay */
.input-blank.revealed-answer {
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border-color);
  color: var(--text-secondary);
}

.input-blank.revealed-inline {
  color: var(--error-color);
  font-weight: 700;
  border-bottom-color: var(--error-color);
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-outline,
.reveal-answer-btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reveal-answer-btn {
  background: #fff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}

.reveal-answer-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  background: var(--primary-light);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

/* Admin Controls */
.question-admin {
  position: absolute;
  top: 0;
  right: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.question-item:hover .question-admin {
  opacity: 1;
}

.is-admin .question-edit-btn {
  display: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.is-admin .question-item:hover .question-edit-btn,
.is-admin .question-item:focus-within .question-edit-btn {
  display: inline-flex;
  opacity: 1;
  pointer-events: auto;
}

.is-admin .normalized-render .admin-hover-target {
  position: relative;
}

.is-admin .normalized-render .question-edit-btn--floating {
  display: none;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
}

.is-admin .normalized-render .admin-hover-target:hover .question-edit-btn--floating,
.is-admin .normalized-render .admin-hover-target:focus-within .question-edit-btn--floating {
  display: inline-flex;
  opacity: 1;
  pointer-events: auto;
}

/* Tables */
.question-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  margin: 24px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.question-table th,
.question-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  min-width: 0;
}

.question-table td input[type="text"],
.question-table td textarea,
.question-table td .input-blank {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  padding: 0;
}

.table-answer-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  display: block;
  min-width: 0;
  min-height: 1.6em;
  line-height: 1.6;
  font-family: inherit;
  font-size: 14px;
  padding: 0;
  margin: 0;
  border: none;
  border-bottom: 2px solid #d6d3d1;
  background: transparent;
  resize: none;
  overflow: hidden;
}

.question-table th {
  background: var(--bg-app);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

.question-table tr:last-child td {
  border-bottom: none;
}

.question-table tr td:last-child,
.question-table tr th:last-child {
  border-right: none;
}

/* Skeleton Overlay */
.skeleton-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.skeleton-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
}

.skeleton-overlay__content {
  position: relative;
  width: 100%;
  max-width: 600px;
  padding: 24px;
}

.skeleton-overlay__card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.skeleton-overlay__line {
  height: 16px;
  background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: 8px;
  width: 100%;
}

.skeleton-overlay__line.w-3\/4 { width: 75%; }
.skeleton-overlay__line.w-5\/6 { width: 83.33%; }
.skeleton-overlay__line.w-2\/3 { width: 66.67%; }
.skeleton-overlay__line.w-4\/5 { width: 80%; }
.skeleton-overlay__line.w-1\/2 { width: 50%; }

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

body.skeleton-active {
  overflow: hidden;
}

/* Performance Optimizations */
.render-content__inner {
  contain: content;
}

.render-content__inner > * {
  contain: layout style;
}

.question-item,
.normalized-element {
  contain: layout style paint;
  content-visibility: auto;
  contain-intrinsic-size: auto 150px;
}
