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

body {
  font-family: serif;
  background: #fafafa;
  color: #1a1a1a;
  height: 100dvh;
  overflow: hidden;
}


/* ── Code gate ─────────────────────────────────────────────────────────────── */

#code-gate {
  position: fixed;
  inset: 0;
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.gate-hidden  { display: none  !important; }
.gate-visible { display: flex  !important; }

.gate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  max-width: 22rem;
  padding: 2rem;
}

.gate-title {
  font-size: 1.1rem;
  color: #1a1a1a;
  text-align: center;
  margin-bottom: 0;
  line-height: 1.3;
}

.gate-author {
  font-size: 0.85rem;
  font-style: italic;
  color: #888;
  text-align: center;
  margin-bottom: 0.5rem;
}

.gate-error {
  font-size: 0.85rem;
  color: #999;
  font-style: italic;
  min-height: 1.2em;
  text-align: center;
}

#email-input,
#secret-input {
  font-family: serif;
  font-size: 1rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid #ccc;
  background: #fff;
  width: 100%;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}

#email-input:focus,
#secret-input:focus {
  border-color: #888;
}

/* The cipher field gets a slightly more ceremonial treatment */
#secret-input {
  font-style: italic;
  letter-spacing: 0.08em;
  border-style: dashed;
}

#secret-input:focus {
  border-style: solid;
}

#code-submit {
  font-family: serif;
  font-size: 0.95rem;
  padding: 0.4rem 1.5rem;
  border: 1px solid #1a1a1a;
  background: #1a1a1a;
  color: #fafafa;
  cursor: pointer;
  margin-top: 0.25rem;
  transition: background 0.2s, color 0.2s;
}

#code-submit:hover {
  background: #fafafa;
  color: #1a1a1a;
}


/* ── Reader layout ──────────────────────────────────────────────────────────── */

#reader {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100dvh;
}

.reader-hidden  { display: none !important; }
.reader-visible { display: grid !important; }


/* ── PDF panel ──────────────────────────────────────────────────────────────── */

#pdf-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e0e0e0;
  overflow: hidden;
  background: #3a3a3a;
}

#pdf-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

#pdf-loading {
  margin: auto;
  color: #aaa;
  font-family: sans-serif;
  font-size: 0.9rem;
}

#pdf-canvas {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  max-width: 100%;
}

.canvas-hidden  { display: none  !important; }
.canvas-visible { display: block !important; }

#pdf-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: #fafafa;
  border-top: 1px solid #e0e0e0;
}

#pdf-controls button {
  font-family: serif;
  font-size: 1.1rem;
  background: none;
  border: none;
  cursor: pointer;
  color: #1a1a1a;
  padding: 0.2rem 0.4rem;
  line-height: 1;
  transition: color 0.15s;
}

#pdf-controls button:hover:not(:disabled) { color: #555; }
#pdf-controls button:disabled { color: #ccc; cursor: default; }

#page-indicator {
  flex: 1;
  text-align: center;
  font-size: 0.85rem;
  color: #555;
}


/* ── Notes panel ────────────────────────────────────────────────────────────── */

#notes-panel {
  overflow-y: auto;
  padding: 2.5rem 3rem;
}

#notes-panel h1 {
  font-size: 1.45rem;
  font-weight: normal;
  line-height: 1.3;
  margin-bottom: 1.5rem;
}

#notes-panel h2 {
  font-size: 1.1rem;
  font-weight: normal;
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #e8e8e8;
}

#notes-panel h3 {
  font-size: 1.15rem;
  font-style: italic;
  font-weight: normal;
  margin: 2rem 0 0.6rem;
}

#notes-panel h4 {
  font-size: 0.95rem;
  font-weight: bold;
  margin: 1.25rem 0 0.4rem;
}

#notes-panel p {
  font-size: 1.05rem;
  line-height: 1.6;
  color: #2a2a2a;
  margin-bottom: 1.4rem;
}

#notes-panel a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: #ccc;
  transition: text-decoration-color 0.15s;
}

#notes-panel a:hover {
  text-decoration-color: #1a1a1a;
}

#notes-panel .page-ref {
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

#notes-panel .page-ref .ref-p {
  font-style: italic;
  color: inherit;
}

#notes-panel .page-ref .ref-num {
  color: #8a9fb0;
}

#notes-panel .page-ref:hover .ref-num {
  color: #5a7a90;
}

#notes-panel blockquote {
  border-left: 2px solid #ddd;
  padding-left: 1rem;
  margin: 1rem 0;
  color: #555;
}

#notes-panel blockquote p {
  font-style: italic;
  color: #555;
}

#notes-panel ul,
#notes-panel ol {
  margin: 0.5rem 0 1rem 1.5rem;
}

#notes-panel li {
  font-size: 1.05rem;
  line-height: 1.5;
  color: #2a2a2a;
  margin-bottom: 0.3rem;
}

#notes-panel code {
  font-family: monospace;
  font-size: 0.9em;
  background: #f0f0f0;
  padding: 0.15em 0.35em;
}

#notes-panel code:has(.page-ref) {
  font-family: inherit;
  font-size: inherit;
  background: none;
  padding: 0;
}

#notes-panel pre {
  background: #f5f5f5;
  border: 1px solid #e8e8e8;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
}

#notes-panel pre code {
  background: none;
  padding: 0;
  font-size: 0.9rem;
}

#notes-panel hr {
  border: none;
  border-top: 1px solid #e8e8e8;
  margin: 2rem 0;
}

#notes-panel strong {
  font-weight: bold;
}

#notes-panel em {
  font-style: italic;
}


/* ── Mobile ─────────────────────────────────────────────────────────────────── */

#zoom-btn {
  font-size: 1rem;
  opacity: 0.75;
}

#zoom-btn.fit-height {
  opacity: 1;
  color: #555;
}

@media (max-width: 768px) {
  body { overflow: auto; }

  #reader {
    grid-template-columns: 1fr;
    grid-template-rows: 100dvh auto;
    height: auto;
    min-height: 100dvh;
  }

  #pdf-panel {
    height: 100dvh;
    max-height: 100dvh;
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
  }


  #notes-panel {
    padding: 1.5rem;
  }
}
