/* Papercraft Story Island Stylesheet */
:root {
  --desk: #f4ede0;
  --desk-edge: #e7dbc6;
  --paper: #f3e6ce;
  --paper-deep: #e5d2b0;
  --core: #fbf6ea;
  --ink: #4a2f1d;
  --ink-soft: rgba(74, 47, 29, 0.72);
  --edge: #cfb992;
  --accent: #b85d3d;
  --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85 .62' numOctaves='2' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .25 0 0 0 0 .15 .32 0 0 0 -.12'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --cut: inset 1px 1px 0 rgba(251, 246, 234, 0.8), 0 0 0 1px rgba(74, 44, 34, 0.55), 1px 1px 0 1px rgba(74, 44, 34, 0.45);
  --contact: 1px 2px 2px rgba(74, 44, 34, 0.34);
  --cast: 6px 10px 18px rgba(74, 44, 34, 0.18);
  --font-serif: "Noto Serif TC", "Source Han Serif TC", "Songti TC", Georgia, "Microsoft JhengHei", serif;
  --font-ui: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

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

html,
body {
  height: 100dvh;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background-color: var(--desk);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

button,
a {
  -webkit-touch-callout: none;
}

body.island-page {
  position: relative;
  background-image:
    radial-gradient(ellipse 84% 78% at 50% 46%, rgba(251, 246, 234, 0.65) 0%, rgba(244, 237, 224, 0.2) 58%, rgba(215, 198, 170, 0.42) 100%),
    var(--paper-grain);
}

/* Subtle macro tilt-shift warmth at extreme top and bottom table edges */
body.island-page::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background:
    linear-gradient(to bottom, rgba(244, 237, 224, 0.34) 0%, transparent 11%, transparent 88%, rgba(232, 218, 195, 0.42) 100%);
}

.stage-wrap {
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: 1;
  transition: opacity 0.32s ease;
}

.stage-wrap.is-booting {
  opacity: 0;
}

.stage-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.stage-canvas.is-dragging {
  cursor: grabbing;
}

.stage-canvas.is-pointer {
  cursor: pointer;
}

/* Top bar: brand on top-left, sound toggle and list link on top-right */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 8px calc(16px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.brand {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
  padding: 5px 12px 5px 7px;
  border-radius: 5px 7px 6px 5px;
  background: var(--paper-grain), rgba(243, 230, 206, 0.9);
  box-shadow: var(--cut), 1px 2px 0 var(--edge), var(--contact);
}

.brand-seal {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 4px 5px 4px 6px;
  background: var(--accent);
  color: var(--core);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 17px;
  line-height: 1;
  box-shadow: inset 1px 1px 0 rgba(251, 246, 234, 0.45), 1px 1px 2px rgba(74, 44, 34, 0.3);
}

.brand-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(18px, 2.4vw, 22px);
  letter-spacing: 0.1em;
  color: var(--ink);
  line-height: 1.1;
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  pointer-events: auto;
}

.sound-btn {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 6px 7px 6px 8px;
  background: var(--paper-grain), var(--paper);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--cut), 1px 2px 0 var(--edge), var(--contact);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.sound-btn:hover {
  transform: translateY(-1px);
}

.sound-btn:active {
  transform: translate(1px, 2px);
  box-shadow: var(--cut), 0 0 0 var(--edge), 1px 1px 1px rgba(74, 44, 34, 0.35);
}

.sound-btn:focus-visible,
.list-link:focus-visible,
.landmark-label:focus-visible,
.tray-close:focus-visible,
.book-card:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 3px;
}

.sound-btn .sound-off {
  display: none;
}

.sound-btn.is-muted .sound-on {
  display: none;
}

.sound-btn.is-muted .sound-off {
  display: block;
}

.list-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 4px 6px 5px 5px;
  background: var(--paper-grain), rgba(243, 230, 206, 0.72);
  color: rgba(74, 47, 29, 0.58);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  box-shadow: var(--cut), 1px 1px 0 var(--edge), var(--contact);
  transition: transform 0.08s ease, color 0.15s ease, background-color 0.15s ease;
}

.list-link:hover {
  color: var(--ink);
  background: var(--paper-grain), rgba(243, 230, 206, 0.92);
  transform: translateY(-1px);
}

/* Projected 3D landmark paper tags */
.labels-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: hidden;
}

.landmark-label {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
  touch-action: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  margin: 0;
  padding: 6px 12px 6px 10px;
  border-radius: 4px 7px 5px 6px;
  border-left: 5px solid var(--theme-color, #8c6a4a);
  background: var(--paper-grain), var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: 0.03em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow:
    inset 1px 1px 0 rgba(251, 246, 234, 0.78),
    0 0 0 1px rgba(74, 44, 34, 0.5),
    1px 2px 0 var(--edge),
    2px 4px 8px rgba(74, 44, 34, 0.22);
  will-change: transform, opacity;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.landmark-label:hover {
  background-color: var(--core);
}

.landmark-label.is-selected {
  font-size: 22px;
  padding: 7px 15px 7px 12px;
  background-color: var(--core);
  box-shadow:
    inset 1px 1px 0 rgba(251, 246, 234, 0.9),
    0 0 0 2px var(--theme-color, #b85d3d),
    2px 3px 0 var(--edge),
    4px 8px 16px rgba(74, 44, 34, 0.28);
}

/* Subtle bottom onboarding hint */
.bottom-hint {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 15;
  margin: 0;
  padding: 5px 14px;
  pointer-events: none;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: rgba(74, 47, 29, 0.62);
  text-shadow: 0 1px 0 rgba(251, 246, 234, 0.85);
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.9s ease, transform 0.9s ease;
}

.bottom-hint.is-gone {
  opacity: 0;
  transform: translate(-50%, 6px);
}

/* Fan-spread playing-card book tray */
.cards-tray {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 6px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(235, 222, 198, 0.94) 0%, rgba(244, 237, 224, 0.78) 74%, rgba(244, 237, 224, 0) 100%);
  pointer-events: none;
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.42s cubic-bezier(0.22, 1.12, 0.36, 1), opacity 0.28s ease;
}

.cards-tray[hidden] {
  display: none;
}

.cards-tray.is-entering {
  transform: translateY(36px);
  opacity: 0;
}

@keyframes trayBounce {
  0% { transform: translateY(0); }
  38% { transform: translateY(-7px); }
  100% { transform: translateY(0); }
}

.cards-tray.is-bouncing {
  animation: trayBounce 0.28s cubic-bezier(0.22, 1.12, 0.36, 1);
}

.tray-bar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
  margin-bottom: -4px;
  pointer-events: none;
}

.tray-title {
  margin: 0;
  padding: 3px 12px;
  border-radius: 5px 6px 5px 6px;
  background: var(--paper-grain), rgba(243, 230, 206, 0.94);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: var(--cut), 1px 2px 0 var(--edge), var(--contact);
  pointer-events: auto;
}

.tray-close {
  position: relative;
  pointer-events: auto;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--paper-grain), var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--cut), 1px 2px 0 var(--edge), var(--contact), var(--cast);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

/* Keep a generous >=48px touch target while staying visually compact */
.tray-close::before {
  content: "";
  position: absolute;
  inset: -6px;
}

.tray-close:hover {
  transform: translateY(-2px);
}

.tray-close:active {
  transform: translate(1px, 2px);
  box-shadow: var(--cut), 0 0 0 var(--edge), 1px 1px 1px rgba(74, 44, 34, 0.4);
}

.cards-track {
  pointer-events: auto;
  touch-action: pan-x;
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  padding: 14px calc(50% - 82px) 18px;
  cursor: grab;
  -webkit-overflow-scrolling: touch;
}

.cards-track::-webkit-scrollbar {
  display: none;
}

.cards-track.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
  scroll-behavior: auto;
}

.cards-track.is-single {
  justify-content: center;
  overflow-x: hidden;
  padding: 14px 24px 18px;
  cursor: default;
}

/* Playing-card style book cover */
.book-card {
  position: relative;
  flex: 0 0 auto;
  width: 158px;
  height: 212px;
  margin-inline: -10px;
  padding: 14px 13px 12px 19px;
  border: 0;
  border-radius: 6px 10px 9px 6px;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: center;
  color: var(--core);
  cursor: pointer;
  background:
    var(--paper-grain),
    linear-gradient(155deg, var(--card-light, #8aa790) 0%, var(--card-color, #64866d) 54%, var(--card-dark, #4b6752) 100%);
  box-shadow:
    inset 1px 1px 0 rgba(251, 246, 234, 0.55),
    inset -2px -2px 0 rgba(48, 28, 16, 0.28),
    3px 0 0 #efe2c8,
    4px 0 0 #c6b08a,
    0 3px 0 #e6d5b4,
    0 4px 0 #baa27b,
    5px 10px 18px rgba(58, 34, 18, 0.28);
  transform: translateY(var(--fan-y, 0px)) rotate(var(--fan-rot, 0deg)) scale(var(--fan-scale, 1));
  transform-origin: 50% 85%;
  transition: box-shadow 0.2s ease, filter 0.2s ease;
  will-change: transform;
}

.cards-track.is-single .book-card {
  margin-inline: 0;
  width: 176px;
  height: 228px;
}

/* Book spine crease */
.book-card::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 10px;
  width: 2px;
  background: linear-gradient(to right, rgba(44, 24, 12, 0.34), rgba(251, 246, 234, 0.34));
  border-radius: 1px;
  pointer-events: none;
}

/* Printed inner gold border frame */
.book-card::after {
  content: "";
  position: absolute;
  inset: 9px 9px 9px 16px;
  border: 1.5px solid rgba(251, 246, 234, 0.52);
  border-radius: 3px 5px 5px 3px;
  pointer-events: none;
}

.book-card:hover {
  filter: brightness(1.05);
}

.book-card.is-center {
  box-shadow:
    inset 1px 1px 0 rgba(251, 246, 234, 0.72),
    inset -2px -2px 0 rgba(48, 28, 16, 0.28),
    3px 0 0 #f4e8d1,
    4px 0 0 #c6b08a,
    0 3px 0 #ebd9b8,
    0 4px 0 #baa27b,
    0 0 0 2px rgba(251, 246, 234, 0.75),
    7px 14px 24px rgba(58, 34, 18, 0.34);
}

.book-card-emblem {
  width: 78px;
  height: 78px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(251, 246, 234, 0.2);
  border: 1.5px solid rgba(251, 246, 234, 0.52);
  box-shadow: inset 0 1px 2px rgba(251, 246, 234, 0.35), 0 2px 6px rgba(58, 34, 18, 0.16);
  color: var(--core);
  flex: 0 0 auto;
}

.book-card-emblem svg {
  width: 68%;
  height: 68%;
  display: block;
}

.cards-track.is-single .book-card-emblem {
  width: 88px;
  height: 88px;
}

.book-card-title {
  margin: auto 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: 0.03em;
  color: var(--core);
  text-shadow: 0 1px 2px rgba(42, 22, 10, 0.42);
  word-break: keep-all;
  overflow-wrap: break-word;
}

.book-card-title.is-long {
  font-size: 16px;
  line-height: 1.24;
}

.book-card-num {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: rgba(251, 246, 234, 0.8);
}

/* 3D book opening transition overlay */
.book-open-stage {
  position: fixed;
  inset: 0;
  z-index: 60;
  perspective: 1400px;
  pointer-events: auto;
  background: rgba(244, 237, 224, 0);
  transition: background-color 0.45s ease;
}

.book-open-stage[hidden] {
  display: none;
}

.book-open-stage.is-veiling {
  background: rgba(244, 237, 224, 0.94);
}

.opening-book {
  position: fixed;
  transform-style: preserve-3d;
  will-change: transform;
}

.opening-pages {
  position: absolute;
  inset: 0;
  border-radius: 6px 10px 9px 6px;
  background:
    var(--paper-grain),
    linear-gradient(90deg, #dfd0b3 0%, #f5ebd7 8%, #f8f0df 100%);
  box-shadow:
    inset 0 0 0 1px rgba(122, 92, 60, 0.35),
    4px 12px 28px rgba(58, 34, 18, 0.28);
}

.opening-pages::after {
  content: "";
  position: absolute;
  inset: 14px 14px 14px 18px;
  border: 1px solid rgba(140, 106, 70, 0.28);
  border-radius: 3px;
}

.opening-cover-wrap {
  position: absolute;
  inset: 0;
  transform-origin: 0% 50%;
  transform-style: preserve-3d;
  will-change: transform;
}

.opening-cover-front {
  position: absolute;
  inset: 0;
  margin: 0 !important;
  width: 100% !important;
  height: 100% !important;
  transform: none !important;
  backface-visibility: hidden;
}

.opening-cover-back {
  position: absolute;
  inset: 0;
  border-radius: 10px 6px 6px 9px;
  background: var(--paper-grain), #efe0c2;
  box-shadow: inset 0 0 0 1px rgba(122, 92, 60, 0.32);
  transform: rotateY(180deg);
  backface-visibility: hidden;
}

/* Noscript fallback */
.noscript-wrap {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--desk);
}

.noscript-card {
  max-width: 380px;
  padding: 24px 28px;
  border-radius: 6px 8px 7px 6px;
  background: var(--paper);
  text-align: center;
  box-shadow: var(--cut), 2px 3px 0 var(--edge), var(--cast);
}

.noscript-link {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 20px;
  border-radius: 5px;
  background: var(--accent);
  color: var(--core);
  text-decoration: none;
  font-weight: 700;
}

/* Responsive: compact portrait phones */
@media (max-width: 600px) {
  .landmark-label {
    font-size: 18px;
    padding: 4px 10px 4px 8px;
    border-left-width: 4px;
  }

  .landmark-label.is-selected {
    font-size: 20px;
    padding: 6px 13px 6px 10px;
  }

  .cards-tray {
    padding: 4px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .tray-bar {
    gap: 8px;
    padding: 0 12px;
    margin-bottom: -4px;
  }

  .tray-title {
    font-size: 14px;
    padding: 2px 10px;
  }

  .tray-close {
    width: 34px;
    height: 34px;
    font-size: 22px;
  }

  .tray-close::before {
    inset: -7px;
  }

  .book-card {
    width: 142px;
    height: 190px;
    margin-inline: -8px;
    padding: 11px 11px 10px 17px;
    gap: 4px;
  }

  .cards-track.is-single .book-card {
    width: 162px;
    height: 206px;
  }

  .book-card-emblem {
    width: 68px;
    height: 68px;
  }

  .cards-track.is-single .book-card-emblem {
    width: 78px;
    height: 78px;
  }

  .cards-track {
    padding: 10px calc(50% - 71px) 12px;
  }

  .cards-track.is-single {
    padding: 10px 20px 12px;
  }

  .book-card-title {
    font-size: 17px;
    line-height: 1.26;
  }

  .book-card-title.is-long {
    font-size: 15px;
    line-height: 1.22;
  }

  .book-card-num {
    font-size: 11px;
  }
}

/* Responsive: short landscape phones place the book tray on the right */
@media (orientation: landscape) and (max-height: 540px) {
  .cards-tray {
    top: calc(58px + env(safe-area-inset-top, 0px));
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: auto;
    right: calc(8px + env(safe-area-inset-right, 0px));
    width: min(50vw, 420px);
    justify-content: center;
    padding: 6px 0;
    border-radius: 10px;
    background: linear-gradient(to left, rgba(235, 222, 198, 0.94) 0%, rgba(244, 237, 224, 0.78) 80%, rgba(244, 237, 224, 0) 100%);
  }

  .cards-tray.is-entering {
    transform: translateX(36px);
  }

  .book-card {
    width: 136px;
    height: 176px;
    margin-inline: -8px;
    padding: 10px 10px 9px 16px;
  }

  .book-card-emblem {
    width: 60px;
    height: 60px;
  }

  .cards-track {
    padding: 10px calc(50% - 68px) 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage-wrap,
  .cards-tray,
  .bottom-hint,
  .book-open-stage,
  .sound-btn,
  .tray-close,
  .list-link,
  .landmark-label,
  .book-card {
    transition-duration: 0.08s !important;
  }

  .cards-tray.is-bouncing {
    animation: none;
  }
}
