:root {
  --ink: #6b3f1f;
  --ink-soft: #9a6a45;
  --accent: #f7a3b2;
  --accent-deep: #e8798d;
  --paper: #fff8ec;
  --book-ratio: 1918 / 1088;
  --topbar-h: 60px;
  --nav-size: 52px;
  --nav-row-h: 68px; /* 책 아래 넘김 버튼 줄 */
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: "Jua", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 40%, #fdeedd 0%, #f6d9c2 60%, #eec4ad 100%) fixed;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }

img { display: block; max-width: 100%; }

/* ---------- 상단 바 ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 3vw, 40px);
}

.logo { height: 44px; width: auto; }

.lang-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 4px 4px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 2px 8px rgba(107, 63, 31, 0.15);
  font-size: 17px;
  transition: transform 0.15s;
}
.lang-btn img { width: 44px; height: 44px; }
.lang-btn:hover { transform: scale(1.05); }
.lang-btn:focus-visible,
.nav-btn:focus-visible,
.card:focus-visible,
.player button:focus-visible { outline: 3px solid var(--accent-deep); outline-offset: 3px; }

/* ---------- 태블릿/PC: 펼친 책 ---------- */
.stage {
  height: calc(100dvh - var(--topbar-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 8px;
}

.book-wrap {
  position: relative;
  padding-bottom: var(--nav-row-h);
}

.book {
  position: relative;
  width: min(100vw - 32px, (100dvh - var(--topbar-h) - var(--nav-row-h) - 8px) * 1918 / 1088);
  aspect-ratio: var(--book-ratio);
  background: url("assets/ui/background_pc_tablet.png") center / 100% 100% no-repeat;
  filter: drop-shadow(0 12px 24px rgba(107, 63, 31, 0.25));
  container-type: inline-size;
}

.page {
  position: absolute;
  top: 7%;
  bottom: 9%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, auto);
  align-content: center; /* 두 줄을 쪽 가운데로 모음 */
  gap: 4.5cqw 1.5cqw;
  align-items: center;
  justify-items: center;
}
.page-left  { left: 5%;  right: 53.5%; }
.page-right { left: 54.5%; right: 4%; }

.page.flip-next { animation: flip-next 0.35s ease-out; }
.page.flip-prev { animation: flip-prev 0.35s ease-out; }
@keyframes flip-next { from { opacity: 0; transform: translateX(2cqw); } }
@keyframes flip-prev { from { opacity: 0; transform: translateX(-2cqw); } }

.nav-btn {
  position: absolute;
  bottom: 0;
  z-index: 1;
  width: var(--nav-size);
  height: var(--nav-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  transition: transform 0.15s, opacity 0.2s;
}
.nav-btn img { width: 100%; height: 100%; filter: drop-shadow(0 3px 6px rgba(107, 63, 31, 0.2)); }
.nav-btn:hover:not(:disabled) { transform: scale(1.1); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn.prev { left: calc(50% - 100px); }
.nav-btn.next { right: calc(50% - 100px); }

.page-indicator {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0;
  line-height: var(--nav-size);
  pointer-events: none; /* 넘김 버튼 클릭을 가리지 않도록 */
  text-align: center;
  font-size: 17px;
  color: var(--ink-soft);
}

/* ---------- 카드 (공통) ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: center;
}

.card-thumb {
  position: relative;
  z-index: 1; /* 캐릭터보다 앞 */
  width: 82%;
  aspect-ratio: 300 / 322;
  object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(107, 63, 31, 0.25));
  transition: transform 0.2s;
}

/* 캐릭터: 썸네일 뒤, 우측 상단에서 빼꼼 */
.card-char {
  position: absolute;
  z-index: 0;
  top: -3.6cqw;
  right: 0;
  height: 6.5cqw;
  width: auto;
  max-width: 48%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
  transform-origin: 50% 100%;
  transition: transform 0.25s;
}

.card-title {
  margin-top: 0.6cqw;
  font-size: max(11px, 1.15cqw);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.5em;
}
.card-num { color: var(--accent-deep); margin-right: 0.25em; }

@media (hover: hover) {
  .card:hover .card-thumb { transform: translateY(-4px) rotate(-1.5deg); }
  .card:hover .card-char { animation: wiggle 0.6s ease-in-out; }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0) translateY(0); }
  30% { transform: rotate(-8deg) translateY(-6px); }
  60% { transform: rotate(6deg) translateY(-3px); }
}

.mobile-list { display: none; }

/* ---------- 모바일 ---------- */
@media (max-width: 767px), (max-height: 500px) and (orientation: landscape) {
  body { background: #fef6e6; }
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: url("assets/ui/background_phone.jpg") center top / cover no-repeat;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 60px;
    background: rgba(254, 246, 230, 0.9);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .logo { height: 34px; }
  .lang-btn { font-size: 15px; padding-right: 12px; }
  .lang-btn img { width: 36px; height: 36px; }

  .stage { height: auto; display: block; padding: 16px 16px 40px; }
  .book-wrap { display: none; }

  .mobile-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 60px 24px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .mobile-list .card-thumb { width: 92%; }
  .mobile-list .card-char { display: none; }
  .mobile-list .card-title { margin-top: 16px; font-size: 15px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .mobile-list { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- 영상 팝업 ---------- */
.player {
  width: min(960px, 94vw);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.player::backdrop { background: rgba(40, 20, 10, 0.75); }
.player:focus { outline: none; }

.player-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 20px;
}
.player-title {
  flex: 1;
  margin: 0;
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 400;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-tabs {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: #f3e2cc;
}
.player-tabs button {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: 15px;
}
.player-tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }

.player-close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #f3e2cc;
  font-size: 26px;
  line-height: 1;
}
.player-close:hover { background: var(--accent); color: #fff; }

.player-frame { position: relative; aspect-ratio: 16 / 9; background: #000; }
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

@media (max-width: 767px) {
  .player { width: calc(100vw - 24px); max-width: calc(100vw - 24px); border-radius: 16px; margin: auto; } /* 화면 가운데 */
  .player-head { flex-wrap: wrap; padding: 10px 10px 10px 16px; }
  .player-title { flex-basis: calc(100% - 52px); order: 0; }
  .player-close { order: 1; }
  .player-tabs { order: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
