:root {
  color-scheme: light;
  --navy: #0c1730;
  --ink: #102139;
  --muted: #657386;
  --green: #2ecc40;
  --green-deep: #159b31;
  --paper: #fbfaf4;
  --line: rgba(12, 23, 48, 0.12);
  --stage-width: min(86vw, calc((100dvh - 212px) * 16 / 9), 1440px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

html {
  overflow: hidden;
}

body {
  overflow: hidden;
  background: #edf2e9;
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", "Thonburi", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  display: grid;
  grid-template-rows: 84px minmax(0, 1fr) 76px;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 10% 105%, rgba(46, 204, 64, 0.17), transparent 32%),
    radial-gradient(circle at 90% -10%, rgba(139, 219, 99, 0.2), transparent 31%),
    linear-gradient(125deg, #f7f5ec 0%, #f0f5ec 52%, #edf4ea 100%);
}

.app::before {
  position: absolute;
  inset: 0;
  z-index: -3;
  background-image:
    linear-gradient(rgba(12, 23, 48, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(12, 23, 48, 0.028) 1px, transparent 1px);
  background-size: 62px 62px;
  mask-image: radial-gradient(circle at center, #000 12%, transparent 72%);
  content: "";
}

.energy-orbit {
  position: absolute;
  z-index: -2;
  border: 1px solid rgba(46, 204, 64, 0.22);
  border-radius: 50%;
  pointer-events: none;
}

.energy-orbit::after {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 8px rgba(46, 204, 64, 0.1), 0 0 24px rgba(46, 204, 64, 0.55);
  content: "";
}

.energy-orbit--one {
  top: 8%;
  right: -11vw;
  width: 34vw;
  height: 34vw;
  transform: rotate(-14deg);
}

.energy-orbit--one::after {
  top: 19%;
  left: 7%;
}

.energy-orbit--two {
  bottom: -23vw;
  left: -11vw;
  width: 42vw;
  height: 42vw;
  border-color: rgba(12, 23, 48, 0.1);
}

.energy-orbit--two::after {
  top: 2%;
  right: 24%;
}

.topbar {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 0 clamp(22px, 3.7vw, 70px);
  border-bottom: 1px solid rgba(12, 23, 48, 0.08);
  background: rgba(250, 250, 245, 0.76);
  backdrop-filter: blur(22px) saturate(130%);
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  height: 42px;
}

.brand img {
  display: block;
  width: auto;
  height: 36px;
}

.edition {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--navy);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.edition__eyebrow {
  opacity: 0.48;
}

.edition__mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.edition__mode i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(46, 204, 64, 0.12);
}

.top-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 4px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #34435b;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.action-button:hover,
.action-button:focus-visible {
  background: #fff;
  color: var(--green-deep);
  outline: none;
  transform: translateY(-1px);
}

.action-button svg,
.edge-button svg,
.thumbs__header button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-button:first-child svg {
  fill: currentColor;
  stroke: none;
}

.action-button:nth-child(2) svg {
  fill: currentColor;
  stroke: none;
}

.icon-collapse,
.app:not(:fullscreen) .icon-collapse,
.app:not(.is-fullscreen) .icon-collapse {
  display: none;
}

.app:fullscreen .icon-expand,
.app.is-fullscreen .icon-expand {
  display: none;
}

.app:fullscreen .icon-collapse,
.app.is-fullscreen .icon-collapse {
  display: block;
}

.reader {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  padding: 14px 0 8px;
}

.reader__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: var(--stage-width);
  min-width: 0;
  margin-bottom: 10px;
  color: var(--muted);
}

.reader__meta > div:first-child {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 12px;
}

.reader__section {
  flex: 0 0 auto;
  color: var(--green-deep);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.19em;
}

.reader__title {
  overflow: hidden;
  color: #4f5e73;
  font-size: 13px;
  font-weight: 580;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gesture-hint {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0.64;
  transition: opacity 320ms ease, transform 320ms ease;
}

.gesture-hint.is-hidden {
  opacity: 0;
  transform: translateY(5px);
}

.gesture-hint__spark {
  width: 22px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--green));
  box-shadow: 9px 0 8px rgba(46, 204, 64, 0.55);
}

.reader__stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.book-shell {
  position: relative;
  width: var(--stage-width);
  aspect-ratio: 16 / 9;
  border-radius: clamp(8px, 1vw, 15px);
  filter: drop-shadow(0 30px 42px rgba(12, 23, 48, 0.19));
  transition: filter 280ms ease, transform 280ms ease;
}

.reader__stage.is-turning .book-shell {
  filter: drop-shadow(0 35px 52px rgba(12, 23, 48, 0.25));
  transform: translateY(-2px);
}

#book {
  width: 100% !important;
  max-width: 1440px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: 100%;
  overflow: visible;
}

#book .stf__wrapper {
  border-radius: inherit;
  overflow: visible;
}

#book .stf__block {
  border-radius: inherit;
}

.book-page {
  overflow: hidden;
  background: #fff;
  border-radius: clamp(7px, 0.8vw, 13px);
  box-shadow: inset 0 0 0 1px rgba(12, 23, 48, 0.08);
}

.book-page::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 18px rgba(12, 23, 48, 0.06);
  pointer-events: none;
  content: "";
}

.book-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.page-edge {
  position: absolute;
  z-index: -1;
  right: -5px;
  bottom: -8px;
  left: 7px;
  height: 13px;
  border-radius: 0 0 14px 14px;
  background: repeating-linear-gradient(0deg, #e0ded5 0 1px, #fbfaf5 1px 2px);
  box-shadow: 0 10px 20px rgba(12, 23, 48, 0.12);
  transform: skewX(-17deg);
}

.book-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid rgba(12, 23, 48, 0.08);
  border-radius: inherit;
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.96), rgba(239, 247, 237, 0.96));
  color: var(--navy);
  transition: visibility 250ms ease, opacity 250ms ease;
}

.book-loading.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.book-loading__mark {
  width: 38px;
  height: 38px;
  margin-bottom: 4px;
  border: 3px solid rgba(46, 204, 64, 0.18);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.book-loading strong {
  font-size: 16px;
}

.book-loading small {
  color: var(--muted);
  font-size: 12px;
}

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

.edge-button {
  position: absolute;
  top: 50%;
  z-index: 22;
  display: grid;
  width: 48px;
  height: 76px;
  place-items: center;
  border: 1px solid rgba(12, 23, 48, 0.1);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--navy);
  box-shadow: 0 14px 32px rgba(12, 23, 48, 0.11);
  backdrop-filter: blur(16px);
  cursor: pointer;
  transform: translateY(-50%);
  transition: opacity 180ms ease, transform 180ms ease, background 180ms ease, color 180ms ease;
}

.edge-button:hover,
.edge-button:focus-visible {
  background: var(--navy);
  color: #fff;
  outline: none;
}

.edge-button:active {
  transform: translateY(-50%) scale(0.95);
}

.edge-button:disabled {
  visibility: hidden;
  opacity: 0;
}

.edge-button--prev {
  left: max(18px, calc((100vw - var(--stage-width)) / 2 - 70px));
}

.edge-button--next {
  right: max(18px, calc((100vw - var(--stage-width)) / 2 - 70px));
}

.controlbar {
  position: relative;
  z-index: 25;
  display: grid;
  grid-template-columns: 105px minmax(160px, 680px) 150px;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 0 clamp(22px, 4vw, 72px) max(0px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(12, 23, 48, 0.08);
  background: rgba(250, 250, 246, 0.72);
  backdrop-filter: blur(22px) saturate(130%);
}

.controlbar__page {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--navy);
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0.09em;
}

.controlbar__page i {
  width: 24px;
  height: 1px;
  background: var(--green);
}

.controlbar__page span:last-child {
  color: #96a1ae;
}

.page-scrubber {
  width: 100%;
  height: 28px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.page-scrubber::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green) 0 var(--progress, 0%), rgba(12, 23, 48, 0.13) var(--progress, 0%) 100%);
}

.page-scrubber::-webkit-slider-thumb {
  width: 15px;
  height: 15px;
  margin-top: -6px;
  appearance: none;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 1px 7px rgba(12, 23, 48, 0.28);
}

.page-scrubber::-moz-range-track {
  height: 3px;
  border: 0;
  border-radius: 99px;
  background: rgba(12, 23, 48, 0.13);
}

.page-scrubber::-moz-range-progress {
  height: 3px;
  border-radius: 99px;
  background: var(--green);
}

.page-scrubber::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 1px 7px rgba(12, 23, 48, 0.28);
}

.controlbar__help {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  color: #788698;
  font-size: 11px;
}

.controlbar__help kbd {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid rgba(12, 23, 48, 0.14);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--navy);
  box-shadow: inset 0 -1px 0 rgba(12, 23, 48, 0.08);
}

.controlbar__help span {
  margin-left: 5px;
}

.thumbs {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(430px, 94vw);
  padding: 30px 24px 22px;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(8, 20, 38, 0.96);
  color: #fff;
  box-shadow: -30px 0 80px rgba(4, 10, 20, 0.28);
  backdrop-filter: blur(24px) saturate(120%);
  transform: translateX(105%);
  transition: transform 320ms cubic-bezier(0.22, 0.8, 0.24, 1);
}

.thumbs.is-open {
  transform: translateX(0);
}

.thumbs__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 2px 4px 24px;
}

.thumbs__header span {
  color: #62e474;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.18em;
}

.thumbs__header h2 {
  margin: 7px 0 0;
  font-size: 21px;
  font-weight: 650;
}

.thumbs__header button {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
}

.thumbs__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 18px 14px;
  overflow-y: auto;
  padding: 0 5px 28px;
  scrollbar-color: rgba(98, 228, 116, 0.5) transparent;
  scrollbar-width: thin;
}

.thumb-card {
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.thumb-card__image {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.thumb-card__image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-card__number {
  position: absolute;
  right: 7px;
  bottom: 7px;
  display: grid;
  min-width: 28px;
  height: 24px;
  padding: 0 6px;
  place-items: center;
  border-radius: 6px;
  background: rgba(7, 18, 33, 0.82);
  color: #fff;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.thumb-card__title {
  display: block;
  overflow: hidden;
  margin-top: 7px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb-card:hover .thumb-card__image,
.thumb-card:focus-visible .thumb-card__image,
.thumb-card.is-active .thumb-card__image {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(46, 204, 64, 0.13);
  transform: translateY(-2px);
}

.thumb-card.is-active .thumb-card__title {
  color: #83ee91;
}

.scrim {
  position: absolute;
  inset: 0;
  z-index: 55;
  visibility: hidden;
  border: 0;
  background: rgba(4, 12, 24, 0.26);
  opacity: 0;
  cursor: default;
  transition: visibility 320ms ease, opacity 320ms ease;
}

.scrim.is-open {
  visibility: visible;
  opacity: 1;
}

.app:fullscreen,
.app.is-fullscreen {
  grid-template-rows: 72px minmax(0, 1fr) 66px;
  background: #edf3e9;
}

.app:fullscreen .reader,
.app.is-fullscreen .reader {
  padding-top: 8px;
}

.app:fullscreen,
.app.is-fullscreen {
  --stage-width: min(94vw, calc((100dvh - 172px) * 16 / 9), 1660px);
}

@media (max-width: 900px) {
  :root {
    --stage-width: min(91vw, calc((100dvh - 190px) * 16 / 9));
  }

  .app {
    grid-template-rows: 72px minmax(0, 1fr) 68px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    padding-inline: 18px;
  }

  .edition {
    display: none;
  }

  .brand img {
    height: 30px;
  }

  .action-button {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .action-button span {
    display: none;
  }

  .reader {
    justify-content: center;
    padding-top: 8px;
  }

  .gesture-hint,
  .reader__title {
    display: none;
  }

  .reader__meta {
    margin-bottom: 7px;
  }

  .book-shell {
    filter: drop-shadow(0 20px 28px rgba(12, 23, 48, 0.18));
  }

  .edge-button {
    top: 50%;
    bottom: auto;
    z-index: 28;
    width: 38px;
    height: 56px;
    border-radius: 12px;
    transform: translateY(-50%);
  }

  .edge-button:active {
    transform: translateY(-50%) scale(0.95);
  }

  .edge-button--prev {
    left: 2px;
  }

  .edge-button--next {
    right: 2px;
  }

  .controlbar {
    grid-template-columns: 70px minmax(100px, 1fr);
    gap: 12px;
    padding-inline: 20px;
  }

  .controlbar__page {
    gap: 7px;
    font-size: 12px;
  }

  .controlbar__page i {
    width: 11px;
  }

  .controlbar__help {
    display: none;
  }
}

@media (max-width: 520px) {
  :root {
    --stage-width: 94vw;
  }

  .app {
    min-height: 430px;
  }

  .top-actions {
    gap: 0;
  }

  .top-actions .action-button:nth-child(2) {
    display: none;
  }

  .reader {
    justify-content: flex-start;
    padding-top: min(14vh, 88px);
  }

  .reader__meta {
    position: absolute;
    top: 20px;
  }

  .book-loading strong {
    font-size: 13px;
  }

  .book-loading small {
    display: none;
  }

  .book-loading__mark {
    width: 28px;
    height: 28px;
  }

  .thumbs {
    width: 100vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
