:root {
  --paper: #efe8d4;
  --ink: #1f3029;
  --ink-soft: #52655b;
  --cinnabar: #a83a2d;
  --gold: #b99155;
  --glass: rgba(244, 239, 222, 0.78);
  --line: rgba(62, 73, 62, 0.26);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #ded7c2; color: var(--ink); }

body {
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  overflow: hidden;
}

button, a { font: inherit; }
button { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 620px;
  overflow: hidden;
  isolation: isolate;
  background: var(--paper);
}

.topbar {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid rgba(59, 72, 61, 0.15);
  background: linear-gradient(180deg, rgba(246, 241, 225, 0.96), rgba(246, 241, 225, 0.7));
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: baseline; gap: 12px; text-decoration: none; color: var(--ink); }
.brand strong { font-size: 22px; letter-spacing: 0.18em; font-weight: 600; }
.brand small { font-family: Georgia, serif; font-size: 10px; letter-spacing: 0.18em; color: var(--ink-soft); }
.top-hint { font-size: 13px; letter-spacing: 0.08em; color: #6a705f; }

.view {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transform: scale(1.015);
  transition: opacity 520ms ease, transform 780ms cubic-bezier(.2,.7,.1,1), visibility 0s linear 780ms;
}

.view.is-active {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  transition-delay: 0s;
}

.map-view {
  padding: 84px 38px 72px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255,255,255,.4), transparent 44%),
    #e9e2cc;
}

.map-frame {
  position: relative;
  width: min(1380px, 100%);
  height: 100%;
  margin: 0 auto;
  border: 1px solid rgba(91, 75, 48, 0.35);
  box-shadow: 0 22px 60px rgba(52, 47, 34, 0.16);
  background: #e9e2ce url("/assets/chinese/grade4a/poetry-map-v2/poetry-map-v2.webp") center/cover no-repeat;
  overflow: hidden;
}

.map-frame::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(116, 89, 50, 0.26);
  pointer-events: none;
}

.map-heading {
  position: absolute;
  z-index: 3;
  left: 4.5%;
  top: 5%;
  padding: 14px 18px 12px;
  background: rgba(243, 237, 218, 0.78);
  border-left: 3px solid var(--cinnabar);
  box-shadow: 0 10px 24px rgba(58, 50, 34, 0.08);
  backdrop-filter: blur(7px);
}

.map-heading h1 { margin: 0; font-size: clamp(24px, 2.35vw, 40px); letter-spacing: 0.15em; font-weight: 600; }
.map-heading p { margin: 6px 0 0; font-size: 12px; letter-spacing: 0.22em; color: var(--ink-soft); }

.marker {
  position: absolute;
  z-index: 8;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 4px 8px rgba(45, 39, 28, 0.28));
}

.marker-dot {
  position: relative;
  width: 19px;
  height: 19px;
  border: 4px solid #f6efdc;
  border-radius: 50%;
  background: var(--cinnabar);
  box-shadow: 0 0 0 1px rgba(89, 43, 31, 0.5);
  flex: 0 0 auto;
}

.marker-dot::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 1px solid rgba(168, 58, 45, 0.55);
  border-radius: 50%;
  animation: pulse 2.4s ease-out infinite;
}

.marker-label {
  padding: 7px 11px 6px;
  min-width: 86px;
  border: 1px solid rgba(76, 68, 49, 0.28);
  background: rgba(247, 242, 226, 0.92);
  font-size: 14px;
  letter-spacing: 0.12em;
  white-space: nowrap;
  transition: transform 180ms ease, background 180ms ease;
}

.marker:hover .marker-label, .marker:focus-visible .marker-label { transform: translateY(-3px); background: #fffaf0; }
.marker.is-other .marker-label { opacity: .76; }
.marker.is-complete .marker-label::after { content: " 朱印"; color: var(--cinnabar); font-size: 10px; }

.place-index {
  position: absolute;
  z-index: 5;
  top: 17%;
  right: 3.2%;
  width: 178px;
  padding: 18px 18px 14px;
  background: rgba(244, 238, 219, 0.84);
  border-left: 1px solid rgba(65, 74, 61, 0.28);
  backdrop-filter: blur(8px);
}

.place-index h2 { margin: 0 0 12px; font-size: 18px; letter-spacing: .16em; font-weight: 600; }
.place-index button {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 6px;
  padding: 7px 0;
  border: 0;
  border-bottom: 1px solid rgba(68, 78, 66, .12);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.place-index span:first-child { color: #9a8160; font-family: Georgia, serif; }
.place-index button:hover span:last-child { color: var(--cinnabar); }

.map-footnote {
  position: absolute;
  z-index: 4;
  bottom: 2.8%;
  left: 4.5%;
  padding: 7px 12px;
  background: rgba(246, 241, 224, 0.72);
  font-size: 11px;
  letter-spacing: .08em;
  color: #6b6e60;
}

.scene-view { background: #c8c1ac; }
.scene-bg { position: absolute; inset: 0; background-position: center; background-size: cover; transform: scale(1.025); transition: background-image 300ms ease; }
.scene-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(245,239,220,.34), transparent 26%, transparent 67%, rgba(25,34,29,.24));
}

.scene-meta {
  position: absolute;
  z-index: 4;
  top: 84px;
  left: 34px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.back-map {
  border: 1px solid rgba(55, 67, 58, 0.24);
  background: rgba(247, 242, 227, 0.86);
  padding: 10px 15px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(45, 41, 32, 0.08);
}
.scene-place strong { display: block; font-size: 28px; letter-spacing: .16em; font-weight: 500; }
.scene-place span { display: block; margin-top: 3px; font-size: 12px; letter-spacing: .16em; color: #5b685f; }

.poem-stage {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 49%;
  width: min(760px, 60vw);
  min-height: 540px;
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: center;
  padding: 28px 40px 18px;
  user-select: none;
}
.poem-stage.has-backdrop { background: rgba(243, 238, 221, .52); box-shadow: 0 18px 60px rgba(55,48,34,.08); backdrop-filter: blur(5px); }

.poem-heading { text-align: center; text-shadow: 0 2px 16px rgba(248,245,227,.85); }
.poem-heading h1 { margin: 0; font-size: clamp(30px, 3.2vw, 48px); letter-spacing: .18em; font-weight: 500; }
.poem-heading p { margin: 8px 0 14px; font-size: 15px; letter-spacing: .14em; }

.poem-lines {
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(22px, 3.4vw, 50px);
  padding: 16px 22px;
  min-height: 330px;
}

.poem-line {
  position: relative;
  width: clamp(40px, 4.2vw, 62px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 25px;
  touch-action: none;
  cursor: grab;
  transform-origin: 50% 12px;
  filter: drop-shadow(0 2px 9px rgba(246, 241, 222, .82));
}
.poem-line:active, .poem-line.is-dragging { cursor: grabbing; }
.string-thread {
  position: absolute;
  z-index: -1;
  top: 6px;
  left: 50%;
  width: 300px;
  overflow: visible;
  transform: translateX(-50%);
  pointer-events: none;
}
.string-thread path {
  fill: none;
  stroke: rgba(71, 80, 69, .34);
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.string-cap {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 9px;
  height: 9px;
  transform: translateX(-50%);
  border: 1px solid rgba(92, 69, 45, .5);
  border-radius: 50%;
  background: rgba(244, 234, 207, .92);
  box-shadow: 0 0 0 3px rgba(244, 238, 218, .38);
}
.bead-char {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.15em;
  height: 1.08em;
  font-size: clamp(28px, 3.1vw, 50px);
  line-height: 1;
  color: #24352e;
  text-shadow: 0 1px 0 rgba(255,255,255,.8), 0 2px 16px rgba(250,245,225,.95);
  will-change: transform;
  transition: color 220ms ease, text-shadow 220ms ease;
}
.bead-char::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(76, 87, 75, .26);
  transform: translateX(-50%);
}
.poem-line.is-lit .bead-char { color: #963b2d; text-shadow: 0 0 18px rgba(250, 238, 201, 1); }
.poem-line.is-dragging .string-cap { background: var(--cinnabar); border-color: #7d2c24; }

.author-card {
  position: absolute;
  z-index: 6;
  top: 17%;
  right: 3%;
  width: min(300px, 23vw);
  padding: 22px 22px 20px;
  background: var(--glass);
  border: 1px solid rgba(77, 72, 55, .2);
  border-radius: 24px 24px 8px 24px;
  box-shadow: 0 22px 50px rgba(44, 40, 31, .16);
  backdrop-filter: blur(12px);
}
.author-art {
  height: 146px;
  display: grid;
  place-items: center;
  margin: -8px -4px 14px;
  background: radial-gradient(circle at 50% 70%, rgba(105,125,109,.24), transparent 46%), linear-gradient(180deg, transparent, rgba(255,255,255,.3));
  border-bottom: 1px solid var(--line);
}
.author-art span {
  display: grid;
  place-items: center;
  width: 94px;
  height: 116px;
  border: 1px solid rgba(58,71,61,.22);
  border-radius: 48% 48% 40% 40%;
  font-size: 42px;
  letter-spacing: .08em;
  color: rgba(39,57,47,.72);
  background: rgba(237,233,217,.48);
}
.author-name { display: flex; align-items: baseline; gap: 10px; }
.author-name strong { font-size: 25px; letter-spacing: .12em; font-weight: 600; }
.author-name small { color: var(--cinnabar); }
.author-years { margin: 5px 0 12px; color: #667067; font-size: 12px; }
.author-card p { margin: 0; font-size: 14px; line-height: 1.9; }

.scene-controls {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 22px;
  width: min(860px, calc(100vw - 80px));
  transform: translateX(-50%);
  padding: 12px 16px 10px;
  background: rgba(239, 233, 214, .86);
  border: 1px solid rgba(72, 70, 55, .22);
  box-shadow: 0 15px 42px rgba(38, 36, 29, .18);
  backdrop-filter: blur(13px);
}
.control-row { display: grid; grid-template-columns: auto auto 1fr auto; gap: 12px; align-items: center; }
.play-btn, .tool-btn, .challenge-btn {
  border: 1px solid rgba(79, 72, 53, .2);
  background: rgba(252, 247, 233, .86);
  padding: 9px 14px;
  cursor: pointer;
}
.play-btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; background: var(--cinnabar); color: white; border: 0; font-size: 17px; }
.progress { position: relative; height: 5px; background: rgba(60,69,59,.22); overflow: hidden; }
.progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--cinnabar); transition: width 180ms linear; }
.time { font-family: Georgia, serif; font-size: 12px; color: #66685d; }
.tool-row { display: flex; justify-content: center; gap: 8px; margin-top: 9px; }
.tool-btn, .challenge-btn { padding: 6px 10px; font-size: 12px; }
.tool-btn.is-on { color: var(--cinnabar); border-color: rgba(168,58,45,.5); }
.challenge-btn { background: #2d493d; color: #f8f2df; border-color: transparent; }

.challenge-panel {
  position: absolute;
  z-index: 30;
  inset: auto 0 0;
  min-height: 310px;
  padding: 24px max(24px, calc((100vw - 1080px)/2));
  background: rgba(241, 235, 216, .97);
  border-top: 1px solid rgba(70, 67, 53, .24);
  box-shadow: 0 -18px 60px rgba(35, 34, 27, .22);
  transform: translateY(105%);
  transition: transform 420ms cubic-bezier(.2,.75,.15,1);
}
.challenge-panel.is-open { transform: translateY(0); }
.challenge-head { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.challenge-head h2 { margin: 0; font-size: 24px; letter-spacing: .12em; }
.close-challenge { border: 0; background: transparent; font-size: 26px; cursor: pointer; }
.challenge-grid { display: grid; grid-template-columns: 1fr 1.35fr .72fr; gap: 22px; margin-top: 18px; }
.challenge-card { padding: 17px; background: rgba(255,252,241,.82); border: 1px solid rgba(76,75,59,.16); }
.challenge-card h3 { margin: 0 0 10px; font-size: 16px; }
.clue-list, .answer-list { display: flex; flex-wrap: wrap; gap: 8px; }
.clue, .answer {
  border: 1px solid rgba(78,76,60,.25);
  background: transparent;
  padding: 8px 11px;
  cursor: pointer;
}
.clue.is-found { background: #dce4d8; color: #31503d; }
.answer.is-correct { background: #d8e4d7; }
.answer.is-wrong { background: #edd8d2; }
.challenge-feedback { min-height: 24px; margin: 10px 0 0; color: #6b4d3c; font-size: 13px; }
.seal-box { display: grid; place-items: center; text-align: center; }
.seal {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border: 4px double #a9a28f;
  color: #9b9585;
  font-size: 18px;
  line-height: 1.25;
  transform: rotate(-5deg);
}
.seal.is-unlocked { color: var(--cinnabar); border-color: var(--cinnabar); animation: stamp .42s cubic-bezier(.2,1.6,.3,1); }

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  top: 82px;
  transform: translate(-50%, -16px);
  padding: 10px 18px;
  background: rgba(36, 51, 43, .92);
  color: #fff9e9;
  border-radius: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-showing { opacity: 1; transform: translate(-50%, 0); }

@keyframes pulse { from { opacity: .8; transform: scale(.55); } to { opacity: 0; transform: scale(1.45); } }
@keyframes stamp { from { opacity: 0; transform: rotate(-5deg) scale(1.8); } to { opacity: 1; transform: rotate(-5deg) scale(1); } }

@media (max-width: 980px) {
  .top-hint { display: none; }
  .map-view { padding: 74px 12px 64px; }
  .map-frame { background-size: cover; background-position: 43% center; }
  .place-index { right: 2%; width: 156px; padding: 12px; }
  .poem-stage { left: 42%; width: 68vw; }
  .author-card { right: 2%; width: 26vw; padding: 15px; }
  .author-card p { font-size: 12px; }
  .author-art { height: 105px; }
}

@media (max-width: 700px) {
  body { overflow: hidden; }
  .app-shell { min-height: 600px; }
  .topbar { height: 54px; padding: 0 14px; }
  .brand strong { font-size: 18px; }
  .brand small { display: none; }
  .map-view { padding: 62px 0 58px; }
  .map-frame { border-inline: 0; background-size: auto 72%; background-position: 43% 24%; background-repeat: no-repeat; background-color: #e9e2ce; box-shadow: none; }
  .map-heading { left: 16px; top: 16px; padding: 10px 12px 9px; }
  .map-heading h1 { font-size: 22px; }
  .map-heading p { font-size: 9px; }
  .marker-label { min-width: 0; padding: 5px 7px; font-size: 11px; }
  .marker-dot { width: 14px; height: 14px; border-width: 3px; }
  .place-index {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 172px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
    padding: 14px 18px;
    border-left: 0;
    border-top: 1px solid rgba(65,74,61,.2);
  }
  .place-index h2 { grid-column: 1/-1; margin: 0; font-size: 15px; }
  .place-index button { padding: 4px 0; font-size: 11px; }
  .map-footnote { display: none; }

  .scene-meta { top: 66px; left: 12px; gap: 10px; }
  .back-map { padding: 8px 10px; font-size: 12px; }
  .scene-place strong { font-size: 18px; }
  .scene-place span { font-size: 9px; }
  .scene-bg { background-position: 47% center; }
  .poem-stage { left: 48%; top: 44%; width: 94vw; min-height: 420px; padding: 20px 10px 8px; }
  .poem-heading h1 { font-size: 27px; }
  .poem-heading p { margin-bottom: 8px; font-size: 12px; }
  .poem-lines { gap: 18px; padding: 8px; }
  .poem-lines { min-height: 285px; }
  .poem-line { width: clamp(34px, 10vw, 44px); gap: 3px; }
  .bead-char { font-size: clamp(25px, 7.6vw, 34px); }
  .author-card { top: auto; right: 10px; bottom: 152px; width: 158px; padding: 11px; border-radius: 16px 16px 5px 16px; }
  .author-art, .author-card p, .author-years { display: none; }
  .author-name strong { font-size: 17px; }
  .scene-controls { bottom: 10px; width: calc(100vw - 20px); padding: 9px; }
  .control-row { grid-template-columns: auto auto 1fr auto; gap: 7px; }
  .play-btn { width: 38px; height: 38px; }
  .tool-row { justify-content: center; flex-wrap: wrap; gap: 6px; white-space: normal; }
  .tool-row .tool-btn, .tool-row .challenge-btn { padding: 7px 10px; font-size: 11px; }
  .challenge-grid { grid-template-columns: 1fr; gap: 10px; }
  .challenge-panel { max-height: 72vh; overflow-y: auto; padding: 18px 14px 24px; }
  .seal-box { min-height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
