/*
 * codex.css — 장소: 연금 도감 (나무 책상 위 가죽 책 · 양피지 두 쪽 · 책장 넘김 · 오른쪽 책갈피 · 리본)
 *   책장 넘기는 효과(접히는 종이·그림자)는 pageFlip.js 가 계산하고, 여기는 겉모양만
 */

/* ───────── 책상 ───────── */
.codex-desk {
  position: relative;
  height: calc(100% - 2 * var(--px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: var(--px);
  padding: 26px 30px 12px;
  background-color: #b78d5e;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 46px, rgba(92, 57, 32, 0.32) 46px 49px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.07), transparent 40%, rgba(0, 0, 0, 0.05));
  box-shadow:
    inset 0 3px 0 rgba(255, 230, 190, 0.3),
    inset 0 -4px 0 rgba(60, 30, 10, 0.25),
    0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    0 6px 0 0 rgba(58, 39, 24, 0.18);
}
.codex-desk::before { /* 네 모서리 나사 */
  content: '';
  position: absolute;
  inset: 9px;
  pointer-events: none;
  background:
    radial-gradient(circle at 7px 7px, #4f3d2b 0 4px, #8e7558 4px 6px, transparent 6.5px) left top / 14px 14px no-repeat,
    radial-gradient(circle at 7px 7px, #4f3d2b 0 4px, #8e7558 4px 6px, transparent 6.5px) right top / 14px 14px no-repeat,
    radial-gradient(circle at 7px 7px, #4f3d2b 0 4px, #8e7558 4px 6px, transparent 6.5px) left bottom / 14px 14px no-repeat,
    radial-gradient(circle at 7px 7px, #4f3d2b 0 4px, #8e7558 4px 6px, transparent 6.5px) right bottom / 14px 14px no-repeat;
}

.codex-stage { position: relative; flex: 1; min-height: 0; display: flex; width: min(1080px, calc(100% - 40px)); max-height: 700px; padding-right: 46px; }

/* ───────── 가죽 표지 ───────── */
.codex-book {
  --cover: #6e3a28;
  position: relative;
  flex: 1;
  display: flex;
  min-width: 0;
  padding: 12px 14px 20px;
  background: var(--cover);
  box-shadow:
    inset 0 3px 0 rgba(255, 200, 160, 0.22),
    inset 0 -4px 0 rgba(30, 10, 4, 0.4),
    0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    0 10px 0 0 rgba(40, 24, 12, 0.3);
}
.codex-book::before { /* 표지 모서리 쇠장식 */
  content: '';
  position: absolute;
  inset: 3px;
  pointer-events: none;
  background:
    linear-gradient(var(--gold), var(--gold)) left top / 10px 10px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right top / 10px 10px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left bottom / 10px 10px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right bottom / 10px 10px no-repeat;
}

/* ───────── 펼친 두 쪽 ───────── */
.book-spread {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  box-shadow: 0 3px 0 #e6d3ab, 0 6px 0 #cdb283, 0 8px 0 rgba(40, 24, 12, 0.45); /* 아래로 겹친 종이 두께 */
}
.book-page {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 24px 30px 8px;
  background-color: var(--paper);
}
.page-left { background-image: linear-gradient(90deg, #efe1c4 0, var(--paper) 6%, var(--paper) 86%, #e4d0aa 100%); }
.page-right { background-image: linear-gradient(270deg, #efe1c4 0, var(--paper) 6%, var(--paper) 86%, #e4d0aa 100%); }
.book-page::before { /* 안쪽 테두리 선 */
  content: '';
  position: absolute;
  inset: 10px;
  border: 2px solid rgba(139, 90, 52, 0.18);
  pointer-events: none;
}
.book-page::after { /* 네 모서리 작은 장식 */
  content: '';
  position: absolute;
  inset: 6px;
  pointer-events: none;
  background:
    linear-gradient(rgba(139, 90, 52, 0.45), rgba(139, 90, 52, 0.45)) left top / 8px 8px no-repeat,
    linear-gradient(rgba(139, 90, 52, 0.45), rgba(139, 90, 52, 0.45)) right top / 8px 8px no-repeat,
    linear-gradient(rgba(139, 90, 52, 0.45), rgba(139, 90, 52, 0.45)) left bottom / 8px 8px no-repeat,
    linear-gradient(rgba(139, 90, 52, 0.45), rgba(139, 90, 52, 0.45)) right bottom / 8px 8px no-repeat;
}
.page-body { position: relative; z-index: 1; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; padding: 0 4px 6px; }
.page-num { position: relative; z-index: 1; padding: 4px 0 2px; text-align: center; font-size: 13px; color: var(--ink-soft); }

/* 가운데 접힌 자국 + 실 바느질 */
.book-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 3;
  width: 30px;
  transform: translateX(-50%);
  pointer-events: none;
  background:
    repeating-linear-gradient(transparent 0 7px, rgba(122, 80, 46, 0.7) 7px 12px) center / 2px 100% no-repeat,
    linear-gradient(90deg, transparent, rgba(94, 70, 48, 0.16) 35%, rgba(94, 70, 48, 0.36) 50%, rgba(94, 70, 48, 0.16) 65%, transparent);
}

/* ───────── 책장 넘기기 (pageFlip.js) ───────── */
/* 넘기는 동안 잠깐 생기는 것들 */
.book-page.flip-under { position: absolute; top: 0; z-index: 0; width: 50%; height: 100%; }   /* 아래에 드러나는 새 쪽 */
.flip-flap { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.book-page.flip-back { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform, clip-path; box-shadow: inset 0 0 0 1px rgba(94, 70, 48, 0.25); } /* 넘어가는 종이 뒷면 */
.book-page.is-turning { will-change: clip-path; }
.flip-shade { position: absolute; inset: 0; z-index: 7; pointer-events: none; }                 /* 종이 위 그늘 */
.flip-shade.is-cast { z-index: 2; }                                                              /* 드러난 쪽 위 그림자 */

/* ───────── 오른쪽 책갈피 (분류) ───────── */
.book-tabs { position: absolute; top: 34px; left: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.book-tab {
  --face: var(--paper-3);
  width: 38px;
  padding: 14px 0;
  border: 0;
  background: var(--face);
  box-shadow: inset -3px 0 0 rgba(94, 70, 48, 0.15), 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), 3px 0 0 0 var(--ink);
  color: var(--ink-2);
  font-family: var(--font-title);
  font-size: 16px;
  letter-spacing: 0.15em;
  writing-mode: vertical-rl;
  cursor: pointer;
  transition: width 0.12s, background-color 0.12s;
}
.book-tab:hover { --face: var(--paper-2); width: 42px; }
.book-tab.is-active { --face: var(--red); width: 46px; color: #fff4e2; }

/* 아래로 늘어진 리본 */
.book-ribbon {
  position: absolute;
  bottom: -32px;
  left: 72%;
  z-index: 4;
  width: 20px;
  height: 56px;
  background: var(--red);
  box-shadow: inset 3px 0 0 rgba(255, 210, 180, 0.3), inset -3px 0 0 rgba(60, 14, 8, 0.35);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  pointer-events: none;
}

.book-nav { display: flex; align-items: center; gap: 10px; }
.book-page-label { min-width: 160px; text-align: center; color: #fff4e2; font-size: 13px; text-shadow: 0 1px 0 rgba(40, 20, 8, 0.6); }

/* ───────── 쪽 안의 글·그림 ───────── */
.page-head { display: flex; justify-content: center; margin-bottom: 10px; }
.page-head .ribbon { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 20px; }
.ribbon.ribbon-small { font-size: 17px; padding: 3px 26px 4px; }
.page-title { margin: 6px 0 0; font-family: var(--font-title); font-weight: 400; font-size: 38px; letter-spacing: 0.08em; color: var(--ink); text-shadow: 0 3px 0 var(--paper-edge); }
.page-orn { margin: -4px 0 12px; text-align: center; color: var(--wood-light); letter-spacing: 0.3em; }
.page-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 20px;
  color: var(--red-dark);
}
.page-heading::after { content: ''; flex: 1; height: 3px; background: linear-gradient(90deg, var(--wood-light), transparent); }
.page-sub { margin: 14px 0 8px; font-family: var(--font-title); font-weight: 400; font-size: 16px; color: var(--red-dark); }
.page-blank { margin: auto; color: var(--paper-edge); font-size: 40px; }

/* 목차 */
.codex-lead { margin: 4px 0 18px; color: var(--ink-2); line-height: 1.8; }
.codex-stat { margin-bottom: 12px; }
.codex-stat-row { display: flex; justify-content: space-between; margin-bottom: 6px; }
.codex-stat-row b { font-family: var(--font-title); font-weight: 400; font-size: 18px; }
.codex-stat-row.is-hidden { color: var(--purple); }
.codex-progress { height: 14px; margin: 0 3px; background: var(--paper-3); box-shadow: 0 0 0 3px var(--ink); }
.codex-progress > span { display: block; height: 100%; background: repeating-linear-gradient(90deg, #5d8a50 0 6px, #6f9d60 6px 12px); transition: width 0.4s; }
.codex-rumor { margin: 14px 0 0; padding: 10px 12px; background: rgba(110, 74, 142, 0.08); color: var(--purple); font-size: 14px; }
.codex-guide { margin: 14px 0 0; font-size: 13px; color: var(--ink-soft); }

.codex-index { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 14px 6px; align-content: start; padding: 4px; }
.codex-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.codex-tile:hover .slot-box { background: var(--gold-soft); transform: translateY(-2px); }
.tile-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--ink-2); }
.codex-tile.is-unknown .tile-name { color: var(--ink-soft); }
.tile-seal { position: absolute; top: -4px; right: 6px; width: 14px; height: 14px; background: var(--red); box-shadow: 0 0 0 2px #fff4e2, 0 0 0 3px var(--red-dark); transform: rotate(45deg); }

/* 레시피·재료 쪽 */
.codex-plate {
  align-self: center;
  margin: 12px 0 18px;
  padding: 16px;
  background: var(--paper-2);
  box-shadow: 0 0 0 3px var(--wood-light), 0 0 0 6px var(--paper), 0 0 0 9px var(--wood-dark);
}
.codex-plate.is-small { margin: 8px 0 14px; padding: 10px; }
.codex-meta { margin-bottom: 12px; text-align: center; font-size: 13px; color: var(--ink-soft); }
.codex-desc { padding: 12px 4px 0; border-top: 2px dotted rgba(139, 90, 52, 0.35); line-height: 1.8; }
.codex-seal {
  position: absolute;
  top: 54px;
  right: 6px;
  padding: 10px 6px;
  background: var(--red);
  color: #fff4e2;
  font-family: var(--font-title);
  font-size: 13px;
  writing-mode: vertical-rl;
  box-shadow: 0 0 0 2px var(--red-dark), 0 3px 0 2px rgba(58, 39, 24, 0.2);
  transform: rotate(6deg);
}

.codex-ingredients { list-style: none; display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0 3px; }
.ing-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px 6px 8px;
  background: var(--paper-2);
  box-shadow: 0 0 0 2px var(--paper-edge);
}
.ing-row.is-unknown { color: var(--ink-soft); }
.ing-row.is-result { margin: 0 3px; background: var(--green-soft); box-shadow: 0 0 0 2px #9fbb86; }
.ing-name { flex: 1; min-width: 0; }
.ing-need { font-weight: 700; }
.ing-have { min-width: 52px; text-align: right; font-size: 12.5px; color: var(--ink-soft); }
.ing-have.is-short { color: var(--red); font-weight: 700; }
.codex-arrow { margin: 6px 0; text-align: center; color: var(--wood-light); font-size: 14px; }
.codex-quote { margin: 16px 0 0; padding: 8px 14px; border-left: 4px solid var(--wood-light); background: rgba(185, 133, 82, 0.1); color: var(--ink-2); font-size: 14px; line-height: 1.75; }
.codex-hint { margin-top: 16px; padding: 10px 12px; background: rgba(201, 154, 60, 0.15); box-shadow: 0 0 0 2px rgba(201, 154, 60, 0.4); line-height: 1.7; }
.codex-hint b { color: #7d5a1e; }
.codex-actions { display: flex; justify-content: center; margin-top: 18px; }

.mat-uses { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.mat-use {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 2px 4px;
  border: 0;
  background: var(--green-soft);
  box-shadow: 0 0 0 2px #9fbb86;
  font-size: 13px;
  cursor: pointer;
}
.mat-use:hover { background: #d3e3b8; }
.mat-unknown { margin: 8px 0 0; font-size: 13px; color: var(--ink-soft); }

/* ───────── 좁은 화면 ───────── */
@media (max-width: 760px) {
  .codex-desk { height: auto; padding: 18px 12px 12px; }
  .codex-stage { width: 100%; padding-right: 0; }
  .book-spread { grid-template-columns: 1fr; }
  .book-spine, .book-tabs { display: none; }
  .book-page { overflow: visible; }
}

/* 6단계: 숙련도 */
.codex-mastery { margin-top: 4px; font-size: 13px; color: #8a5a00; text-align: center; }
.book .trait-line { justify-content: center; }
