/* ==========================================================================
   MOMOTARŌ POP-UP BOOK — JAPANESE WASHI & WOODBLOCK STORYBOOK STYLES
   Pure book experience: zero surrounding navigation chrome or HUD widgets.
   WCAG AA ink contrast across warm handmade kōzo paper surfaces.
   ========================================================================== */

:root {
  color-scheme: light;

  --desk-bg: #d9cbb6;
  --washi: #f5eddc;
  --washi-deep: #ece1cb;
  --washi-tint: #fbf7ee;
  --washi-edge: #c9b594;
  --washi-rule: #b89e74;

  --ink: #1a100c;
  --ink-muted: #3b2a20;
  --ink-soft: #4e3b2e;

  --akane: #8e1f17;
  --akane-hover: #6d150e;
  --akane-bg: #f6e1dc;
  --indigo: #16314d;
  --indigo-soft: #e6eef4;
  --pine: #1b442e;
  --gold: #724d0c;
  --gold-bright: #b88b32;

  --error-ink: #8f1919;
  --error-bg: #fae9e7;
  --select-bg: #f2cf88;

  --font-serif: 'Baskerville', 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua',
    'Hiragino Mincho ProN', 'Yu Mincho', Georgia, serif;
  --font-sans: 'Hiragino Sans', 'SF Pro Text', -apple-system, BlinkMacSystemFont,
    'Segoe UI', sans-serif;

  accent-color: var(--akane);
}

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

html {
  margin: 0;
  padding: 0;
  background-color: var(--desk-bg);
  color: var(--ink);
  font-family: var(--font-serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(110, 86, 62, 0.45) transparent;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--desk-bg);
  overflow-x: hidden;
}

/* Full-viewport fixed WebGL canvas stage — zero surrounding UI */
.book-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#book-canvas {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
  outline: none;
}

/* Scroll spacer driving continuous book opening (0..6 spreads) */
.scroll-track {
  position: relative;
  width: 1px;
  height: 6200px;
  pointer-events: none;
}

/* Fallback overlay container when native HTML-in-Canvas is unsupported */
.hic-fallback-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.hic-fallback-layer .book-plaque {
  pointer-events: auto;
  box-shadow: 0 10px 26px rgba(42, 26, 14, 0.22);
}

/* Accessible live region */
.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* ==========================================================================
   BASE DRAWABLE PLAQUE ELEMENTS (Captured via texElementSubImage2D)
   ========================================================================== */

.book-plaque {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background-color: var(--washi);
  background-image:
    radial-gradient(rgba(128, 97, 56, 0.08) 1px, transparent 1px),
    radial-gradient(rgba(255, 252, 244, 0.55) 1px, transparent 1px),
    linear-gradient(180deg, #faf4e6 0%, #f5eddc 52%, #eee2ca 100%);
  background-size: 18px 18px, 29px 29px, 100% 100%;
  background-position: 0 0, 7px 11px, 0 0;
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
  overflow: hidden;
  border-radius: 3px;
}

.book-plaque ::selection {
  background-color: var(--select-bg);
  color: var(--ink);
}

/* ==========================================================================
   COVER & BACK COVER CARTOUCHE PLAQUES
   ========================================================================== */

.plaque-cover {
  width: 440px;
  height: 540px;
  padding: 18px;
  background-color: #f6eedb;
  border: 2px solid #b58d40;
  box-shadow:
    inset 0 0 0 4px #f6eedb,
    inset 0 0 0 6px #96261d;
}

.plaque-back {
  width: 420px;
  height: 480px;
  padding: 18px;
  background-color: #f5ecda;
  border: 2px solid #b58d40;
  box-shadow:
    inset 0 0 0 4px #f5ecda,
    inset 0 0 0 6px #96261d;
}

.cover-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border: 1.5px solid #bfa066;
  padding: 28px 30px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 50% 34%, rgba(226, 175, 162, 0.16), transparent 62%),
    linear-gradient(180deg, #fbf6ea 0%, #f3e9d3 100%);
}

.cover-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: #96261d;
  border-style: solid;
  border-width: 0;
}

.cover-corner-tl {
  top: 8px;
  left: 8px;
  border-top-width: 2.5px;
  border-left-width: 2.5px;
}

.cover-corner-tr {
  top: 8px;
  right: 8px;
  border-top-width: 2.5px;
  border-right-width: 2.5px;
}

.cover-corner-bl {
  bottom: 8px;
  left: 8px;
  border-bottom-width: 2.5px;
  border-left-width: 2.5px;
}

.cover-corner-br {
  bottom: 8px;
  right: 8px;
  border-bottom-width: 2.5px;
  border-right-width: 2.5px;
}

.cover-kicker {
  margin: 0 0 12px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--akane);
}

.cover-seal-ring {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2.5px solid var(--akane);
  background: radial-gradient(circle at 38% 32%, #f8d4cc, #e48f8b 65%, #c95d57 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: inset 0 0 0 3px rgba(255, 246, 232, 0.72);
}

.cover-seal-kanji {
  font-size: 32px;
  font-weight: 700;
  color: #fffaf0;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(64, 14, 10, 0.45);
}

.cover-title {
  margin: 0;
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.05;
  color: #1f1410;
}

.cover-subtitle {
  margin: 6px 0 0;
  font-size: 19px;
  font-style: italic;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--akane);
}

.cover-rule {
  width: 112px;
  height: 2px;
  border: 0;
  margin: 18px auto 16px;
  background: linear-gradient(90deg, transparent, #b38938 25%, #96261d 50%, #b38938 75%, transparent);
}

.cover-epigraph {
  margin: 0 0 22px;
  font-size: 14.5px;
  line-height: 1.56;
  color: var(--ink-muted);
  max-width: 320px;
}

.cover-action-row {
  margin-bottom: 16px;
}

.cover-belly-note {
  margin: 0 0 10px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.02em;
}

.cover-edition {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
}

.back-frame {
  padding: 28px 28px 22px;
}

.back-title {
  margin: 0 0 14px;
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.06em;
}

.back-note {
  margin: 0 0 16px;
  padding: 12px 16px;
  font-size: 15px;
  font-style: italic;
  line-height: 1.5;
  color: var(--akane);
  border-top: 1px solid #cdb78f;
  border-bottom: 1px solid #cdb78f;
}

.back-credit {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.back-signature-line {
  margin: 0 0 22px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.back-actions {
  margin-bottom: 18px;
}

/* ==========================================================================
   INNER SPREAD STORY PLAQUES (Lower inlaid washi panels on left/right boards)
   ========================================================================== */

.plaque-page {
  width: 560px;
  height: 336px;
  padding: 15px 22px 12px;
  display: flex;
  flex-direction: column;
  border: 1.5px solid #baa27b;
  box-shadow:
    inset 0 0 0 4px rgba(252, 248, 237, 0.8),
    inset 0 0 0 5px rgba(173, 145, 97, 0.65);
}

/* Soft gutter edge darkening hinting toward the paper fold seam */
.plaque-left {
  background-image:
    linear-gradient(90deg, rgba(84, 62, 34, 0.01) 78%, rgba(56, 38, 18, 0.14) 100%),
    linear-gradient(180deg, rgba(84, 62, 34, 0.06) 0%, transparent 18%),
    linear-gradient(180deg, #faf4e6 0%, #f4ebda 100%);
}

.plaque-right {
  background-image:
    linear-gradient(270deg, rgba(84, 62, 34, 0.01) 78%, rgba(56, 38, 18, 0.14) 100%),
    linear-gradient(180deg, rgba(84, 62, 34, 0.06) 0%, transparent 18%),
    linear-gradient(180deg, #faf4e6 0%, #f4ebda 100%);
}

/* Subtle regional tint variations that stay effortlessly legible */
.plaque-sea {
  border-color: #6b889e;
  background-color: #f0f2f2;
  background-image:
    linear-gradient(180deg, rgba(28, 56, 86, 0.07) 0%, rgba(28, 56, 86, 0.0) 22%),
    linear-gradient(180deg, #f5f5f2 0%, #e7ecec 100%);
}

.plaque-sea .chapter-tag,
.plaque-sea .drop-cap {
  color: var(--indigo);
}

.plaque-oni {
  border-color: #9e6b5b;
  background-image:
    linear-gradient(180deg, rgba(114, 34, 24, 0.06) 0%, transparent 20%),
    linear-gradient(180deg, #faf0e4 0%, #f1e3d1 100%);
}

.plaque-finale {
  border-color: #b78d3e;
  background-image:
    linear-gradient(180deg, rgba(182, 138, 52, 0.08) 0%, transparent 22%),
    linear-gradient(180deg, #fcf6e8 0%, #f3e6cb 100%);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 5px;
  margin-bottom: 7px;
  border-bottom: 1px solid rgba(154, 128, 86, 0.45);
  flex-shrink: 0;
}

.chapter-tag {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--akane);
  text-transform: uppercase;
}

.page-numeral {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
}

.page-title {
  margin: 0 0 8px;
  font-size: 27px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.form-title {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
}

.story-prose {
  margin: 0 0 9px;
  font-size: 15.8px;
  line-height: 1.5;
  color: var(--ink);
}

.story-prose-compact {
  font-size: 14.2px;
  line-height: 1.46;
  color: var(--ink-muted);
}

.story-chronicle {
  font-size: 14.3px;
  line-height: 1.46;
  margin-bottom: 8px;
}

.drop-cap {
  float: left;
  font-size: 44px;
  line-height: 0.78;
  font-weight: 700;
  color: var(--akane);
  padding: 2px 5px 0 0;
}

.chronicle-quote {
  margin: 4px 0 6px;
  padding: 6px 12px;
  border-left: 3px solid var(--akane);
  background: rgba(150, 38, 29, 0.06);
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--akane);
}

.chronicle-note {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--ink-muted);
}

.roster-bar {
  display: flex;
  gap: 8px;
  margin: 8px 0 6px;
  flex-wrap: wrap;
}

.roster-pill {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px dashed #a88f64;
  background: rgba(255, 250, 238, 0.55);
  color: var(--ink-soft);
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.roster-pill.is-joined {
  border-style: solid;
  border-color: var(--pine);
  background: #e1efe5;
  color: var(--pine);
}

.page-foot {
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid rgba(154, 128, 86, 0.38);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tab-cue {
  font-family: var(--font-sans);
  font-size: 11px;
  font-style: italic;
  color: var(--ink-soft);
}

.hanko-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 7px;
  border: 1.5px solid var(--akane);
  border-radius: 3px;
  background: rgba(150, 38, 29, 0.08);
  color: var(--akane);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.hanko-indigo {
  border-color: var(--indigo);
  background: rgba(31, 60, 92, 0.08);
  color: var(--indigo);
}

/* ==========================================================================
   INTERACTIVE STORY FORMS & ACCESSIBLE VALIDATION (:user-invalid)
   ========================================================================== */

.book-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1 1 auto;
}

.field-split {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 10px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field-label {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.req-mark {
  color: var(--akane);
}

.paper-input,
.paper-select,
.paper-textarea {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.25;
  color: var(--ink);
  background: rgba(255, 252, 245, 0.9);
  border: 1.5px solid #8a7353;
  border-radius: 3px;
  padding: 5px 10px;
  width: 100%;
  min-height: 32px;
  outline: none;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.paper-textarea {
  min-height: 48px;
  resize: none;
  font-size: 13.8px;
  line-height: 1.32;
  padding: 5px 9px;
}

.paper-input:focus-visible,
.paper-select:focus-visible,
.paper-textarea:focus-visible,
.paper-range:focus-visible,
.woodblock-btn:focus-visible,
.tab-toggle-btn:focus-visible,
input[type="radio"]:focus-visible,
input[type="checkbox"]:focus-visible {
  outline: 2.5px solid var(--akane);
  outline-offset: 2px;
}

.paper-input:hover,
.paper-select:hover,
.paper-textarea:hover {
  border-color: var(--ink);
}

.field-hint {
  font-family: var(--font-sans);
  font-size: 10.5px;
  color: var(--ink-soft);
}

.field-error {
  display: none;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--error-ink);
  margin-top: 1px;
}

/* Show validation feedback ONLY after user interaction (:user-invalid) */
.paper-input:is(:user-invalid, .user-invalid-fallback),
.paper-textarea:is(:user-invalid, .user-invalid-fallback),
.paper-select:is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--error-ink);
  background-color: var(--error-bg);
}

.paper-input:is(:user-invalid, .user-invalid-fallback) ~ .field-error,
.paper-textarea:is(:user-invalid, .user-invalid-fallback) ~ .field-error {
  display: block;
}

.choice-fieldset {
  margin: 0;
  padding: 5px 9px 6px;
  border: 1px solid #c2ab84;
  border-radius: 3px;
  background: rgba(255, 250, 238, 0.45);
}

.field-legend {
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 0 4px;
}

.radio-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.radio-pill input[type="radio"] {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}

.radio-pill label {
  cursor: pointer;
  padding: 2px 3px 2px 0;
}

.check-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
}

.check-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.check-item label {
  cursor: pointer;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.paper-range {
  flex: 1 1 auto;
  height: 18px;
  cursor: pointer;
}

.form-actions {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}

.form-actions-tight {
  gap: 10px;
}

.woodblock-btn {
  appearance: none;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 7px 16px;
  min-height: 33px;
  border-radius: 3px;
  border: 1.5px solid var(--akane-hover);
  background: var(--akane);
  color: #fff9f2;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 2px 0 #5b140f;
  transition: background-color 0.14s ease, transform 0.1s ease;
}

.woodblock-btn:hover {
  background: var(--akane-hover);
}

.woodblock-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #5b140f;
}

.btn-cover-open {
  padding: 10px 24px;
  font-size: 13.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tab-toggle-btn {
  appearance: none;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 9px;
  border-radius: 2px;
  border: 1px solid var(--gold);
  background: #f8ecd2;
  color: #5e410d;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.tab-toggle-btn:hover {
  background: #edd7a8;
  color: #3a2606;
}

.tab-toggle-btn[aria-pressed="true"] {
  background: var(--akane);
  border-color: var(--akane);
  color: #fffaf0;
}

.seal-status {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  color: var(--pine);
  text-align: right;
  white-space: nowrap;
}

.blueprint-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--indigo);
  padding: 4px 8px;
  border: 1px dashed #6b889e;
  border-radius: 3px;
  background: rgba(31, 60, 92, 0.06);
}

.blueprint-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
}

.blueprint-toggle label {
  cursor: pointer;
}
