/* =========================================================
   자료 보기 창 (js/viewer.js)
   - 데스크톱: 가운데 큰 창 / 767px 이하: 전체 화면, 아래에서 올라옴
   ========================================================= */

html.has-modal { overflow: hidden; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.viewer {
  --line: #e3e9dc;
  --paper: #f3f5ef;
  --muted: #5d6657;

  width: min(1440px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 40px 100px rgba(25, 40, 15, .28);
  overflow: hidden;
}

.viewer[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  animation: viewer-in .38s var(--ease);
}

.viewer::backdrop {
  background: rgba(34, 46, 24, .38);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade-in .3s ease;
}

/* 창 전체에 포커스 테두리가 생기지 않게 (안쪽 요소에만 표시) */
.viewer:focus,
.viewer:focus-visible { outline: none; }

.viewer.is-closing { animation: viewer-out .18s ease forwards; }
.viewer.is-closing::backdrop { animation: fade-out .18s ease forwards; }

@keyframes viewer-in { from { opacity: 0; transform: translateY(28px) scale(.98); } }
@keyframes viewer-out { to { opacity: 0; transform: translateY(16px) scale(.99); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

.viewer svg {
  width: 20px;
  height: 20px;
  flex: none;
}

/* ---------- 머리글: 한 줄로 낮게 ---------- */
.viewer__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 10px 14px 10px 24px;
  background: linear-gradient(180deg, var(--green-soft), #f6f9f2);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.viewer__heading {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.viewer__crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 14px;
  font-weight: 600;
}

.viewer__crumb .badge,
.viewer__back .badge {
  width: 24px;
  height: 24px;
  margin: 0;
  border: 0;
  box-sizing: border-box;
  font-size: 13px;
}

.viewer__back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: -6px;
  padding: 2px 10px 2px 2px;
  border-radius: 999px;
  font-family: var(--font-title);
  font-size: 15px;
  letter-spacing: -0.03em;
  transition: background-color .2s;
}

.viewer__back::before {
  content: "";
  width: 14px;
  height: 14px;
  margin-left: 4px;
  margin-right: -3px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 5l-7 7 7 7' fill='none' stroke='%23000' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 5l-7 7 7 7' fill='none' stroke='%23000' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform .25s var(--ease);
}

.viewer__back:hover { background: rgba(69, 109, 42, .1); }

/* 분류 화면: 단계 › 항목 */
.viewer__crumb { min-width: 0; }
.viewer__sep { flex: none; color: var(--muted); }

.viewer__crumbitem {
  min-width: 0;
  overflow: hidden;
  padding: 2px 8px;
  margin-left: -6px;
  border-radius: 999px;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color .2s;
}

.viewer__crumbitem:hover { background: rgba(69, 109, 42, .1); }
.viewer__back:hover::before { transform: translateX(-3px); }

.viewer__titleline {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.viewer__title {
  min-width: 0;
  overflow: hidden;
  color: var(--navy);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.03em;
  text-overflow: ellipsis;
  white-space: nowrap;
  outline: none;
}

.viewer__title.is-display {
  font-family: var(--font-title);
  font-weight: normal;
  font-size: 26px;
}

.viewer__meta {
  flex: none;
  color: var(--muted);
  font-size: 14px;
}

/* 단계 그림: 머리글 오른쪽에 작게 (높이가 넉넉할 때만) */
.viewer__art {
  flex: none;
  align-self: flex-end;
  height: 64px;
  width: auto;
  margin-bottom: -11px;
  pointer-events: none;
}

.viewer__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewer__pager {
  display: flex;
  gap: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}

.hbtn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
  cursor: pointer;
  transition: transform .25s var(--ease), background-color .2s, color .2s;
}

.hbtn svg { width: 18px; height: 18px; }
.hbtn.is-disabled { opacity: .35; box-shadow: none; cursor: default; }

.hbtn--prev:hover,
.hbtn--next:hover { background: var(--green); color: #fff; }
.hbtn--prev:hover svg { transform: translateX(-2px); }
.hbtn--next:hover svg { transform: translateX(2px); }
.hbtn svg { transition: transform .25s var(--ease); }

/* 이전/다음 말풍선: 어디로 가는지 미리 보여줌 */
.hbtn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 2;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(24, 32, 18, .92);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity .15s, transform .2s var(--ease);
}

.hbtn[data-tip]:hover::after,
.hbtn[data-tip]:focus-visible::after { opacity: 1; transform: none; }

.viewer__head { overflow: visible; }

.viewer__close:hover {
  background: var(--ink);
  color: #fff;
  transform: rotate(90deg);
}

/* ---------- 본문 ---------- */
.viewer__body {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.viewer__body.has-list { grid-template-columns: 240px minmax(0, 1fr); }

.viewer__body--stage {
  grid-template-rows: none;
  overflow: auto;
  padding: 24px;
  align-content: start;
}

/* 자료 목록 (자료가 2개 이상일 때) */
.mlist {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.mlist__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color .2s;
}

.mlist__item:hover { background: var(--paper); }

.mlist__item[aria-current="true"] {
  background: var(--green-soft);
  box-shadow: inset 0 0 0 1.5px rgba(69, 109, 42, .35);
}

.mlist__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: #fff;
  color: var(--navy);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

.mlist__icon.is-video { color: #d33b3b; }

.mlist__text { min-width: 0; display: grid; gap: 2px; }

.mlist__title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.02em;
}

.mlist__type { color: var(--muted); font-size: 13px; }

.pane {
  min-width: 0;
  min-height: 0;
  display: grid;
}

.pane__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.pane__desc {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

/* 버튼 */
.btn,
.icon-btn,
.pdf__zoom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .2s, border-color .2s, color .2s;
}

.btn { padding: 0 16px; }
.icon-btn { width: 36px; }
.pdf__zoom { min-width: 56px; padding: 0 10px; font-variant-numeric: tabular-nums; }

.btn:hover,
.icon-btn:hover,
.pdf__zoom:hover {
  border-color: var(--green);
  color: var(--green-dark);
  background: var(--green-soft);
}

.btn--solid {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.btn--solid:hover {
  background: var(--green-dark);
  border-color: var(--green-dark);
  color: #fff;
}

.btn svg,
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- PDF ---------- */
.pdf {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.pdf__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 8px 12px 8px 20px;
  border-bottom: 1px solid var(--line);
}

.pdf__name {
  min-width: 0;
  display: grid;
}

.pdf__nameline {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.pdf__name .pane__title {
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf__page {
  flex: none;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.pdf__page b { color: var(--ink); }

.pdf__desc {
  overflow: hidden;
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf__tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.pdf__tools .btn--solid { margin-left: 4px; }

.pdf__scroll {
  overflow: auto;
  background: var(--paper);
  outline: none;
  overscroll-behavior: contain;
}

.pdf__pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: max-content;
  min-width: 100%;
  padding: 20px 20px 32px;
}

.pdf__sheet {
  width: min(100%, 900px);
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 8px 24px rgba(40, 60, 20, .08);
  overflow: hidden;
}

.pdf__sheet canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.pdf__sheet.is-skeleton {
  aspect-ratio: 210 / 297;
  background: linear-gradient(100deg, #fff 30%, #f1f4ec 50%, #fff 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer { to { background-position: -150% 0; } }

/* ---------- 영상 ---------- */
.video-wrap {
  overflow: auto;
  padding: 24px;
  background: var(--paper);
}

.video {
  position: relative;
  /* 화면 높이가 낮아도 영상 전체가 보이도록 */
  width: min(100%, 1000px, (100dvh - 260px) * 16 / 9);
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 12px 40px rgba(20, 30, 10, .2);
}

.video iframe,
.video__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video__poster {
  padding: 0;
  background: #111 center / cover no-repeat;
  cursor: pointer;
}

.video__poster::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, .35));
  transition: background-color .25s;
}

.video__play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
  transform: translate(-50%, -50%);
  transition: transform .3s var(--ease), background-color .2s;
}

.video__play::after {
  content: "";
  position: absolute;
  left: 34px;
  top: 26px;
  border-style: solid;
  border-width: 16px 0 16px 26px;
  border-color: transparent transparent transparent var(--green);
}

.video__poster:hover .video__play { transform: translate(-50%, -50%) scale(1.08); }
.video__poster:hover::before { background-color: rgba(0, 0, 0, .12); }

.video__info {
  width: min(100%, 1000px, (100dvh - 260px) * 16 / 9);
  margin: 16px auto 0;
  display: grid;
  justify-items: start;
  gap: 4px;
}

.video__info .btn { margin-top: 10px; }

/* ---------- 단계 개요 카드 ---------- */
.cards {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card {
  position: relative;
  display: grid;
  gap: 6px;
  min-height: 112px;
  padding: 22px 56px 22px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  transition: border-color .2s, background-color .2s, transform .3s var(--ease), box-shadow .3s var(--ease);
}

.card__title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.02em;
}

.card__meta {
  align-self: end;
  color: var(--green);
  font-size: 14px;
  font-weight: 600;
}

.card__meta.is-empty { color: #9aa294; font-weight: 500; }

.card__arrow {
  position: absolute;
  right: 20px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--green);
  transform: translateY(-50%);
  transition: transform .3s var(--ease), background-color .2s, color .2s;
}

.card__arrow svg { width: 16px; height: 16px; }

/* 터치 기기에서는 누른 뒤 hover 가 남지 않도록 마우스일 때만 */
@media (hover: hover) {
  .card:hover {
    border-color: rgba(69, 109, 42, .45);
    background: #fbfdf8;
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(40, 60, 20, .1);
  }

  .card:hover .card__arrow {
    background: var(--green);
    color: #fff;
    transform: translate(3px, -50%);
  }
}

.card:active { background: var(--green-soft); }
.card:focus-visible .card__arrow { background: var(--green); color: #fff; }

/* ---------- 상태 (불러오는 중 / 준비 중 / 오류) ---------- */
.state {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  min-height: 100%;
  padding: 40px 24px;
  text-align: center;
}

.state__art {
  width: 180px;
  height: auto;
  margin-bottom: 14px;
  filter: saturate(.3) contrast(.6) brightness(1.25);
}

.state__title { font-size: 20px; font-weight: 700; color: var(--navy); }
.state__text { color: var(--muted); font-size: 15px; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--green-soft);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 화면 높이가 낮으면(태블릿 가로, 배율 큰 노트북) 머리글 그림 숨김 */
@media (max-height: 820px) {
  .viewer__art { display: none; }
}

/* =========================================================
   태블릿 이하: 창을 화면 가득, 자료 목록은 위쪽 가로 줄
   ========================================================= */
@media (max-width: 1023.98px) {
  .viewer {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
    border-radius: 16px;
  }

  .viewer__art { display: none; }

  .viewer__body.has-list {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mlist {
    flex-direction: row;
    gap: 6px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
  }

  .mlist__item {
    flex: none;
    width: auto;
    max-width: 70vw;
    padding: 4px 14px 4px 4px;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px var(--line);
  }

  .mlist__icon { width: 30px; height: 30px; border-radius: 50%; box-shadow: none; background: var(--paper); }
  .mlist__icon svg { width: 17px; height: 17px; }
  .mlist__type { display: none; }
  .mlist__title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .pdf__tools .btn--solid span { display: none; }
  .pdf__tools .btn--solid { width: 36px; padding: 0; }
}

/* =========================================================
   휴대폰: 전체 화면
   ========================================================= */
@media (max-width: 767.98px) {
  .viewer {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .viewer[open] { animation-name: sheet-in; }
  .viewer.is-closing { animation-name: sheet-out; }

  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
  @keyframes sheet-out { to { transform: translateY(40px); opacity: 0; } }

  .viewer__head {
    gap: 8px;
    min-height: 60px;
    padding: 8px 8px 8px 14px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .viewer__titleline { flex-direction: column; align-items: flex-start; gap: 0; }
  .viewer__title { font-size: 18px; }
  .viewer__title.is-display { font-size: 22px; }
  .viewer__meta { font-size: 12.5px; }
  .viewer__crumb { font-size: 13px; }
  .viewer__back { font-size: 14px; }
  .viewer__actions { gap: 4px; }
  .viewer__pager { padding-right: 4px; gap: 2px; }
  .hbtn { width: 36px; height: 36px; }
  .hbtn[data-tip]::after { display: none; }

  .pdf__bar { min-height: 48px; padding: 6px 8px 6px 14px; gap: 8px; }
  .pdf__tools [data-zoom], .pdf__tools a[target] { display: none; }
  .pdf__desc { display: none; }
  .pdf__pages { padding: 10px 8px calc(24px + env(safe-area-inset-bottom)); gap: 10px; }

  .video-wrap { padding: 12px; }
  .video { width: 100%; border-radius: 12px; }
  .video__info { width: 100%; }
  .video__play { width: 64px; height: 64px; }
  .video__play::after { left: 25px; top: 19px; border-width: 13px 0 13px 21px; }

  .viewer__body--stage { padding: 12px; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .card { min-height: 0; padding: 16px 56px 16px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .viewer[open],
  .viewer::backdrop { animation: none; }
}
