:root {
  --bg: #ece1d0;
  --bg-soft: rgba(255, 255, 255, 0.45);
  --panel: rgba(245, 236, 224, 0.82);
  --panel-strong: rgba(41, 28, 20, 0.82);
  --text: #25170f;
  --muted: #6e5d52;
  --line: rgba(61, 42, 30, 0.16);
  --accent: #9f5a36;
  --accent-soft: rgba(159, 90, 54, 0.15);
  --shadow: 0 20px 60px rgba(58, 39, 28, 0.14);
  --radius: 28px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-body: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.6), transparent 30%),
    linear-gradient(180deg, #f4ebdc 0%, #e6d6bf 42%, #d3b494 100%);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
  padding: 0 1.25rem;
}

body.mode-study {
  --bg: #eadac3;
  --panel: rgba(251, 244, 235, 0.74);
  --panel-strong: rgba(54, 38, 28, 0.82);
  --accent: #a25932;
}

body.mode-garden {
  --bg: #e2e7d6;
  --panel: rgba(245, 249, 239, 0.72);
  --panel-strong: rgba(39, 56, 42, 0.8);
  --text: #1d2a1f;
  --muted: #5b6a5d;
  --line: rgba(44, 72, 49, 0.16);
  --accent: #4a7f62;
  --accent-soft: rgba(74, 127, 98, 0.16);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.62), transparent 32%),
    linear-gradient(180deg, #f1f5ea 0%, #dce6cf 45%, #c5d5b6 100%);
}

body.mode-atlas {
  --bg: #e8e5dd;
  --panel: rgba(247, 246, 241, 0.78);
  --panel-strong: rgba(32, 38, 49, 0.82);
  --text: #1f2430;
  --muted: #606776;
  --line: rgba(57, 66, 85, 0.16);
  --accent: #355a91;
  --accent-soft: rgba(53, 90, 145, 0.14);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 33%),
    linear-gradient(180deg, #f5f4ef 0%, #e4e1d5 52%, #d0ccbf 100%);
}

.ambient {
  position: fixed;
  inset: auto;
  border-radius: 999px;
  filter: blur(18px);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
  animation: drift 14s ease-in-out infinite;
}

.ambient-a {
  top: 8vh;
  right: -6rem;
  width: 20rem;
  height: 20rem;
  background: rgba(255, 220, 184, 0.55);
}

.ambient-b {
  bottom: 10vh;
  left: -5rem;
  width: 18rem;
  height: 18rem;
  background: rgba(164, 213, 185, 0.4);
  animation-delay: -5s;
}

@keyframes drift {
  0%, 100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, -14px, 0) scale(1.06);
  }
}

.chooser-page {
  display: flex;
  justify-content: center;
  padding: 4rem 1.25rem 5rem;
}

.chooser-shell,
.app-shell {
  position: relative;
  z-index: 1;
  width: min(1200px, 100%);
  margin: 0 auto;
}

/* Room Tabs */
.room-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  padding-top: 2rem;
}

.room-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: transparent;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.room-tab:hover {
  background: var(--bg-soft);
  border-color: var(--accent);
  color: var(--text);
}

.room-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.room-tab .tab-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.room-tab .tab-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.room-tab .tab-years {
  font-size: 0.75rem;
  opacity: 0.7;
  font-weight: 400;
}


.chooser-hero,
.hero {
  display: grid;
  gap: 1.5rem;
}

.chooser-hero {
  margin-bottom: 2.2rem;
}

.eyebrow,
.prototype-tag,
.drawer-category,
.panel-title {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 0.98;
  margin: 0;
}

h1 {
  font-size: clamp(2.8rem, 7vw, 5.6rem);
  max-width: 12ch;
}

h2 {
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.chooser-copy,
.hero-text,
.panel-copy,
.prototype-card p,
.prototype-points,
.drawer-note {
  color: var(--muted);
  line-height: 1.6;
}

.room-link {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.room-link a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  transition: opacity 0.2s ease;
}

.room-link a:hover {
  opacity: 0.7;
}

.room-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  align-items: start;
}

.room-hero.has-shelf {
  grid-template-columns: 1fr 1fr;
}

.hero-shelf {
  display: none;
}

.room-hero.has-shelf .hero-shelf {
  display: block;
}

.room-shelf-section {
  margin: 2rem 0;
}

.shelf-figure {
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-soft);
  box-shadow: var(--shadow);
  max-width: 800px;
  margin: 0 auto;
}

.shelf-figure img {
  width: 100%;
  height: auto;
  display: block;
  max-height: 400px;
  object-fit: cover;
}

.shelf-figure figcaption {
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  background: rgba(255, 255, 255, 0.5);
}

@media (max-width: 768px) {
  .room-hero.has-shelf {
    grid-template-columns: 1fr;
  }
}

.room-controls .search-wrap {
  display: none;
}

.prototype-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.2rem;
}

.prototype-card,
.hero-panel,
.controls,
.detail-drawer {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.prototype-card {
  padding: 1.4rem;
  border-radius: var(--radius);
  min-height: 24rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.study-card {
  background:
    linear-gradient(180deg, rgba(255, 248, 241, 0.82), rgba(237, 217, 196, 0.82)),
    var(--panel);
}

.garden-card {
  background:
    linear-gradient(180deg, rgba(248, 255, 246, 0.84), rgba(225, 240, 225, 0.84)),
    var(--panel);
}

.atlas-card {
  background:
    linear-gradient(180deg, rgba(250, 250, 248, 0.84), rgba(226, 228, 233, 0.84)),
    var(--panel);
}

.prototype-points {
  padding-left: 1rem;
  margin: 1rem 0;
}

.prototype-link,
.back-link,
.surprise-button,
.chip,
.drawer-close {
  appearance: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  font: inherit;
}

.prototype-link,
.surprise-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 2.8rem;
  padding: 0 1rem;
  border-radius: 999px;
  background: var(--panel-strong);
  color: #fff8f2;
}

.back-link {
  color: var(--muted);
}

.hero {
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.9fr);
  align-items: end;
  padding: 3rem 0 1.2rem;
}

.hero-panel,
.controls {
  border-radius: 24px;
}

.hero-panel {
  padding: 1.25rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.stat-pill,
.chip {
  padding: 0.65rem 0.92rem;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.controls {
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.search-wrap {
  display: none !important;
}

.room-controls {
  display: none !important;
}

.room-controls .chip-row {
  display: none !important;
}

.search-wrap input {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.64);
  padding: 0.95rem 1rem;
  font: inherit;
  color: var(--text);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip {
  background: transparent;
}

.chip.active {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.results-bar {
  padding: 1rem 0 0.4rem;
  color: var(--muted);
}

.era-shell {
  padding-bottom: 4rem;
}

.era-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.9fr);
  gap: 1.25rem;
  align-items: end;
  padding: 3rem 0 1rem;
}

.era-note,
.memory-card,
.era-room {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 26px;
}

.era-note {
  padding: 1rem 1.1rem;
}

.era-layout {
  display: grid;
  gap: 1.2rem;
}

.entry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
  align-items: start;
}

.era-room {
  padding: 1.2rem;
}

.era-room.current-room {
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.44), rgba(219, 184, 147, 0.1)),
    var(--panel);
}

.era-room.archive-room,
.memory-card.secondary {
  background:
    linear-gradient(180deg, rgba(245, 239, 229, 0.58), rgba(162, 135, 102, 0.1)),
    var(--panel);
}

.era-room-head,
.origin-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.era-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  padding: 0.2rem 0.4rem;
}

.divider-line {
  height: 1px;
  flex: 1;
  background: var(--line);
}

.divider-copy {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
}

.era-books-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 0.85rem;
}

.era-books-row.compact {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.era-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.38);
}

.era-cover {
  aspect-ratio: 0.72;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.4), rgba(0, 0, 0, 0.06));
}

.era-cover img,
.era-cover .placeholder-cover {
  width: 100%;
  height: 100%;
}

.era-card-body {
  padding: 0.75rem;
}

.era-card-meta {
  margin-top: 0.38rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.memory-card {
  padding: 1.25rem;
}

.era-bridge {
  display: block;
}

.entry-door {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 1.5rem;
  border-radius: 28px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--panel);
  position: relative;
  overflow: hidden;
  min-height: 400px;
  text-decoration: none;
  color: inherit;
  transition: transform 200ms ease, box-shadow 200ms ease;
  cursor: pointer;
}

.entry-door:hover {
  transform: translateY(-4px);
  box-shadow: 0 24px 72px rgba(58, 39, 28, 0.18);
}

.entry-door:active {
  transform: translateY(-2px);
}

.entry-door::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
}

.entry-door > * {
  position: relative;
  z-index: 1;
}

.door-icon {
  font-size: 4rem;
  text-align: center;
  margin-top: auto;
  padding: 1rem;
  opacity: 0.7;
}

.door-image {
  margin-top: auto;
  text-align: center;
  padding: 2rem 1rem;
}

.door-image img {
  max-width: 200px;
  max-height: 200px;
  object-fit: contain;
}

.room-title-with-icon {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.room-icon-container {
  flex-shrink: 0;
}

.room-icon-container img {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
}

.archive-door {
  background:
    linear-gradient(180deg, rgba(245, 239, 229, 0.58), rgba(162, 135, 102, 0.1)),
    var(--panel);
}

.study-door {
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.44), rgba(219, 184, 147, 0.1)),
    var(--panel);
}

.room-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.15;
}

.room-shell {
  padding-bottom: 4rem;
}

.room-controls {
  grid-template-columns: 1fr;
}

.room-book-grid {
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}

.theme-book-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.all-book-grid {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.library-view {
  display: grid;
  gap: 1.25rem;
  padding-bottom: 5rem;
}

.shelf-section {
  position: relative;
  padding: 1.05rem 1.05rem 1.25rem;
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.36);
  border: 1px solid var(--line);
}

.mode-study .shelf-section {
  background:
    linear-gradient(180deg, rgba(255, 248, 239, 0.42), rgba(219, 184, 147, 0.12)),
    rgba(255, 252, 247, 0.36);
}

.mode-atlas .shelf-section {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(190, 199, 216, 0.08)),
    rgba(255, 252, 247, 0.36);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 0.9rem;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.section-note {
  color: var(--muted);
  max-width: 58ch;
}

.book-grid {
  display: grid;
  gap: 0.8rem;
}

.mode-study .book-grid {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.mode-garden .book-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.mode-atlas .book-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.book-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 16px 40px rgba(43, 35, 28, 0.08);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.mode-study .book-card {
  border-radius: 16px;
}

.mode-study .book-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  background: linear-gradient(90deg, #8d5d33, #c7925f, #7b4c28);
  opacity: 0.8;
}

.book-card:hover {
  transform: translateY(-5px) rotate(-0.4deg);
  box-shadow: 0 26px 52px rgba(43, 35, 28, 0.14);
  border-color: rgba(255, 255, 255, 0);
}

.book-button {
  display: grid;
  gap: 0.65rem;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.cover-wrap {
  aspect-ratio: 0.72;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.45), rgba(0, 0, 0, 0.08));
  overflow: hidden;
}

.mode-study .cover-wrap {
  aspect-ratio: 0.62;
}

.cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.placeholder-cover {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: end start;
  padding: 0.85rem;
  color: white;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.14)),
    linear-gradient(135deg, #8b6545, #496b77);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.placeholder-cover-chinese {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.02em;
  padding: 1rem;
  place-items: center center;
  text-align: center;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.12)),
    linear-gradient(135deg, #9f5a36, #5d7d8a);
}

.book-meta {
  padding: 0 0.8rem 0.85rem;
}

.book-title {
  font-weight: 600;
  line-height: 1.3;
}

.detail-drawer {
  position: fixed;
  top: 1rem;
  right: 1rem;
  bottom: 1rem;
  width: min(420px, calc(100vw - 2rem));
  padding: 1rem;
  transform: translateX(calc(100% + 1rem));
  transition: transform 220ms ease;
  z-index: 3;
}

.detail-drawer.open {
  transform: translateX(0);
}

.drawer-close {
  display: inline-flex;
  margin-left: auto;
  background: transparent;
  color: var(--muted);
}

.drawer-cover {
  aspect-ratio: 0.72;
  border-radius: 22px;
  overflow: hidden;
  margin-top: 0.75rem;
  background: rgba(255, 255, 255, 0.48);
}

.drawer-cover img,
.drawer-cover .placeholder-cover {
  width: 100%;
  height: 100%;
}

.drawer-body {
  padding-top: 1rem;
}

@media (max-width: 980px) {
  .prototype-grid,
  .hero,
  .era-hero {
    grid-template-columns: 1fr;
  }

  .entry-grid {
    grid-template-columns: 1fr;
  }

  .entry-door {
    min-height: 400px;
  }
}

@media (max-width: 720px) {
  body {
    padding: 0 0.8rem;
  }

  .chooser-page {
    padding-inline: 0.8rem;
  }

  h1 {
    font-size: clamp(2.4rem, 10vw, 4rem);
  }

  .app-shell {
    padding-bottom: 2rem;
  }
}

/* Left-Right Layout for Two Rooms */
.library-layout {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 1.5rem;
  padding: 2rem 0 4rem;
  width: 100%;
}

.room {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.room-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
  margin: 0;
  padding: 0 1rem;
  color: var(--text);
}

.left-room {
  border-right: 2px solid var(--line);
  padding-right: 1.5rem;
}

.right-room {
  padding-left: 1.5rem;
}

.room .bookshelf-room {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.room .shelf-section {
  position: relative;
  padding: 1.05rem 1.05rem 1.25rem;
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.36);
  border: 1px solid var(--line);
}

.room .shelf-label {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.9rem 0;
  color: var(--text);
}

.room .shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.8rem;
}

@media (max-width: 980px) {
  .library-layout {
    grid-template-columns: 1fr;
  }

  .left-room {
    border-right: none;
    border-bottom: 2px solid var(--line);
    padding-right: 0;
    padding-bottom: 1rem;
  }

  .right-room {
    padding-left: 0;
    padding-top: 1rem;
  }
}

/* ============================================
   Keyboard Navigation & Focus Improvements
   ============================================ */

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  border-radius: 0 0 8px 0;
  text-decoration: none;
  font-weight: 600;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

/* Enhanced focus states for interactive elements */
.chip:focus-visible,
.book-button:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.drawer-close:focus-visible {
  outline: 3px solid white;
  outline-offset: 2px;
}

/* Improve button focus within cards */
.book-card:has(.book-button:focus-visible) {
  transform: translateY(-5px) rotate(-0.4deg);
  box-shadow: 0 0 0 3px var(--accent);
  border-color: transparent;
}

/* Active state improvements */
.chip:active {
  transform: scale(0.96);
}

.book-button:active .cover-wrap {
  transform: scale(0.98);
}

/* Hover improvements for better interactivity */
.prototype-link:hover,
.back-link:hover,
.surprise-button:hover {
  opacity: 0.85;
}

