*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: #222;
  background: #fff;
  font: 16px/1.55 Arial, "Malgun Gothic", sans-serif;
}

a {
  color: #143c92;
  text-underline-offset: 3px;
}

a:visited { color: #543e78; }
a:hover { text-decoration-thickness: 2px; }

a, button, select {
  touch-action: manipulation;
}

button {
  min-height: 36px;
  padding: 4px 9px;
  border: 1px solid #888;
  color: #143c92;
  background: #fff;
  font: inherit;
  cursor: pointer;
}

button:hover { background: #eff3fa; }

:focus-visible {
  outline: 3px solid #a45400;
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.wrap {
  max-width: 1160px;
  height: 100vh;
  height: 100dvh;
  margin: auto;
  padding-inline: max(3vw, env(safe-area-inset-left)) max(3vw, env(safe-area-inset-right));
  padding-block: env(safe-area-inset-top) env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  background: #fff;
}

.mast, .brand-lockup, footer, .pager, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mast {
  border-bottom: 3px double #777;
  padding: 16px 0 10px;
}

[data-reader-page="reader"] .mast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 6px 12px;
  padding: 6px 0;
  border-bottom: 1px solid #cbd5d0;
}

[dir="rtl"] .wrap {
  padding-inline: max(3vw, env(safe-area-inset-right)) max(3vw, env(safe-area-inset-left));
}

.reader-tools, .language-picker {
  display: flex;
  align-items: center;
  gap: 4px 8px;
}

.reader-tools { grid-column: 3; }
.reader-tools button {
  border-color: #a6b1ae;
  border-radius: 6px;
  overflow-wrap: anywhere;
}
.reader-tools button[aria-expanded="true"] {
  color: #182d55;
  background: #e6efec;
  border-color: #718883;
}

.language-picker {
  grid-column: 2;
  justify-self: end;
  min-width: 0;
  font-size: 13px;
}

.language-picker select {
  min-width: 0;
  max-width: min(40vw, 166px);
  min-height: 36px;
  border: 1px solid #a6b1ae;
  border-radius: 6px;
  font: inherit;
  font-size: 16px;
  color: #143c92;
  background: #fff;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .25em;
  font: bold 32px/1 Georgia, serif;
  letter-spacing: -.05em;
  text-decoration: none;
}

.brand, .brand:visited {
  color: #18336c;
}

.brand img { width: .9em; height: .9em; flex: none; }
.brand:hover span { text-decoration: underline; }

.beta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 0;
  font-size: 13px;
  color: #555;
}

.beta strong {
  color: #24493a;
  background: #e2ece6;
  padding: 2px 8px;
}

body[data-reader-page="reader"] .beta {
  display: block;
  margin: 24px 0 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

html[lang="ko"] .prose,
html[lang="ko"] body[data-reader-page="reader"] .beta { word-break: keep-all; }

body[data-reader-page="reader"] .beta strong {
  display: inline-block;
  margin-inline-end: 4px;
}

.genre {
  display: block;
  font-size: 12px;
  font-weight: normal;
}

/* 목록을 열어도 읽기 열의 너비와 스크롤 영역이 그대로 유지된다. */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  position: relative;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  grid-template-areas: "read";
}

.panel {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  max-height: min(100%, 34rem);
  width: min(100%, 24rem);
  background: #fff;
  border: 1px solid #9aaca6;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgb(18 39 33 / 18%);
}


.panel-head {
  flex: none;
  flex-wrap: nowrap;
  gap: 4px;
  background: #e2ece6;
  border-block: 1px solid #aaa;
}

.panel-head h2 {
  font-size: 16px;
  margin: 0;
  padding: 5px 9px;
  overflow-wrap: anywhere;
}

.panel-head .close { margin: 3px; }

.links, article {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #989898 #f3f3f3;
  scrollbar-gutter: stable;
}

.links {
  position: relative;
  min-height: 0;
  flex: 1;
}

.links a {
  display: block;
  min-height: 44px;
  padding: 8px 12px;
  border-bottom: 1px dotted #bcbcbc;
  overflow-wrap: anywhere;
  content-visibility: auto;
  contain-intrinsic-size: auto 44px;
}

.links a:hover { background: #f2f6f4; }
.links a:focus-visible { outline-offset: -3px; }
.links [aria-current] {
  color: #182d55;
  background: #eff3fa;
  font-weight: bold;
  text-decoration: none;
}

#reader {
  grid-area: read;
  min-width: 0;
  min-height: 0;
  container-type: size;
  padding-inline: 8px;
  scroll-padding-block: 5px;
}

#reader:focus-visible { outline-offset: -3px; }

.reader-content {
  max-width: 620px;
  margin-inline: auto;
  padding-block: 14px 20px;
}

.reader-head { overflow-wrap: anywhere; }

h1 {
  margin: 10px 0;
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1.3;
  letter-spacing: -.05em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

[dir="rtl"] h1 { letter-spacing: normal; }

.prose {
  margin: 20px 0 30px;
  font: 19px/1.95 Georgia, "Batang", "Noto Serif CJK KR", serif;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.prose p { margin: 0 0 1em; }

.prose-skeleton {
  display: grid;
  gap: .7em;
}

.prose-skeleton span {
  height: .7em;
  border-radius: .2em;
  background: #eef1f5;
}

.prose-skeleton span:nth-child(2), .prose-skeleton span:nth-child(5) { width: 70%; }
.prose-skeleton span:nth-child(3) { margin-top: 1em; }

.prose hr {
  width: 3em;
  border: 0;
  border-top: 1px solid #aaa;
  margin: 2em auto;
}

.webtoon-cut {
  max-width: 620px;
  margin: 1.5em auto;
}

.webtoon-cut img {
  display: block;
  width: 100%;
  height: auto;
  background: #f1f1f1;
}

.cut-frame.is-loading { background: #eef1f5; }
.cut-frame.is-loading img { opacity: 0; }

/* 컷 구간: 이미지가 본문 스크롤(article) 상단에 붙어 구간 끝까지 보인다. */
.cut-section { position: relative; }

.cut-section > .webtoon-cut {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 auto 1em;
  padding: 6px 0 10px;
  background: #fff;
  box-shadow: 0 10px 12px -10px rgba(0, 0, 0, .35);
}

.cut-section > .webtoon-cut img {
  width: 100%;
  height: auto;
  max-height: 46vh;
  max-height: 50cqh;
  object-fit: contain;
  background: #fff;
}

.cut-section > .webtoon-cut:has(+ .webtoon-cut) { position: static; box-shadow: none; }

.pager {
  border-block: 1px solid #aaa;
  padding: 10px 4px;
}

.pager a { min-height: 32px; padding-block: 4px; }
.pager span, small, footer { color: #555; }

footer {
  border-top: 1px solid #bbb;
  padding: 6px 0;
  font-size: 13px;
}

.site-links {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
}

.site-links a { padding-block: 3px; }

.analytics-panel, .analytics-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.analytics-panel {
  justify-content: space-between;
  padding: 6px 0;
  border-top: 1px solid #bbb;
  color: #333;
  font-size: 13px;
}

.analytics-settings {
  min-height: 0;
  padding: 3px 0;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.policy-page {
  width: 100%;
  max-width: 760px;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
}

.policy-content {
  flex: 1;
  padding-block: 24px 32px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.policy-content h2 {
  margin: 24px 0 4px;
  font-size: 18px;
  text-wrap: balance;
}

.policy-content p, .policy-content ul { margin: 0 0 12px; }
.policy-content ul { padding-inline-start: 1.4em; }
.policy-content li + li { margin-top: 6px; }

.skip {
  position: absolute;
  top: 6px;
  inset-inline-start: 6px;
  z-index: 3;
  padding: 8px;
  background: white;
  transform: translateY(-200%);
}

.skip:focus { transform: none; }

html[data-view="mobile"] .wrap {
  max-width: 760px;
  padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
}
html[data-view="mobile"][dir="rtl"] .wrap {
  padding-inline: max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-left));
}
html[data-view="mobile"] [data-reader-page="reader"] .brand { font-size: 24px; }
html[data-view="mobile"] .prose { font-size: 18px; }
html[data-view="mobile"] footer { font-size: 12px; }

@media (max-width: 520px) {
  [data-reader-page="reader"] .mast { grid-template-columns: minmax(0, 1fr) auto; }
  .reader-tools {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .reader-tools button, .language-picker select, .panel-head .close { min-height: 44px; }
  .books { inset-inline: 0 auto; }
  #reader { padding-inline: 4px; }
  .reader-content { padding-top: 10px; }
}

@media (max-width: 620px) {
  .language-picker label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.cut-sequence { display: flow-root; }
.cut-stage {
  position: sticky;
  top: 0;
  z-index: 2;
  width: 100%;
  max-width: 620px;
  aspect-ratio: 3 / 2;
  max-height: min(46vh, 440px);
  max-height: min(50cqh, 440px);
  margin: 0 auto 1em;
  background: #fff;
}
.cut-stage::after {
  content: "";
  position: absolute;
  inset: 100% 0 auto;
  height: 20px;
  background: linear-gradient(#fff 4px, rgb(255 255 255 / 0));
  pointer-events: none;
}
.cut-stage.is-loading { background: #eef1f5; }
.cut-stage .webtoon-cut {
  position: absolute;
  inset: 8px 0;
  margin: 0;
}
.cut-stage .cut-frame { height: 100%; }
.cut-stage .webtoon-cut img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}
.cut-stage .webtoon-cut:has(button) {
  overflow: auto;
  padding: 6px 8px;
}

.cut-stage .webtoon-cut p { margin: 0 0 4px; font: 14px/1.35 Arial, sans-serif; }
.cut-stage .webtoon-cut button { font: 14px/1.35 Arial, sans-serif; }
.cut-alt {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-height: 500px) {
  .cut-stage, .cut-section > .webtoon-cut img { max-height: 42cqh; }
}
