/* 화면 전체 */
html, body {
  margin: 0;
  background: var(--bg, #000);
  color: var(--fg, #eee);
  font-family: system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
  /* 노치, 둥근 모서리 피하기 */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] { display: none !important; }

/* 첫 화면: 팀 고르기 */
#home { flex: 1; min-height: 0; overflow: auto; padding: 32px 16px; text-align: center; }
#home .cover img { display: block; max-width: 100%; max-height: 85dvh; margin: 0 auto 20px; box-shadow: 0 8px 30px #0004; }
#home a { color: inherit; text-decoration: none; }
#home .all { display: inline-block; padding: 12px 20px; border: 1px solid #8888; border-radius: 999px; }
#home .all:hover, #home .all:focus-visible { border-color: currentColor; }
#home .grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 20px 16px;
  max-width: 1100px; margin: 32px auto 0; text-align: left;
}
#home .grid img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; margin-bottom: 8px; background: #8882; }
#home .grid b { display: block; font-weight: 500; }
#home .grid span { color: #888; font-size: .85rem; }
#home .grid a:hover img, #home .grid a:focus-visible img { opacity: .8; }

/* 책이 놓이는 영역 */
#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

/* 쪽 */
.pg { background: #fff; position: relative; overflow: hidden; box-shadow: 0 16px 28px -12px #0007; }
/* 실제 책처럼: 접히는 가운데(책등) 쪽은 그늘지고 바깥 가장자리는 살짝 어둡다. --left, --right 는 넘김 라이브러리가 붙인다 */
.pg::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.pg.--right::after { background: linear-gradient(to right, #0000004d, #0000001f 2.5%, #0000000a 8%, #0000 16%, #0000 95%, #0000000f); }
.pg.--left::after { background: linear-gradient(to left, #0000004d, #0000001f 2.5%, #0000000a 8%, #0000 16%, #0000 95%, #0000000f); }
/* 종이와 배경이 같은 색이어도 쪽 경계가 보이도록 가는 테두리 */
.pg img { outline: 1px solid #0002; outline-offset: -1px; width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }

/* 책 두께: 책 양옆에 쌓인 종이 단면 */
.wrap { position: relative; }
.edge {
  position: absolute;
  top: .6%;
  bottom: .6%;
  width: 0;
  transition: width .4s;
  background: repeating-linear-gradient(90deg, #f4f1ee 0 1px, #b9b4ae 1px 2px);
}
.edge { box-shadow: 0 16px 28px -12px #0007; }
/* 쌓인 종이는 바깥으로 갈수록 어둡다 */
.edge.l { right: 100%; background-image: linear-gradient(to left, #0000, #0003), repeating-linear-gradient(90deg, #f4f1ee 0 1px, #b9b4ae 1px 2px); }
.edge.r { left: 100%; background-image: linear-gradient(to right, #0000, #0003), repeating-linear-gradient(90deg, #f4f1ee 0 1px, #b9b4ae 1px 2px); }

/* 펼침 영상의 첫 장면(종이에 인쇄된 것처럼) */
.still { position: absolute; background-size: 100% 100%; }

/* 펼침 영상을 얹는 칸. 영상 밖은 책이 그대로 눌린다 */
.over { position: absolute; inset: 0; z-index: 100; pointer-events: none; }
.over .m { pointer-events: auto; }

/* 쪽 위에 올리는 오디오, 영상 */
.m { position: absolute; z-index: 1; } /* 그늘(.pg::after)보다 위 */
.m video, .m iframe { width: 100%; height: 100%; border: 0; background: #000; }
.m button {
  width: 100%; height: 100%;
  min-width: 44px; min-height: 44px;
  border-radius: 999px; border: 0;
  background: #000b; color: #fff;
  font-size: 1rem; cursor: pointer;
}

/* 목차 링크: 글자 위에 얹는 투명 버튼 */
.m button.link { min-width: 0; min-height: 0; border-radius: 4px; background: none; }
.m button.link:hover, .m button.link:focus-visible { background: #fff3; }
/* 넘어가는 종이의 뒷면은 빈 종이 */
.pg.back { background: var(--paper, #fff); }
.pg.back > * { visibility: hidden; }

/* 목차 창 */
#toc {
  width: min(420px, 88vw); max-height: 80dvh; padding: 0;
  background: #111; color: #eee; border: 1px solid #333; border-radius: 10px;
}
#toc::backdrop { background: #000a; }
#toc h2 { margin: 0; padding: 16px 20px 12px; font-size: .8rem; font-weight: 500; letter-spacing: .12em; color: #888; }
#toc button {
  display: flex; gap: 14px; width: 100%; min-height: 44px; padding: 10px 20px;
  background: none; color: inherit; border: 0; border-top: 1px solid #2a2a2a;
  font-size: 1rem; text-align: left; cursor: pointer;
}
#toc button::before { content: attr(data-no); color: #888; font-variant-numeric: tabular-nums; }
#toc button:hover, #toc button:focus-visible { background: #222; }


/* 아래 버튼 줄 */
#bar { display: flex; gap: 12px; justify-content: center; align-items: center; padding: 6px; }
#bar button {
  min-width: 44px; min-height: 44px;
  background: #fff; color: #111;
  border: 1px solid #0003; border-radius: 8px;
  font-size: 1rem; cursor: pointer;
}

/* 통계 화면 */
#st { position: fixed; inset: 0; background: #000e; color: #eee; padding: 24px; overflow: auto; }
#st input, #st button { font-size: 1rem; padding: 8px; margin: 4px 4px 4px 0; }

/* 플립 반 접힘(플렉스 모드): 책은 위 화면, 버튼은 아래 화면 */
@media (vertical-viewport-segments: 2) {
  #stage { flex: none; height: env(viewport-segment-height 0 0); }
  #bar { flex: 1; }
}
