@font-face {
  font-family: 'GenWanMinJP';
  src: url('../fonts/GenWanMinJP-Light-2.woff2') format('woff2');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'GenWanMinJP';
  src: url('../fonts/GenWanMinJP-Regular-4.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'GenWanMinJP';
  src: url('../fonts/GenWanMinJP-Medium-3.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'GenWanMinJP';
  src: url('../fonts/GenWanMinJP-SemiBold-5.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SourceSansVariable';
  src: url('../fonts/SourceSansVariable-Roman.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'SourceSansVariable';
  src: url('../fonts/SourceSansVariable-Italic.woff2') format('woff2');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

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

:root {
  --paper:   #ffffff;
  --ink:     #3B2E21;
  --bronze:  #8B6A3F;
  --bronze-glow: #8B6A3F55;
  --locked-wash: rgba(244, 239, 229, 0.55);
  --serif-en: 'SourceSansVariable', sans-serif;
  --serif-zh: 'GenWanMinJP', serif;
  --sans:    'SourceSansVariable', sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screens ── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }
.screen.fade-out { animation: fadeOut 0.5s ease forwards; }

@keyframes fadeOut { to { opacity: 0; } }

/* ── Title Screen ── */
#title-screen {
  align-items: center;
  justify-content: center;
  background: var(--paper);
  background-image:
    radial-gradient(ellipse at 30% 70%, rgba(139,106,63,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 30%, rgba(139,106,63,0.04) 0%, transparent 60%);
}

.title-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#game-title {
  font-family: var(--serif-zh);
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--ink);
}

#game-subtitle {
  font-family: var(--serif-en);
  font-size: clamp(0.85rem, 2vw, 1.05rem);
  font-style: italic;
  color: var(--bronze);
  letter-spacing: 0.06em;
}

.title-start-btns {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}
.title-start-btns .btn-primary {
  margin-top: 0;
}
.title-sound-hint {
  margin-top: 24px;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--ink);
  opacity: 0.5;
  text-align: center;
  line-height: 1.7;
}

.btn-primary {
  margin-top: 24px;
  padding: 10px 36px;
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 300ms, color 300ms;
}
.btn-primary:hover {
  background: var(--ink);
  color: var(--paper);
}

.lang-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--bronze);
  padding: 6px 10px;
  transition: opacity 200ms;
}
.lang-toggle:hover { opacity: 0.7; }

/* ── Top Bar ── */
#top-bar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(59,46,33,0.1);
}

#progress-dots {
  display: flex;
  gap: 10px;
  align-items: center;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--bronze);
  background: transparent;
  cursor: pointer;
  transition: background 400ms, transform 200ms;
}
.dot.solved { background: var(--bronze); }
.dot.active { transform: scale(1.3); }

.mute-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--ink);
  opacity: 0.6;
  width: 32px;
  text-align: center;
  padding: 4px;
}
.mute-btn.muted { opacity: 0.3; }

/* ── Canvas Area ── */
#canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#main-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(59,46,33,0.18);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.6rem;
  color: var(--ink);
  opacity: 0.85;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.14);
  transition: opacity 200ms, background 200ms, box-shadow 200ms;
  user-select: none;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.nav-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}
.nav-btn:active {
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
#prev-btn { left: 10px; }
#next-btn { right: 10px; }

/* ── Puzzle Screens ── */
.puzzle-screen {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
}
.puzzle-screen.active { display: flex; }

#screen-2,
#screen-4 { padding: 0 64px; }

.screen-bg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: sepia(20%);
}

.not-yet-overlay {
  position: absolute;
  inset: 0;
  background: var(--locked-wash);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(1px);
}
.not-yet-overlay.hidden { display: none; }

.not-yet-text {
  font-family: var(--serif-en);
  font-size: 1.2rem;
  font-style: italic;
  color: var(--bronze);
  letter-spacing: 0.1em;
  opacity: 0.7;
}

/* ── Inventory Bar ── */
#inventory-bar {
  height: 76px;
  flex-shrink: 0;
  border-top: 1px solid rgba(59,46,33,0.12);
  background: linear-gradient(180deg, rgba(244,239,229,0.6) 0%, var(--paper) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.inventory-empty {
  width: 56px;
  height: 56px;
  border: 1.5px dashed rgba(59,46,33,0.2);
  border-radius: 4px;
}

.inventory-has-item {
  display: flex;
  align-items: center;
  justify-content: center;
}

.inventory-img {
  max-width: 120px;
  max-height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(59,46,33,0.2));
  cursor: grab;
  transition: transform 200ms;
}
.inventory-img:hover { transform: scale(1.05); }

/* ── Poem Overlay ── */
#poem-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59,46,33,0.15);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 400ms ease;
  cursor: pointer;
}
#poem-overlay.hidden { display: none; }
#poem-overlay.visible { opacity: 1; }

.poem-panel {
  background: var(--paper);
  background-image:
    radial-gradient(ellipse at 50% 50%, rgba(139,106,63,0.04) 0%, transparent 80%);
  border: 1px solid rgba(59,46,33,0.15);
  max-width: 820px;
  width: 92%;
  padding: 40px 56px;
  cursor: default;
  position: relative;
  box-shadow: 0 8px 40px rgba(59,46,33,0.15);
}

.figure-name {
  font-family: var(--serif-en);
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  text-align: center;
}

.figure-meta {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--bronze);
  letter-spacing: 0.04em;
  margin-bottom: 24px;
  line-height: 1.5;
  text-align: center;
}

.poem-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--bronze), transparent);
  margin-bottom: 28px;
}

.poem-body { margin-bottom: 28px; text-align: center; }

.poem-line {
  font-family: var(--serif-zh);
  font-size: 1rem;
  line-height: 1.9;
  opacity: 0;
  transform: translateY(6px);
  animation: lineIn 400ms ease forwards;
  animation-delay: calc(300ms + var(--i) * 250ms);
}
.poem-line-zh { color: var(--ink); }
.poem-line-en {
  color: var(--bronze);
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 0.9rem;
  text-align: left;
  margin-bottom: 8px;
}

@keyframes lineIn {
  to { opacity: 1; transform: translateY(0); }
}

.btn-show-both {
  background: none;
  border: 1px solid rgba(139,106,63,0.4);
  color: var(--bronze);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  padding: 5px 12px;
  cursor: pointer;
  position: absolute;
  top: 40px;
  right: 48px;
  transition: background 200ms;
}
.btn-show-both:hover { background: rgba(139,106,63,0.08); }

.poem-continue {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(59,46,33,0.4);
  text-align: center;
  opacity: 0;
  transition: opacity 500ms;
}
.poem-continue.visible { opacity: 1; }

/* ── Stele Puzzle ── */
#stele-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#stele-wrapper {
  position: relative;
}

/* ── Responsive ── */
@media (max-width: 360px) {
  .poem-panel { padding: 24px 20px; }
  .btn-show-both { top: 24px; right: 20px; }
}

@media (max-width: 480px) {
  #top-bar { height: 40px; padding: 0 10px; }
  #inventory-bar { height: 66px; }
  .poem-panel { padding: 28px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .poem-line { animation: none; opacity: 1; transform: none; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
