@font-face {
  font-family: Cinzel;
  src: url("fonts/Cinzel.ttf") format("truetype");
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --bg: #000000;
  --gold: #c9a84c;
  --gold-soft: #e6d7a8;
  --cream: #f3efe6;
  --ink: #d8d8d8;
  --muted: #9a9a9a;
  --error: #e8b4b4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vv-top: 0px;
  --app-height: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #000;
  color: var(--cream);
  font-family: "Source Sans 3", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

img, a { -webkit-user-drag: none; user-drag: none; }

#app, .screen {
  min-height: 100dvh;
  min-height: 100svh;
  background: #000;
}

.screen { display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

/* Brand mark */
.ms-logo {
  display: block;
  height: auto;
  background: #000;
}

.ms-logo.signin {
  width: min(280px, 82vw);
  height: auto;
  margin: 0 auto 22px;
}

.ms-logo.library {
  width: auto;
  height: 40px;
  flex-shrink: 0;
  margin: 0;
}

.ms-logo.reader {
  height: 32px;
  width: auto;
  margin: 0 auto;
  pointer-events: none;
}

/* Sign in */
#screen-signin {
  align-items: center;
  justify-content: center;
  padding: calc(32px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  background: #000;
}

.signin-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

h1 {
  font-family: Cinzel, Palatino, "Times New Roman", serif;
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  margin: 0 0 16px;
  color: var(--cream);
}

.lede {
  margin: 0 0 28px;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.45;
}

#signin-form { text-align: left; }

label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 6px;
}

input[type="email"] {
  width: 100%;
  padding: 14px 14px;
  border: 1px solid rgba(201, 168, 76, 0.45);
  border-radius: 8px;
  background: #111;
  color: var(--cream);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

input[type="email"]::placeholder { color: #777; }
input[type="email"]:focus { border-color: var(--gold); }

#signin-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  color: #000;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  font-family: inherit;
}

#signin-btn:active { opacity: 0.9; }
#signin-btn:disabled { opacity: 0.7; cursor: wait; }

.signin-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
}


.error {
  margin: 14px 0 0;
  color: var(--error);
  font-size: 0.9rem;
  text-align: center;
}

/* Library */
#screen-library {
  background: #000;
  padding-bottom: var(--safe-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  border-bottom: 1px solid rgba(201, 168, 76, 0.22);
  background: #000;
}

.topbar-text h1 {
  margin: 0;
  font-size: 1.15rem;
}

.library-body {
  padding: 24px 20px 32px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

.library-body h2 {
  font-family: Cinzel, Palatino, serif;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 16px;
}

.book-card {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid rgba(201, 168, 76, 0.4);
  border-radius: 12px;
  overflow: hidden;
  background: #111;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.book-card img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.book-meta { padding: 16px 16px 18px; }

.book-meta h3 {
  font-family: Cinzel, Palatino, serif;
  font-size: 1.25rem;
  margin: 0 0 4px;
  font-weight: 700;
}

.book-meta .volume {
  margin: 0;
  color: var(--gold);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-meta .subtitle {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 0.95rem;
}

.session-line, .install-hint {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
}

.linkish {
  border: 0;
  background: none;
  color: var(--gold-soft);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Reader — visible viewport, page sits between header and footer */
#screen-reader {
  position: fixed;
  top: var(--vv-top, 0px);
  left: 0;
  width: 100%;
  height: var(--app-height, 100svh);
  min-height: 0;
  overflow: hidden;
  background: #000;
  display: flex;
  flex-direction: column;
}

#viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  background: #000;
}

#stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
}

#page-wrap {
  position: relative;
  line-height: 0;
  flex: 0 0 auto;
}

#page-img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Slim chrome in document flow — page is laid out between them */
.reader-chrome {
  position: relative;
  flex: 0 0 auto;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #000;
}

.reader-top {
  padding: calc(6px + var(--safe-top)) 8px 6px;
  min-height: calc(44px + var(--safe-top));
  border-bottom: 1px solid rgba(201, 168, 76, 0.18);
}

.reader-nav {
  padding: 4px 10px calc(8px + var(--safe-bottom));
  min-height: calc(44px + var(--safe-bottom));
  border-top: 1px solid rgba(201, 168, 76, 0.18);
}

#screen-reader.chrome-hidden .reader-top,
#screen-reader.chrome-hidden .reader-nav {
  height: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

#page-counter, #nav-counter {
  margin: 0;
  font-size: 0.78rem;
  color: var(--gold-soft);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

#page-counter {
  min-width: 64px;
  text-align: right;
  padding-right: 6px;
}

#nav-counter {
  color: var(--cream);
  font-size: 0.85rem;
}

.text-btn, .nav-arrow {
  border: 0;
  background: none;
  color: var(--gold);
  font: inherit;
  cursor: pointer;
}

.text-btn {
  font-size: 0.85rem;
  padding: 8px 10px;
  min-width: 64px;
  text-align: left;
}

.nav-arrow {
  width: 56px;
  height: 44px;
  font-size: 2rem;
  line-height: 1;
  color: var(--gold);
}

.nav-arrow:disabled, .text-btn:disabled { opacity: 0.35; cursor: default; }

.edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22%;
  border: 0;
  background: transparent;
  padding: 0;
  z-index: 3;
  cursor: pointer;
}

.edge-left { left: 0; }
.edge-right { right: 0; }


.success {
  margin: 14px 0 0;
  color: var(--gold-soft);
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.45;
}

.success a {
  color: var(--gold);
  font-weight: 700;
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.book-card.locked {
  cursor: default;
}

.book-card.locked img {
  opacity: 0.55;
  filter: grayscale(0.15);
}

.book-actions {
  margin-top: 12px;
}

.buy-btn, .open-btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
}

.open-btn {
  border: 0;
  background: var(--gold);
  color: #000;
}

.buy-btn {
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
}

.book-status {
  margin: 8px 0 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.book-card.owned .book-status { color: var(--gold); }

@media (min-width: 720px) {
  .library-body { padding-top: 32px; }
  .book-card { display: flex; align-items: stretch; }
  .book-card img { width: 220px; flex-shrink: 0; }
  .book-meta { display: flex; flex-direction: column; justify-content: center; }
}
