:root {
  --bg-sky: #6ec6ff;
  --bg-sky2: #c8e9ff;
  --ground: #5a8f3c;
  --ground2: #3d6b28;
  --gate: #8b5a2b;
  --gate-dark: #5c3a1a;
  --text: #1a1a1a;
  --ui: #fff;
  --accent: #ff6b3d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #0b1020;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  max-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #111;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.is-active { display: flex; }

/* —— 视频占位 —— */
#screen-video {
  background: #000;
  color: #fff;
  justify-content: center;
  align-items: center;
  padding: calc(16px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  text-align: center;
}
.video-box {
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 70dvh;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.2);
  background:
    linear-gradient(160deg, #1a2338, #0d121f);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 24px;
}
.video-box h1 { font-size: 1.2rem; font-weight: 800; }
.video-box p { color: rgba(255,255,255,.7); font-size: .9rem; line-height: 1.5; }
.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255,107,61,.35);
}
.btn--ghost {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.92);
  box-shadow: none;
  border: 1px solid rgba(255,255,255,.22);
}
.btn-row { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 18px; width: min(100%, 320px); }
.btn-row .btn { width: 100%; }

/* —— 地图通用 —— */
.map {
  position: relative;
  flex: 1;
  overflow: hidden;
}
.map-hud {
  position: absolute;
  z-index: 20;
  left: 12px;
  right: 12px;
  top: calc(10px + var(--safe-top));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.map-hud > * { pointer-events: auto; }
.map-hud__right {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
a.icon-btn--link {
  text-decoration: none;
  box-sizing: border-box;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.35);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.15;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.hint-toast {
  position: absolute;
  z-index: 25;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 92%;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  line-height: 1.45;
}
.hint-toast__line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.hint-toast__gap {
  width: 12px;
  flex-shrink: 0;
}
.hint-ico {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}
.hint-ico--arrow {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 11px solid #ffef3d;
  filter: drop-shadow(0 0 3px rgba(255, 230, 0, .85));
}
.hint-ico--block {
  width: 16px;
  height: 14px;
  border: 1.5px solid #6b4a28;
  border-radius: 2px;
  background: linear-gradient(180deg, #c49a6c, #8b5a2b);
  box-shadow: 0 1px 0 #5c3a1a;
}

/* 大院 · 俯瞰院落（原院外；色块进各科） */
#screen-gate .map {
  background:
    linear-gradient(180deg, var(--bg-sky) 0%, var(--bg-sky2) 36%, #9ecf6a 36%, var(--ground) 68%, var(--ground2) 100%);
}
.mountain {
  position: absolute;
  left: -10%;
  right: -10%;
  top: 12%;
  height: 24%;
  background: #7a8fa3;
  clip-path: polygon(0% 100%, 18% 35%, 32% 55%, 48% 20%, 62% 48%, 78% 28%, 100% 100%);
  opacity: .9;
}
.academy--topdown {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translateX(-50%);
  width: min(78vw, 320px);
  height: 42%;
}
.compound {
  position: relative;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 10px 16px rgba(0,0,0,.22));
}
.compound__plaque {
  position: absolute;
  z-index: 6;
  top: -4%;
  left: 50%;
  transform: translateX(-50%);
  background: #8b1e1e;
  color: #ffe9a8;
  font-weight: 900;
  font-size: .88rem;
  padding: 5px 12px;
  border-radius: 6px;
  letter-spacing: .14em;
  white-space: nowrap;
}
.compound__court {
  position: absolute;
  left: 14%;
  right: 14%;
  top: 16%;
  bottom: 22%;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 10px, rgba(255,255,255,.06) 10px, rgba(255,255,255,.06) 11px),
    #c8e39a;
  border-radius: 4px;
}
.compound__wall {
  position: absolute;
  background: #d9c2a0;
  border: 2px solid #a88962;
  box-sizing: border-box;
}
.compound__wall--n {
  left: 8%;
  right: 8%;
  top: 8%;
  height: 12%;
  border-radius: 6px 6px 0 0;
}
.compound__wall--e {
  top: 8%;
  right: 8%;
  bottom: 14%;
  width: 10%;
}
.compound__wall--w {
  top: 8%;
  left: 8%;
  bottom: 14%;
  width: 10%;
}
.compound__wall--s-l {
  left: 8%;
  bottom: 14%;
  width: 28%;
  height: 10%;
}
.compound__wall--s-r {
  right: 8%;
  bottom: 14%;
  width: 28%;
  height: 10%;
}
.compound__block {
  position: absolute;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 2px solid #6b4a28;
  border-radius: 4px;
  background: linear-gradient(180deg, #c49a6c, #8b5a2b);
  color: #fff8e8;
  font-size: clamp(0.68rem, 2.8vw, 0.85rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 2px 0 #5c3a1a;
  -webkit-tap-highlight-color: transparent;
}
.compound__yards {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
.compound__yards .compound__block {
  pointer-events: auto;
}
.compound__block:active {
  transform: translateY(1px);
  box-shadow: none;
}
.compound__block--roots {
  left: 18%;
  top: 18%;
  width: 28%;
  height: 15%;
}
.compound__block--code {
  right: 18%;
  top: 18%;
  width: 28%;
  height: 15%;
}
.compound__block--split {
  left: 18%;
  top: 36%;
  width: 28%;
  height: 15%;
}
.compound__block--short {
  right: 18%;
  top: 36%;
  width: 28%;
  height: 15%;
}
.compound__block--blind {
  left: 18%;
  top: 54%;
  width: 28%;
  height: 15%;
}
.gate--topdown {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  width: 22%;
  height: 16%;
  padding: 0;
  background: #5c3a1a;
  border: 2px solid #3a2410;
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.gate--topdown .gate-door {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background:
    repeating-linear-gradient(90deg, #9a6834 0 6px, #7a4e28 6px 12px);
  transition: transform .65s ease;
}
.gate-door--l { left: 0; transform-origin: left center; }
.gate-door--r { right: 0; transform-origin: right center; }
.gate--topdown.is-open .gate-door--l {
  transform: translateX(-92%);
}
.gate--topdown.is-open .gate-door--r {
  transform: translateX(92%);
}
.avatar {
  position: absolute;
  width: 42px;
  height: 58px;
  transition: left .8s ease, top .8s ease, opacity .4s ease;
  z-index: 7;
}
.avatar__body {
  width: 28px;
  height: 28px;
  margin: 10px auto 0;
  background: #3d8bfd;
  border-radius: 10px 10px 6px 6px;
  position: relative;
}
.avatar__head {
  width: 22px;
  height: 22px;
  margin: 0 auto;
  background: #ffd3a8;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.12);
}
.avatar__legs {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 2px;
}
.avatar__legs span {
  width: 8px;
  height: 14px;
  background: #2a4a7a;
  border-radius: 3px;
}
#hero-gate {
  left: 50%;
  top: 82%;
  transform: translateX(-50%);
}
.flash-arrow {
  position: absolute;
  z-index: 8;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  animation: pulse 1s ease-in-out infinite;
}
.flash-arrow::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-bottom: 22px solid #ffef3d;
  filter: drop-shadow(0 0 6px rgba(255, 230, 0, .9));
  margin: 0 auto;
}
.flash-arrow--up::before {
  transform: none;
}
@keyframes pulse {
  0%, 100% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(-8px); opacity: .55; }
}
#arrow-gate {
  left: 50%;
  top: 68%;
  margin-left: -18px;
}

/* 院落地图（大图占位） */
#screen-yard .map {
  background:
    linear-gradient(180deg, #87c8ef 0 18%, #6aa84f 18% 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 72px 20px 28px;
  box-sizing: border-box;
}
.yard-map-placeholder {
  width: min(100%, 420px);
  padding: 22px 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px dashed rgba(80, 60, 20, 0.35);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  text-align: center;
  z-index: 2;
}
.yard-map-placeholder__title {
  font-size: 1.25rem;
  font-weight: 900;
  color: #2a2208;
  margin-bottom: 10px;
}
.yard-map-placeholder__text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.55;
  color: #4a4030;
  font-weight: 600;
}

/* 胖老师：进场介绍 → 角落半身答疑入口 */
.teacher {
  position: absolute;
  z-index: 12;
  width: 78px;
  left: -90px;
  bottom: 18%;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: center;
  transition: left 0.85s ease, bottom 0.85s ease, transform 0.85s ease;
  -webkit-tap-highlight-color: transparent;
}
.teacher[hidden] {
  display: none !important;
}
.teacher.is-in {
  left: 10%;
}
.teacher__body {
  width: 54px;
  height: 44px;
  margin: 0 auto;
  background: #e8a87c;
  border-radius: 50% 50% 40% 40%;
}
.teacher__head {
  width: 36px;
  height: 36px;
  margin: 0 auto -6px;
  background: #ffd3a8;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
}
.teacher__label {
  margin-top: 4px;
  font-size: 0.7rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.teacher.is-dock {
  left: auto;
  right: 6px;
  bottom: calc(-18px + var(--safe-bottom, 0px));
  width: 72px;
  overflow: hidden;
  height: 78px;
  animation: teacherBlink 3.6s ease-in-out infinite;
}
.teacher.is-dock .teacher__label {
  position: absolute;
  left: 0;
  right: 0;
  top: 2px;
  margin: 0;
  font-size: 0.62rem;
}
.teacher.is-dock .teacher__head {
  margin-top: 16px;
}
@keyframes teacherBlink {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(10px);
  }
  40%,
  60% {
    opacity: 1;
    transform: translateY(0);
  }
}

.dialog,
.ask-panel {
  position: absolute;
  z-index: 30;
  left: 10px;
  right: 10px;
  bottom: calc(14px + var(--safe-bottom, 0px));
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  padding: 14px 14px 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}
.dialog[hidden],
.ask-panel[hidden] {
  display: none !important;
}
.dialog.is-open,
.ask-panel.is-open {
  display: block;
}
.dialog__name,
.ask-panel__name {
  font-weight: 900;
  color: #c44536;
  margin-bottom: 6px;
}
.dialog__text,
.ask-panel__text {
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 12px;
  color: #333;
}
.dialog__actions,
.ask-panel__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.dialog__actions .btn,
.ask-panel__actions .btn {
  padding: 8px 16px;
  font-size: 0.9rem;
}

/* 字根院 25 门 */
#screen-roots .map {
  background: linear-gradient(180deg, #9fd0ef 0 22%, #6fad52 22% 100%);
}
.roots-title {
  position: absolute;
  top: calc(58px + var(--safe-top));
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 900;
  font-size: 1.05rem;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.35);
  z-index: 3;
}
.keys-grid {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(96px + var(--safe-top));
  bottom: calc(108px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  overflow: auto;
  padding-bottom: 8px;
  z-index: 4;
}
.roots-zigen-link {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(52px + var(--safe-bottom));
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.roots-zigen-link__a {
  pointer-events: auto;
  display: inline-block;
  padding: 8px 22px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  font-weight: 900;
  font-size: 0.95rem;
  text-decoration: none;
  backdrop-filter: blur(6px);
}
.roots-zigen-link__a:active {
  transform: scale(0.97);
}
.key-door {
  aspect-ratio: 1;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff4dd, #efd3a0);
  box-shadow: 0 4px 10px rgba(0,0,0,.15);
  font-size: 1.15rem;
  font-weight: 900;
  color: #4a2a12;
  cursor: pointer;
}
.key-door:active { transform: scale(.96); }

.back-fab {
  position: absolute;
  z-index: 20;
  left: 12px;
  bottom: calc(14px + var(--safe-bottom));
}
.back-fab .btn {
  background: rgba(0,0,0,.45);
  box-shadow: none;
  font-size: .85rem;
  padding: 10px 14px;
}
