:root {
  --paper: #fffaf0;
  --edge: #e2cfa6;
  --ink: #3f3226;
  --muted: #9a8466;
  --accent: #c0563a;
  --field: #fbf1da;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--field);
  overscroll-behavior: none;
}

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#overlay > * { pointer-events: auto; }

.notice {
  position: fixed;
  inset: auto 16px 40% 16px;
  margin: 0;
  padding: 16px;
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 14px;
}
/* One island did not load: a small note at the top; a tap puts it away. */
.notice.top { inset: 12px 16px auto 16px; padding: 10px 14px; font-size: 14px; cursor: pointer; }
/* Pull-to-refresh is off (dragging turns the view), so a notice reloads itself. */
.notice .reload {
  display: block;
  margin: 10px auto 0;
  padding: 8px 18px;
  font: inherit;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.notice.top .reload { display: inline-block; margin: 0 0 0 10px; padding: 4px 12px; }

.card {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-height: min(70vh, 640px);
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(90, 70, 40, 0.18);
}

/* Wide screens and landscape phones: the card sits at the side. */
@media (min-width: 720px), (orientation: landscape) and (min-width: 540px) {
  .card {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: min(380px, 46vw);
    max-height: calc(100vh - 32px);
  }
}

.card h2 { margin: 0 0 10px; font-size: 18px; }

.reader-text p { margin: 0 0 10px; line-height: 1.8; font-size: 16px; }
.reader-text .glyph { height: 1em; width: auto; margin: 0 0.06em; vertical-align: -0.12em; }

.source { margin: 4px 0 12px; font-size: 13px; color: var(--muted); }

.reader-video iframe {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 60vh;
  border: 0;
  border-radius: 10px;
  margin-bottom: 12px;
}

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.actions button, .actions a {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: #f7ecd2;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.actions .reader-play { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions .card-close { margin-left: auto; }

/* A reader opened from the 藏書閣: the way back, above its title. */
.card-back {
  font: inherit;
  font-size: 14px;
  padding: 4px 0;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
}

/* The 藏書閣: pill tabs that stay in view while the list scrolls under them. */
.library-tabs {
  position: sticky;
  top: -16px;
  z-index: 1;
  display: flex;
  gap: 8px;
  margin: 0 -18px 8px;
  padding: 10px 18px;
  overflow-x: auto;
  background: var(--paper);
  border-bottom: 1px solid var(--edge);
  scrollbar-width: none;
}
.library-tab {
  flex: none;
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: #f7ecd2;
  color: var(--ink);
  cursor: pointer;
}
.library-tab .count { margin-left: 6px; font-size: 12px; color: var(--muted); }
.library-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.library-tab[aria-selected="true"] .count { color: rgba(255, 255, 255, 0.85); }
.library-list { display: flex; flex-direction: column; margin-bottom: 12px; }
.library-note { margin: 0 0 8px; font-size: 13px; color: var(--accent); }
.library-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  width: 100%;
  padding: 10px 2px;
  font: inherit;
  text-align: left;
  border: none;
  border-bottom: 1px solid #efe2c4;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
.library-row:hover { background: #fbf2de; }
.library-row .row-title { font-size: 16px; }
.library-row .row-date { grid-column: 2; grid-row: 1; font-size: 12px; color: var(--muted); }
.library-row .row-line { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }

.bubble {
  position: relative;
  max-width: min(240px, 70vw);
  padding: 10px 14px;
  background: var(--paper);
  border: 1.5px solid var(--edge);
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(90, 70, 40, 0.16);
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  background: var(--paper);
  border-right: 1.5px solid var(--edge);
  border-bottom: 1.5px solid var(--edge);
  transform: rotate(45deg);
}

.bubble[hidden] { display: none; }
.bubble-text, .bubble-quote { display: block; }
.bubble-quote { margin-top: 6px; font-weight: 600; }

.panel-greeting { margin: 0 0 12px; font-size: 16px; line-height: 1.7; }

.label { margin: 12px 0 6px; font-size: 13px; color: var(--muted); }

.newest { padding: 10px 12px; background: #f7ecd2; border-radius: 10px; }
.newest p { margin: 0 0 6px; }
.newest-title { font-weight: 700; }
.newest-line { line-height: 1.7; }

.helper-line { margin: 0 0 8px; font-size: 16px; line-height: 1.7; }

#fps {
  position: fixed;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  font: 12px/1.6 ui-monospace, monospace;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.8);
  border-radius: 6px;
  pointer-events: none;
}

.top-buttons {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  display: flex;
  gap: 8px;
}
.menu-button, .reload-button {
  font: inherit;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(255, 250, 240, 0.92);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(90, 70, 40, 0.14);
  cursor: pointer;
}
.reload-button { padding: 8px 12px; line-height: 1; font-size: 17px; }

#menu .reset {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

#menu .intro-again {
  margin-top: 8px;
  background: transparent;
  color: var(--accent);
}

#menu .isles { display: grid; gap: 8px; margin-bottom: 12px; }

.intro-text { margin: 0 0 4px; font-size: 16px; line-height: 1.8; }

#xian-card .saying p { margin: 0; font-size: 16px; line-height: 1.8; }
#xian-card .newest-title { margin: 0 0 6px; font-weight: 600; }
#saying-card .helper-line p, #story-card .helper-line p { margin: 0; }
#saying-card .who { margin: 4px 0 0; text-align: right; color: var(--muted); }
.intro-step { margin-top: 0; }

#menu .island {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font: inherit;
  font-size: 15px;
  text-align: left;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: #f7ecd2;
  color: var(--ink);
  cursor: pointer;
}

#menu .island.here { background: #fffaf0; }
#menu .badge { font-size: 12px; color: var(--muted); }
#menu .badge.soon { color: var(--accent); }

.isle-label {
  padding: 2px 10px;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.8);
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: auto; /* a tap on it flies there */
  cursor: pointer;
}
