:root {
  --bg: #f5f5f5;
  --bg-2: #ffffff;
  --gold: #ff404c;
  --gold-2: #ff1a29;
  --ink: #333333;
  --muted: rgba(51, 51, 51, 0.62);
  --line: rgba(0, 0, 0, 0.12);
  --shadow: rgba(0, 0, 0, 0.16);
  --header: #231f20;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}
body {
  margin: 0;
  color: var(--ink);
  font-family: "Open Sans", sans-serif;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

#app {
  height: 100%;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.welcome {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.welcome-hero {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: var(--header);
  padding: calc(18px + var(--safe-t)) 24px 16px;
}

.welcome-logo {
  width: auto;
  height: auto;
  max-width: min(280px, 70vw);
  max-height: min(18dvh, 72px);
  object-fit: contain;
  animation: rise 1.1s ease both;
}

.welcome-kicker {
  margin: 10px 0 0;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  font-family: "Source Sans 3", "Source Sans Pro", sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  animation: rise 1.1s ease 0.15s both;
}

.shelf-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 8px 0 calc(18px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.welcome:has(#gateForm:not(.hidden)) .shelf-wrap {
  align-items: center;
  justify-content: center;
  padding: 28px 20px calc(28px + var(--safe-b));
  border-top: 0;
  background: var(--bg);
}

.shelf-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 calc(22px + var(--safe-r)) 12px calc(22px + var(--safe-l));
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
}

.shelf-count { color: var(--muted); letter-spacing: 0.08em; }
.shelf-tools { display: flex; align-items: center; gap: 14px; }
.leave {
  border: 0;
  background: transparent;
  color: var(--gold-2);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
}
.gate {
  width: min(420px, calc(100% - 32px - var(--safe-l) - var(--safe-r)));
  margin: 0;
  padding: 28px 26px 22px;
  border: 1px solid rgba(35, 31, 32, 0.14);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(35, 31, 32, 0.08);
}
.gate label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.gate input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 0 14px;
}
.gate input:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }
.gate button {
  width: 100%;
  height: 46px;
  margin-top: 16px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #fff;
  font: inherit;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
}
.gate-error {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: #b42318;
  font-size: 14px;
}

.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 calc(22px + var(--safe-r)) 12px calc(22px + var(--safe-l));
}
.search-bar input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 0 16px;
}
.search-bar input::placeholder { color: var(--muted); }
.search-bar input:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }
.search-bar button {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--gold-2);
  font: inherit;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  cursor: pointer;
}
.search-bar button:hover { border-color: var(--gold); }
.page-search { margin: 10px 14px 0; }
.page-search-note {
  margin: 6px 22px 0;
  color: var(--gold-2);
  font-size: 13px;
}

.shelf {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  gap: 28px 22px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px calc(22px + var(--safe-r)) calc(36px + var(--safe-b)) calc(22px + var(--safe-l));
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.shelf::-webkit-scrollbar { height: 6px; }
.shelf::-webkit-scrollbar-thumb { background: rgba(212, 175, 106, 0.35); border-radius: 99px; }

.shelf-wrap.can-swipe::after {
  content: "";
  position: absolute;
  top: 36px;
  right: 0;
  bottom: 0;
  width: 56px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(7, 7, 7, 0.94));
}

.shelf-hint {
  position: absolute;
  right: calc(10px + var(--safe-r));
  top: 58%;
  z-index: 2;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  pointer-events: none;
  border-radius: 50%;
  background: rgba(8, 8, 8, 0.82);
  border: 1px solid var(--line);
}

.shelf-hint-finger {
  position: relative;
  width: 16px;
  height: 22px;
  border: 1.5px solid var(--gold-2);
  border-radius: 9px 9px 7px 7px;
  background: linear-gradient(180deg, rgba(240, 217, 162, 0.34), rgba(212, 175, 106, 0.05));
  animation: shelf-nudge 1.7s ease-in-out infinite;
}
.shelf-hint-finger::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 7px;
  height: 6px;
  transform: translateX(-50%);
  border-radius: 5px 5px 3px 3px;
  border: 1px solid rgba(240, 217, 162, 0.8);
}

.shelf-empty {
  margin: 0 calc(22px + var(--safe-r)) 10px calc(22px + var(--safe-l));
  color: var(--muted);
  font-size: 14px;
}
.shelf-empty code { color: var(--gold-2); }

.mag {
  flex: 0 0 auto;
  width: 148px;
  border: 0;
  background: none;
  color: inherit;
  padding: 0 0 8px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  overflow: visible;
}
.mag:focus-visible { outline: 1px solid var(--gold); outline-offset: 4px; }

.mag-cover {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4.15;
  max-height: max(150px, calc(100dvh - 380px));
  border-radius: 2px 6px 6px 2px;
  overflow: hidden;
  background: #161616;
  transform: perspective(900px) rotateY(-9deg);
  transform-origin: left center;
  box-shadow:
    inset 8px 0 10px rgba(0,0,0,0.35),
    10px 14px 28px var(--shadow);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.mag-cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 10px;
  background: linear-gradient(90deg, #231f20, #ff404c 55%, #9d1822);
  z-index: 2;
}
.mag-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.25), transparent 18%);
  pointer-events: none;
}
.mag:hover .mag-cover,
.mag:active .mag-cover {
  transform: perspective(900px) rotateY(-2deg) translateY(-6px);
  box-shadow: 12px 22px 36px rgba(0,0,0,0.62);
}

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

.mag-name {
  display: block;
  margin-top: 12px;
  padding: 0 6px 2px 10px;
  font-family: "Open Sans", sans-serif;
  font-weight: 500;
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
  color: var(--ink);
  white-space: normal;
  overflow: visible;
}

.mag-pages {
  display: block;
  margin-top: 4px;
  padding-left: 10px;
  font-family: "Open Sans", sans-serif;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.3;
  color: rgba(51, 51, 51, 0.72);
  letter-spacing: 0;
}

.reader {
  position: fixed;
  inset: 0;
  background: #ececec;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.reader-bar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l));
  border-bottom: 1px solid rgba(212, 175, 106, 0.18);
}

.icon-btn,
.nav-btn {
  border: 0;
  background: transparent;
  color: var(--gold-2);
  cursor: pointer;
}
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

.reader-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.reader-logo { height: 28px; width: auto; background: var(--header); border-radius: 4px; }
.reader-meta strong {
  font-family: "Open Sans", sans-serif;
  font-weight: 500;
  font-size: 16px;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}
.zoom-controls {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.zoom-controls .icon-btn {
  width: 36px;
  height: 36px;
  font-size: 22px;
  line-height: 1;
}
.zoom-reset {
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--gold-2);
  min-width: 52px;
  height: 36px;
  padding: 0 8px;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.page-label {
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--muted);
  padding-right: 6px;
}

.flip-stage {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.flip-stage.is-dragging { cursor: grabbing; }

.flip-track {
  height: 100%;
  min-height: 0;
  display: flex;
  will-change: transform;
}

.flip-page {
  flex: 0 0 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 12px calc(16px + var(--safe-r)) calc(18px + var(--safe-b)) calc(16px + var(--safe-l));
}

.flip-page img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  transform-origin: center center;
  border-radius: 2px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.55);
  background: #fff;
  pointer-events: none;
  transition: transform 160ms ease;
}
.flip-stage.is-live .flip-page img { transition: none; }

.nav-btn {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 48px;
  height: 72px;
  font-size: 34px;
  opacity: 0.35;
  transform: translateY(-30%);
}
.nav-btn:hover { opacity: 1; }
.nav-prev { left: calc(4px + var(--safe-l)); }
.nav-next { right: calc(4px + var(--safe-r)); }

.swipe-hint {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-b));
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 14px 18px 12px;
  transform: translateX(-50%);
  pointer-events: none;
  color: var(--gold-2);
  background: rgba(8, 8, 8, 0.78);
  border: 1px solid var(--line);
  border-radius: 18px;
  backdrop-filter: blur(10px);
}
.swipe-hint p {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.swipe-stage {
  position: relative;
  width: 132px;
  height: 52px;
}
.swipe-trail {
  position: absolute;
  left: 8px;
  right: 22px;
  top: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold));
  opacity: 0.8;
}
.swipe-finger {
  position: absolute;
  top: 8px;
  left: 0;
  width: 22px;
  height: 30px;
  border: 1.5px solid var(--gold-2);
  border-radius: 12px 12px 10px 10px;
  background: linear-gradient(180deg, rgba(240, 217, 162, 0.38), rgba(212, 175, 106, 0.06));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
}
.swipe-finger::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 50%;
  width: 8px;
  height: 7px;
  transform: translateX(-50%);
  border-radius: 6px 6px 3px 3px;
  border: 1px solid rgba(240, 217, 162, 0.85);
}
.swipe-hint.is-playing .swipe-finger {
  animation: finger-swipe 1.45s cubic-bezier(.45, .05, .25, 1) 2;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

@keyframes finger-swipe {
  0% { transform: translateX(96px) scale(0.94); opacity: 0; }
  14% { opacity: 1; transform: translateX(88px) scale(1); }
  24% { transform: translateX(78px) scale(0.88); }
  76% { transform: translateX(4px) scale(0.88); opacity: 1; }
  100% { transform: translateX(-4px) scale(0.94); opacity: 0; }
}

@keyframes shelf-nudge {
  0%, 100% { transform: translateX(8px); opacity: 0.35; }
  50% { transform: translateX(-14px); opacity: 1; }
}

@media (max-width: 720px) {
  .mag { width: min(126px, 38vw); }
  .nav-btn { display: none; }
  .welcome-kicker { letter-spacing: 0.32em; }
}

@media (max-width: 380px) {
  .welcome-kicker { letter-spacing: 0.22em; font-size: 10px; }
  .reader-logo { display: none; }
  .reader-meta strong { font-size: 16px; }
  .page-label { letter-spacing: 0.08em; }
  .shelf-head { letter-spacing: 0.18em; }
}

@media (max-height: 520px) {
  .welcome-hero { padding-top: calc(8px + var(--safe-t)); padding-bottom: 4px; }
  .welcome-logo { max-height: 72px; max-width: min(260px, 52vw); }
  .welcome-kicker { margin-top: 4px; }
  .mag { width: 108px; }
  .mag-name { margin-top: 6px; font-size: 14px; }
  .shelf { padding-top: 4px; padding-bottom: calc(28px + var(--safe-b)); }
  .shelf-head { padding-bottom: 6px; }
  .flip-page { padding-top: 6px; padding-bottom: calc(8px + var(--safe-b)); }
  .reader-bar { padding-top: calc(6px + var(--safe-t)); padding-bottom: 6px; }
  .swipe-hint { bottom: calc(12px + var(--safe-b)); padding-top: 8px; }
  .swipe-stage { height: 42px; }
}

@media (min-width: 1100px) {
  .mag { width: 168px; }
}

@media (hover: none) and (pointer: coarse) {
  .shelf { scrollbar-width: none; }
  .shelf::-webkit-scrollbar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .welcome-logo,
  .welcome-kicker,
  .shelf-hint-finger,
  .swipe-hint.is-playing .swipe-finger { animation: none; }
  .mag-cover { transition: none; }
  .swipe-finger { opacity: 1; transform: translateX(36px); }
}
