:root {
  color-scheme: dark;
  --ink: #0d120f;
  --panel: #171e19;
  --panel-2: #202922;
  --line: #435047;
  --text: #f1eddf;
  --muted: #aaa99e;
  --gold: #d6ad56;
  --green: #446653;
  --red: #834952;
  --blue: #526d7d;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--ink); }
body, button, select { color: var(--text); font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.game-app { display: grid; width: 100vw; height: 100dvh; grid-template-rows: 68px minmax(0, 1fr); }
.topbar { z-index: 20; display: grid; grid-template-columns: 42px minmax(250px, 1fr) minmax(260px, 460px) minmax(260px, 1fr); align-items: center; gap: 13px; padding: 0 18px; border-bottom: 1px solid var(--line); background: #121813; }
.icon-button { display: grid; width: 40px; height: 40px; place-items: center; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--panel); text-decoration: none; }
.brand, .player-summary { display: flex; min-width: 0; align-items: center; gap: 10px; }
.brand > span:last-child { display: grid; min-width: 0; }
.brand strong { overflow: hidden; font-size: 16px; white-space: nowrap; text-overflow: ellipsis; }
.brand small, .eyebrow { color: var(--muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 9px; font-weight: 800; }
.crest { display: grid; width: 36px; height: 36px; flex: 0 0 auto; place-items: center; border: 1px solid #896f3e; border-radius: 50%; color: #1a160f; background: var(--gold); font-family: Georgia, serif; font-size: 20px; font-weight: 900; }
.quest { display: grid; height: 44px; align-content: center; gap: 2px; padding: 0 15px; border-right: 1px solid var(--line); border-left: 1px solid var(--line); background: #161d18; }
.quest small { color: var(--muted); font-size: 9px; }
.quest strong { overflow: hidden; font-size: 13px; white-space: nowrap; text-overflow: ellipsis; }
.player-summary { justify-content: end; }
.summary-avatar { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid #8a7244; border-radius: 5px; color: #211b10; background: var(--gold); font-weight: 900; }
.player-summary > div { display: grid; min-width: 100px; gap: 5px; }
.player-summary small { overflow: hidden; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.player-summary strong { width: 100%; height: 5px; overflow: hidden; border-radius: 3px; background: #3c2829; }
.player-summary strong i { display: block; width: 100%; height: 100%; background: #62b67b; transition: width 180ms; }
.mute-line { display: none; }
.is-muted .sound-wave { display: none; }
.is-muted .mute-line { display: block; }

.game-stage { position: relative; min-height: 0; overflow: hidden; background: #101711; }
canvas { display: block; width: 100%; height: 100%; }
.scene-label { position: absolute; top: 18px; left: 22px; padding: 7px 11px; border: 1px solid rgba(216, 190, 128, .4); border-radius: 5px; color: #e8d6aa; background: rgba(11, 17, 13, .76); font-size: 11px; font-weight: 800; }
.story-panel { position: absolute; right: clamp(26px, 7vw, 110px); bottom: clamp(28px, 8vh, 100px); width: min(510px, calc(100% - 40px)); padding: 27px; border-left: 3px solid var(--gold); background: rgba(13, 18, 15, .88); backdrop-filter: blur(7px); }
.story-panel h1 { margin: 8px 0 12px; font-family: Georgia, "Songti SC", serif; font-size: clamp(38px, 6vw, 68px); line-height: .98; }
.story-panel > p:nth-of-type(2) { margin: 0 0 22px; color: #d1cec2; font-size: 14px; line-height: 1.7; }
.primary-button, .secondary-button, .danger-button { display: inline-flex; min-height: 43px; align-items: center; justify-content: center; gap: 9px; padding: 0 18px; border-radius: 5px; font-weight: 900; }
.primary-button { border: 1px solid #ecd184; color: #211b11; background: var(--gold); }
.secondary-button { border: 1px solid var(--line); color: var(--text); background: var(--panel-2); }
.danger-button { border: 1px solid #7d4c51; color: #e8c9ca; background: #3a2327; }

.choice-layer, .wand-layer, .lesson-layer, .book-layer { position: fixed; inset: 68px 0 0; z-index: 15; display: grid; place-items: center; padding: 22px; background: rgba(7, 11, 8, .82); backdrop-filter: blur(6px); }
.choice-dialog, .lesson-dialog, .book-dialog { display: grid; width: min(950px, 100%); max-height: calc(100dvh - 110px); overflow: hidden; border: 1px solid #59655c; border-radius: 7px; background: #151c17; box-shadow: 0 24px 80px rgba(0,0,0,.5); }
.choice-dialog > header, .lesson-dialog > header, .book-dialog > header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--line); background: #1b241d; }
.choice-dialog h2, .lesson-dialog h2, .book-dialog h2, .school-map h2 { margin: 3px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 25px; }
.choice-dialog > header > span { color: var(--gold); font-weight: 900; }
.choice-copy { margin: 0; padding: 12px 20px; color: var(--muted); font-size: 12px; }
.choice-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; overflow: auto; padding: 4px 18px 18px; }
.choice-card { display: grid; min-height: 120px; align-content: center; justify-items: center; gap: 7px; padding: 12px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: #202922; }
.choice-card:hover, .choice-card.is-selected { border-color: var(--gold); background: #2a3026; }
.choice-card .portrait { display: grid; width: 53px; height: 53px; place-items: center; border: 2px solid rgba(255,255,255,.35); border-radius: 50%; background: var(--avatar); font-size: 19px; font-weight: 1000; }
.choice-card strong { font-size: 12px; text-align: center; }
.choice-card small { color: var(--muted); font-size: 9px; text-align: center; }
.choice-dialog footer { display: flex; justify-content: end; gap: 9px; padding: 13px 18px; border-top: 1px solid var(--line); }
.choice-dialog button:disabled { cursor: default; opacity: .35; }

.wand-shop { display: grid; width: min(900px, 100%); grid-template-columns: minmax(260px, .8fr) minmax(360px, 1.2fr); overflow: hidden; border: 1px solid #665d48; border-radius: 7px; background: #171914; }
.ollivander-scene { position: relative; min-height: 540px; overflow: hidden; background: repeating-linear-gradient(90deg, #2d2217 0 46px, #211910 46px 50px); }
.ollivander-scene::before { position: absolute; inset: 0; background: repeating-linear-gradient(0deg, transparent 0 52px, rgba(222,180,87,.17) 52px 55px); content: ""; }
.ollivander-scene i { position: absolute; width: 130px; height: 18px; border: 1px solid #856a37; background: #584022; box-shadow: 0 0 20px rgba(230,185,80,.16); }
.ollivander-scene i:nth-of-type(1) { top: 90px; left: 38px; transform: rotate(8deg); }
.ollivander-scene i:nth-of-type(2) { top: 220px; right: 35px; transform: rotate(-5deg); }
.ollivander-scene i:nth-of-type(3) { bottom: 105px; left: 65px; transform: rotate(3deg); }
.wand-glow { position: absolute; top: 50%; left: 50%; z-index: 2; width: 220px; height: 220px; transform: translate(-50%,-50%); border-radius: 50%; background: radial-gradient(circle, rgba(245,215,130,.38), transparent 68%); }
.wand-form { display: grid; align-content: center; gap: 12px; padding: 28px; }
.wand-form h2 { margin: 2px 0 0; font-family: Georgia, serif; font-size: 32px; }
.wand-form > p:nth-of-type(2) { margin: 0 0 5px; color: var(--muted); font-size: 12px; }
.wand-form label { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 12px; color: #d5d0c0; font-size: 12px; }
.wand-form select { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: #252d26; }
.wand-preview { display: grid; gap: 9px; padding: 14px; border: 1px solid #4e5145; background: #101510; text-align: center; }
.wand-preview span { position: relative; display: block; width: 78%; height: 7px; margin: 8px auto; transform: rotate(-3deg); border-radius: 5px 70% 70% 5px; background: linear-gradient(90deg, #24170e, #9c7548, #d0ac74); box-shadow: 0 0 12px rgba(236,204,121,.4); }
.wand-preview span::after { position: absolute; right: -5px; top: -3px; width: 11px; height: 11px; border-radius: 50%; background: #f1d783; box-shadow: 0 0 18px #f5de92; content: ""; }
.wand-preview strong { color: #e6d5aa; font-size: 11px; }

.school-map { position: absolute; inset: 50px max(24px, calc((100% - 920px)/2)) 28px; z-index: 5; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 13px; padding: 18px; border: 1px solid rgba(218,190,121,.44); border-radius: 7px; background: rgba(14, 20, 16, .9); backdrop-filter: blur(6px); }
.school-map > header { display: flex; align-items: center; justify-content: space-between; }
.school-map > header > span { color: var(--gold); font-size: 12px; font-weight: 900; }
.classrooms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; min-height: 0; }
.classroom { display: grid; grid-template-rows: 70px 1fr auto; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); text-align: left; background: #202820; }
.classroom > span { display: grid; width: 58px; height: 58px; place-items: center; border: 1px solid rgba(255,255,255,.26); border-radius: 50%; font-size: 28px; }
.classroom strong { display: block; margin: 4px 0 7px; font-family: Georgia, serif; font-size: 22px; }
.classroom p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.classroom b { margin-top: 14px; color: var(--gold); font-size: 11px; }
.classroom.is-complete { border-color: #5e8d6e; }
.classroom.is-complete b::after { content: " · 已完成"; }
.potions > span { background: #5d4d74; }
.defense > span { background: #77444b; }
.charms > span { background: #456b70; }
.hagrid-route { display: flex; min-height: 52px; align-items: center; gap: 12px; padding: 0 15px; border: 1px solid #6f633f; border-radius: 6px; color: var(--text); background: #302b1d; }
.hagrid-route span { font-family: Georgia, serif; font-size: 18px; font-weight: 900; }
.hagrid-route small { flex: 1; color: var(--muted); text-align: left; }
.hagrid-route:disabled { cursor: default; opacity: .45; }

.lesson-dialog { width: min(720px, 100%); }
.lesson-dialog > p { margin: 0; padding: 18px 20px 5px; color: #ccc8bb; }
.lesson-rewards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; overflow: auto; padding: 14px 20px; }
.reward-item { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 10px; border: 1px solid var(--line); border-radius: 5px; background: #202922; }
.reward-item span { display: grid; width: 36px; height: 36px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: #211a0e; background: var(--gold); font-weight: 900; }
.reward-item div { display: grid; gap: 3px; }
.reward-item strong { font-size: 12px; }
.reward-item small { color: var(--muted); font-size: 9px; }
.lesson-dialog > .primary-button { margin: 5px 20px 20px; }

.battle-hud { position: absolute; top: 18px; right: 22px; z-index: 4; display: flex; align-items: center; gap: 8px; }
.battle-objective, .enemy-counter { display: grid; gap: 2px; min-height: 44px; padding: 7px 12px; border: 1px solid rgba(218,190,121,.42); border-radius: 5px; background: rgba(10,16,12,.82); }
.battle-objective small, .enemy-counter span { color: var(--muted); font-size: 9px; }
.battle-objective strong, .enemy-counter strong { font-size: 12px; }
.potion-bar { display: flex; gap: 6px; }
.potion-button { min-height: 44px; padding: 5px 9px; border: 1px solid #62766a; border-radius: 5px; color: #e9e5d8; background: rgba(26,39,31,.88); font-size: 10px; }
.potion-button:disabled { opacity: .35; }
.spell-bar { position: absolute; right: 22px; bottom: 20px; z-index: 5; display: flex; gap: 8px; }
.spell-button { position: relative; display: grid; width: 78px; height: 68px; align-content: center; justify-items: center; gap: 4px; overflow: hidden; border: 1px solid #7b704f; border-radius: 6px; color: #f3ead1; background: rgba(22,27,22,.9); }
.spell-button strong { font-size: 17px; }
.spell-button small { width: 100%; overflow: hidden; font-size: 9px; white-space: nowrap; text-overflow: ellipsis; }
.spell-button i { position: absolute; right: 0; bottom: 0; left: 0; height: 0; background: rgba(8,10,8,.68); transition: height 80ms linear; }
.mobile-move { position: absolute; bottom: 20px; left: 22px; z-index: 5; width: 138px; height: 138px; }
.mobile-move button { position: absolute; width: 48px; height: 48px; border: 1px solid rgba(255,255,255,.32); border-radius: 6px; color: #fff; background: rgba(15,25,18,.7); font-size: 20px; }
.mobile-move button:nth-child(1) { top: 0; left: 45px; }.mobile-move button:nth-child(2) { top: 45px; left: 0; }.mobile-move button:nth-child(3) { top: 90px; left: 45px; }.mobile-move button:nth-child(4) { top: 45px; left: 90px; }

.book-layer { inset: 0; z-index: 30; }
.book-dialog { width: min(850px, 100%); }
.profile-record { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.record-item { display: grid; gap: 4px; padding: 10px; border: 1px solid var(--line); background: #202822; }
.record-item small { color: var(--muted); font-size: 9px; }
.record-item strong { overflow: hidden; font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.book-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; overflow: auto; padding: 16px 18px; }
.book-columns h3 { margin: 0 0 9px; font-size: 14px; }
.book-columns > div > div { display: flex; flex-wrap: wrap; gap: 6px; }
.book-tag { padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; color: #d8d3c5; background: #242c25; font-size: 10px; }
.book-dialog > .danger-button { justify-self: start; margin: 0 18px 18px; }

@media (hover: hover) and (pointer: fine) { .mobile-move { opacity: .3; }.mobile-move:hover { opacity: 1; } }
@media (max-width: 860px) {
  .game-app { grid-template-rows: 58px minmax(0, 1fr); }
  .topbar { grid-template-columns: 38px minmax(80px, 1fr) minmax(130px, 230px) auto; gap: 7px; padding: 0 8px; }
  .crest, .brand small, .player-summary > div, .book-button { display: none; }
  .brand strong { font-size: 12px; }
  .choice-layer, .wand-layer, .lesson-layer { inset: 58px 0 0; padding: 8px; }
  .choice-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wand-shop { grid-template-columns: 1fr; max-height: calc(100dvh - 75px); overflow: auto; }
  .ollivander-scene { min-height: 180px; }
  .school-map { inset: 12px; }
  .classrooms { grid-template-columns: 1fr; overflow: auto; }
  .classroom { grid-template-columns: 60px 1fr auto; grid-template-rows: auto; align-items: center; }
  .classroom b { margin: 0; }
}
@media (max-width: 560px) {
  .quest { display: none; }
  .topbar { grid-template-columns: 38px 1fr auto; }
  .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-card { min-height: 105px; }
  .spell-bar { right: 8px; bottom: 10px; gap: 4px; }
  .spell-button { width: 58px; height: 58px; }
  .mobile-move { bottom: 10px; left: 8px; transform: scale(.82); transform-origin: left bottom; }
  .battle-hud { top: 8px; right: 8px; }
  .battle-objective { display: none; }
  .profile-record { grid-template-columns: repeat(2, 1fr); }
  .book-columns { grid-template-columns: 1fr; }
}
