:root {
  color-scheme: dark;
  font-family: "M PLUS Rounded 1c", "Zen Maru Gothic", sans-serif;
  --ink: #fffaf2;
  --muted: #cbc9e7;
  --panel: rgba(22, 19, 62, 0.74);
  --panel-deep: rgba(14, 12, 43, 0.94);
  --line: rgba(255, 255, 255, 0.18);
  --gold: #ffd45f;
  --purple: #9f7cff;
  --pink: #ff73a9;
  --cyan: #5ce4e7;
  --green: #73e4a2;
  --danger: #ff6d71;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #14113a; color: var(--ink); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }

#game { position: relative; width: 100%; height: 100%; min-height: 540px; isolation: isolate; overflow: hidden; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: -2; }
#game::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 7, 32, .04) 40%, rgba(8, 7, 32, .72) 100%);
}

.glass { background: var(--panel); border: 1px solid var(--line); box-shadow: 0 16px 45px rgba(3, 2, 19, .25); backdrop-filter: blur(18px); }
.hidden { display: none !important; }
.topbar { position: absolute; top: max(18px, env(safe-area-inset-top)); left: 22px; right: 22px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.hero-card { min-width: 268px; border-radius: 18px; padding: 10px 14px 10px 10px; display: flex; align-items: center; gap: 11px; text-align: left; cursor: pointer; transition: transform .2s ease, background .2s ease; }
.hero-card:hover { transform: translateY(-2px); background: rgba(34, 29, 87, .86); }
.avatar { width: 48px; height: 48px; display: grid; place-items: center; background: linear-gradient(145deg, #7363db, #362877); border: 2px solid rgba(255,255,255,.28); border-radius: 14px; font-size: 27px; }
.hero-info { display: grid; gap: 4px; flex: 1; }
.hero-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-line b { font-size: 15px; letter-spacing: .03em; }
.hero-rank { display: flex; align-items: center; gap: 6px; }
.hero-rank i { padding: 3px 7px; color: #fff5c4; background: rgba(255,212,95,.16); border: 1px solid rgba(255,212,95,.32); border-radius: 99px; font-size: 10px; font-style: normal; font-weight: 900; white-space: nowrap; }
.hero-line em { color: var(--gold); font-style: normal; font-weight: 900; font-size: 14px; }
.hero-info small { color: var(--muted); font-size: 12px; text-align: right; }
.xp-track { width: 100%; height: 7px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.12); }
.xp-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), #8df6be); box-shadow: 0 0 12px var(--cyan); transition: width .5s ease; }
.resource-group { border-radius: 18px; padding: 11px 12px; display: flex; align-items: center; gap: 18px; }
.resource-group > span { display: flex; align-items: center; gap: 7px; font-size: 17px; }
.resource-group i { color: var(--gold); font-style: normal; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 12px; background: rgba(255,255,255,.1); cursor: pointer; }

.quest-card { position: absolute; top: 108px; left: 22px; width: 260px; padding: 16px 18px; border-radius: 18px; }
.quest-kicker, .logo-kicker { margin: 0 0 4px; color: var(--gold); font-size: 12px; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.quest-card h2 { margin: 0 0 11px; font-size: 16px; }
.quest-card p { display: flex; justify-content: space-between; margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.quest-card p b { color: var(--ink); font-weight: 700; }
.quest-progress { height: 8px; background: rgba(255,255,255,.12); border-radius: 99px; overflow: hidden; }
.quest-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #ff9472); border-radius: inherit; transition: width .45s ease; }

.stage-card { position: absolute; top: 108px; right: 22px; width: 340px; padding: 14px 16px 13px; border-radius: 18px; overflow: hidden; transition: border-color .3s, box-shadow .3s; }
.stage-card.boss { border-color: rgba(255,109,113,.62); box-shadow: 0 16px 45px rgba(75,12,34,.35), 0 0 24px rgba(255,109,113,.16); }
.stage-card-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .08em; }
.stage-card-head b { color: var(--gold); }
.stage-card.boss .stage-card-head b { color: #ff9da2; }
.stage-card h2 { margin: 5px 0 10px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-route { position: relative; display: grid; grid-template-columns: repeat(6,1fr); grid-template-rows: repeat(2,auto); row-gap: 9px; padding: 2px 1px; }
.stage-route::before { content:""; position:absolute; inset:14px 17px 20px; border:3px dotted rgba(255,255,255,.16); border-left:0; border-radius:0 22px 22px 0; }
.stage-node { position: relative; z-index: 1; width: 32px; display: grid; justify-items: center; gap: 3px; color: #8f8aaa; font-size: 9px; font-weight: 900; }
.stage-node::before { display:none; }
.stage-node i { width: 27px; height: 27px; display: grid; place-items: center; color: #aaa4c6; background: #302b63; border: 2px solid rgba(255,255,255,.14); border-radius: 50%; font-size: 11px; font-style: normal; }
.stage-node.current i { color: #29203f; background: var(--gold); border-color: #fff0aa; box-shadow: 0 0 16px rgba(255,212,95,.5); transform: scale(1.12); }
.stage-node.boss i { color: #fff; background: #b34266; border-color: #ff9bac; }
.stage-node.done i { color: #183c32; background: var(--green); border-color: #b4ffd0; }
.stage-node.done::before, .stage-node.current::before { background: linear-gradient(90deg, var(--green), var(--gold)); }
.stage-card > p { margin: 8px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.stage-card.boss > p { color: #ffb2b7; font-weight: 900; animation: bossPulse 1.2s ease-in-out infinite; }
.subject-seals { display:flex; justify-content:center; flex-wrap:wrap; gap:5px; margin-top:8px; }
.subject-seals span { padding:4px 7px; color:#8f8aaa; background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.11); border-radius:99px; font-size:9px; font-weight:900; }
.subject-seals span.earned { color:#213a2d; background:var(--green); border-color:#c6ffda; box-shadow:0 0 10px rgba(107,238,162,.25); }

.world-title { position: absolute; top: 24%; left: 50%; transform: translateX(-50%); text-align: center; width: min(92vw, 740px); pointer-events: none; text-shadow: 0 3px 20px rgba(14, 9, 50, .55); transition: opacity .3s ease; }
.world-title p { margin: 0 0 8px; color: #f7dc91; font-weight: 900; letter-spacing: .2em; font-size: 13px; }
.world-title h1 { margin: 0; font-family: "Zen Maru Gothic", sans-serif; font-size: clamp(27px, 4vw, 48px); letter-spacing: .04em; }

.subject-dock { position: absolute; bottom: max(28px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width:94vw; display: flex; align-items: stretch; justify-content:center; gap: 12px; }
.subject-button { width: 205px; min-height: 88px; border: 1px solid rgba(255,255,255,.35); border-radius: 24px; padding: 12px 14px; display: flex; align-items: center; gap: 11px; cursor: pointer; text-align: left; box-shadow: 0 15px 35px rgba(7,5,32,.38); transition: transform .18s ease, filter .18s ease; overflow: hidden; position: relative; }
.subject-button::after { content: ""; position: absolute; width: 85px; height: 85px; border-radius: 50%; right: -28px; top: -34px; background: rgba(255,255,255,.12); }
.subject-button:hover { transform: translateY(-6px) scale(1.02); filter: brightness(1.08); }
.subject-button:active { transform: translateY(-1px) scale(.99); }
.subject-button.kokugo { background: linear-gradient(135deg, #a9437d, #643da2); }
.subject-button.math { background: linear-gradient(135deg, #167e9d, #3c51ae); }
.subject-button.science { background: linear-gradient(135deg, #2e9862, #397b69); }
.subject-button.social { background: linear-gradient(135deg, #c16b35, #8a4562); }
.subject-button.cleared { border-color:#d6ffdf; box-shadow:0 0 0 3px rgba(107,238,162,.2),0 15px 35px rgba(7,5,32,.38); }
.subject-button.cleared::before { content:"CLEAR ✓"; position:absolute; z-index:2; top:6px; right:7px; padding:3px 6px; color:#173d2b; background:var(--green); border-radius:99px; font-size:8px; font-weight:900; letter-spacing:.04em; }
.subject-icon { flex: 0 0 auto; width: 55px; height: 55px; display: grid; place-items: center; border-radius: 17px; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.3); font-family: "Zen Maru Gothic", sans-serif; font-size: 25px; font-weight: 900; }
.subject-button > span:last-child { display: grid; grid-template-columns: auto auto; align-items: end; column-gap: 14px; }
.subject-button small { grid-column: 1 / -1; color: rgba(255,255,255,.72); font-size: 12px; letter-spacing: .06em; }
.subject-button b { font-size: 22px; letter-spacing: .08em; }
.subject-button em { margin-bottom: 4px; color: var(--gold); font-size: 13px; font-style: normal; }
.hint { position: absolute; right: 22px; bottom: 32px; padding: 9px 13px; border-radius: 13px; color: var(--muted); font-size: 12px; }
kbd { display: inline-grid; place-items: center; min-width: 23px; height: 23px; margin-right: 3px; color: var(--ink); background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); border-radius: 6px; box-shadow: inset 0 -2px rgba(0,0,0,.15); }

#game.in-battle .topbar,
#game.in-battle .quest-card,
#game.in-battle .stage-card,
#game.in-battle .world-title,
#game.in-battle .subject-dock,
#game.in-battle .hint { opacity: 0; pointer-events: none; transition: opacity .22s ease; }

.battle-panel { position: absolute; inset: 0; display: grid; grid-template-rows: auto auto 1fr auto; justify-items: center; align-content: stretch; gap: 10px; padding: max(14px, env(safe-area-inset-top)) clamp(14px, 4vw, 48px) max(16px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(16,12,53,.14) 0%, rgba(13,10,43,.32) 42%, rgba(11,9,38,.8) 100%); }
.battle-panel.boss-battle { background: linear-gradient(180deg, rgba(45,10,32,.26) 0%, rgba(30,8,34,.52) 40%, rgba(15,6,31,.88) 100%); }
.battle-intro { position:absolute; z-index:15; inset:0; display:grid; place-content:center; justify-items:center; gap:13px; background:radial-gradient(circle at center,rgba(89,39,126,.58),rgba(6,4,27,.95)); text-align:center; animation:introFade 1.5s both; }
.battle-panel.boss-battle .battle-intro { background:radial-gradient(circle at center,rgba(165,28,58,.62),rgba(11,4,24,.96)); }
.battle-intro p { margin:0; padding:7px 14px; color:#ffdae0; background:#b53256; border:1px solid #ff95a8; border-radius:99px; font-size:13px; font-weight:900; letter-spacing:.14em; animation:warningPulse .5s ease-in-out infinite alternate; }
.battle-intro .versus { display:flex; align-items:center; gap:clamp(22px,6vw,70px); font-size:clamp(54px,10vw,100px); filter:drop-shadow(0 18px 28px rgba(0,0,0,.4)); }
.battle-intro .versus b { color:var(--gold); font-size:clamp(42px,8vw,78px); font-style:italic; transform:rotate(-8deg); text-shadow:4px 4px #b13f54; }
.battle-intro h2 { margin:0; font-size:clamp(25px,4vw,45px); text-shadow:0 5px 25px #000; }
.battle-intro small { color:#c6bfdf; font-weight:800; }
.battle-head { width: min(760px, 100%); display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.round-btn, .modal-close { border: 1px solid var(--line); background: rgba(17,14,54,.8); border-radius: 50%; cursor: pointer; font-size: 28px; }
.round-btn { width: 44px; height: 44px; display: grid; place-items: center; }
.battle-meta-pill { justify-self: center; display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: rgba(17,14,54,.8); border: 1px solid var(--line); border-radius: 99px; font-size: 12px; font-weight: 900; backdrop-filter: blur(12px); }
.battle-meta-pill > span:first-child { color: var(--gold); }
.battle-panel.boss-battle .battle-meta-pill { border-color: rgba(255,115,134,.55); background: rgba(54,14,38,.86); }
.battle-panel.boss-battle .battle-meta-pill > span:first-child { color: #ff9cb0; }
.question-number { padding: 3px 9px; background: rgba(255,255,255,.1); border-radius: 99px; font-size: 11px; font-weight: 900; color: var(--ink); }
.player-hp-pill { display: flex; align-items: center; gap: 8px; padding: 6px 11px 6px 8px; background: rgba(17,14,54,.82); border: 1px solid var(--line); border-radius: 15px; backdrop-filter: blur(12px); min-width: 175px; transition: border-color .2s, background .2s; }
.player-hp-pill.damaged { border-color: #ff6d71; background: rgba(94,20,38,.9); animation: enemyHit .38s ease-out; }
.player-hp-avatar { width: 32px; height: 32px; display: grid; place-items: center; background: linear-gradient(145deg,#7363db,#362877); border-radius: 10px; font-size: 19px; flex: 0 0 auto; }
.player-hp-body { flex: 1; display: grid; gap: 4px; }
.player-hp-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 10px; color: var(--muted); font-weight: 800; }
.player-hp-row b { color: var(--ink); font-size: 11px; }
.player-hp-track { display: block; width: 100%; height: 7px; border-radius: 99px; background: rgba(255,255,255,.14); overflow: hidden; }
.player-hp-track i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #43d98d, #8ef6c2); transition: width .35s ease, background .35s ease; }
.player-hp-pill.low .player-hp-track i { background: linear-gradient(90deg, #ff5d6c, #ff9966); }

.enemy-stage { width: min(740px, 100%); display: flex; justify-content: center; margin-top: 2px; }
.enemy-card { position: relative; width: 100%; display: grid; grid-template-columns: 98px 1fr; align-items: center; gap: 16px; padding: 13px 18px; background: linear-gradient(135deg, rgba(28,22,78,.86), rgba(16,13,48,.9)); border: 1.5px solid rgba(173,157,255,.32); border-radius: 22px; box-shadow: 0 18px 46px rgba(4,3,24,.45), inset 0 1px rgba(255,255,255,.14); backdrop-filter: blur(14px); transition: transform .25s ease, border-color .3s ease, box-shadow .3s ease, opacity .5s ease; }
.enemy-card.boss { background: linear-gradient(135deg, rgba(72,18,52,.9), rgba(26,11,46,.94)); border-color: rgba(255,109,134,.72); box-shadow: 0 20px 55px rgba(84,10,36,.52), 0 0 28px rgba(255,95,125,.24), inset 0 1px rgba(255,204,212,.22); animation: bossAura 2.2s ease-in-out infinite; }
.enemy-card.enraged { border-color: #ff5668; box-shadow: 0 20px 58px rgba(128,12,34,.65), 0 0 36px rgba(255,74,98,.46); animation: enragedPulse 1s ease-in-out infinite; }
.enemy-card.hit { animation: enemyHit .42s ease-out; border-color: #fff0a8; }
.enemy-card.attacking { animation: enemyAttack .48s ease-out; border-color: #ff6174; }
.enemy-card.defeated { opacity: .45; transform: scale(.94) translateY(8px); filter: grayscale(.6); }
.enemy-portrait { position: relative; width: 92px; height: 92px; display: grid; place-items: center; border-radius: 20px; background: radial-gradient(circle at 50% 42%, rgba(159,124,255,.34), rgba(19,16,56,.85)); border: 2px solid rgba(255,255,255,.2); overflow: visible; }
.enemy-card.boss .enemy-portrait { background: radial-gradient(circle at 50% 42%, rgba(255,95,125,.42), rgba(38,10,36,.92)); border-color: rgba(255,180,104,.65); }
.enemy-aura { position: absolute; inset: -6px; border-radius: 24px; border: 2px solid rgba(159,124,255,.28); pointer-events: none; animation: auraSpin 3.6s ease-in-out infinite; }
.enemy-card.boss .enemy-aura { border-color: rgba(255,112,135,.65); box-shadow: 0 0 18px rgba(255,95,125,.35); }
.enemy-boss-crown { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font-size: 20px; filter: drop-shadow(0 3px 6px rgba(0,0,0,.5)); }
.enemy-emoji { position: relative; z-index: 1; font-size: 52px; line-height: 1; filter: drop-shadow(0 8px 14px rgba(0,0,0,.45)); animation: enemyFloat 2.4s ease-in-out infinite; }
.enemy-card.hit .enemy-emoji { filter: brightness(2.2) drop-shadow(0 0 18px #ffe484); }
.enemy-card.defeated .enemy-emoji { animation: enemyDefeat .75s ease-in forwards; }
.damage-layer { position: absolute; inset: -16px -22px; pointer-events: none; z-index: 5; overflow: visible; }
.damage-popup { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); font-family: "Zen Maru Gothic", sans-serif; font-size: 26px; font-weight: 900; color: #fff6a8; text-shadow: 0 3px 0 #7b223a, 0 0 18px rgba(255,212,95,.85); white-space: nowrap; animation: damageFloat 1.05s cubic-bezier(.16,.84,.32,1) forwards; }
.damage-popup.critical { font-size: 30px; color: #ffeb70; text-shadow: 0 3px 0 #a31d41, 0 0 24px rgba(255,110,130,.95); }
.damage-popup.enemy-atk { font-size: 20px; color: #ff9da8; text-shadow: 0 2px 0 #4d0d1c, 0 0 16px rgba(255,70,95,.85); }
.enemy-info { display: grid; gap: 6px; min-width: 0; }
.enemy-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.enemy-tags span { padding: 2px 8px; border-radius: 99px; font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.enemy-boss-tag { color: #fff; background: linear-gradient(135deg, #e5395e, #ff7b47); box-shadow: 0 0 12px rgba(255,86,118,.45); }
.enemy-boss-tag.enraged { background: linear-gradient(135deg, #ff2a55, #ffd059); color: #2a0a16; animation: warningPulse .55s ease-in-out infinite alternate; }
.enemy-rank-tag { color: var(--muted); background: rgba(255,255,255,.1); }
.enemy-stat-tag { color: #d5f9ff; background: rgba(92,228,231,.16); border: 1px solid rgba(92,228,231,.3); }
.enemy-stat-tag.atk { color: #ffd4c9; background: rgba(255,109,113,.16); border-color: rgba(255,109,113,.35); }
.enemy-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.enemy-title-row h2 { margin: 0; font-family: "Zen Maru Gothic", sans-serif; font-size: clamp(19px, 2.2vw, 24px); letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.enemy-hp-text { color: #ffe5b4; font-size: 13px; font-weight: 900; white-space: nowrap; }
.hp-box { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; }
.hp-box small { color: #ffb5be; font-size: 11px; font-weight: 900; letter-spacing: .08em; }
.hp-track { position: relative; height: 13px; background: rgba(6,5,24,.65); border: 1px solid rgba(255,255,255,.16); border-radius: 99px; overflow: hidden; box-shadow: inset 0 2px 5px rgba(0,0,0,.45); }
.hp-trail { position: absolute; inset: 0 auto 0 0; width: 100%; border-radius: inherit; background: linear-gradient(90deg, #fff2a6, #ffb96a); transition: width .8s ease .26s; }
.hp-track u { position: relative; z-index: 1; display: block; width: 100%; height: 100%; text-decoration: none; border-radius: inherit; background: linear-gradient(90deg, #ff4b6b, #ff8f5c); box-shadow: 0 0 12px rgba(255,95,117,.55); transition: width .28s ease; }
.enemy-card.low-hp .hp-track u { background: linear-gradient(90deg, #ff2a50, #ff6c5c); animation: bossPulse .7s ease-in-out infinite; }
.enemy-speech { margin: 0; color: #ddd8f8; font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.question-card { align-self: center; justify-self: center; width: min(740px, 100%); padding: clamp(18px, 2.6vw, 28px) clamp(18px, 3vw, 32px); background: rgba(255,252,244,.97); color: #282248; border: 2px solid rgba(255,255,255,.75); border-radius: 26px; box-shadow: 0 24px 72px rgba(7,4,32,.5); }
.battle-panel.boss-battle .question-card { border-color: rgba(255,156,174,.7); box-shadow: 0 24px 75px rgba(56,8,30,.58); }
.question-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.question-meta span { padding: 5px 11px; color: #5d4b93; background: #eee9ff; border-radius: 99px; font-size: 12px; font-weight: 900; }
.question-meta span:first-child { color: #fff; background: #7356b5; }
.question-meta span:last-child { margin-left: auto; color: #a76200; background: #fff0be; }
.question-meta span.hard { color: #fff; background: linear-gradient(135deg, #d83a62, #ff7c43); }
.question-card h2 { margin: 14px 0 18px; font-family: "Zen Maru Gothic", sans-serif; font-size: clamp(19px, 2.1vw, 26px); line-height: 1.6; text-align: center; }
.passage { margin: 12px 0 0; padding: 13px 16px; background: #f2eff9; border-left: 5px solid #8c70c8; border-radius: 8px 14px 14px 8px; font-size: 14px; line-height: 1.8; white-space: pre-line; text-align: left; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; max-width: 660px; margin: 0 auto; }
.choice { min-height: 56px; display: flex; align-items: center; gap: 11px; padding: 11px 14px; color: #332d4b; background: #fff; border: 2px solid #ddd8eb; border-radius: 15px; cursor: pointer; text-align: left; font-size: 16px; font-weight: 800; box-shadow: 0 4px 0 #e5e0f2; transition: border-color .16s, transform .16s, background .16s, box-shadow .16s; }
.choice:hover { border-color: #8269c4; background: #f8f5ff; transform: translateY(-2px); box-shadow: 0 6px 0 #d8cff0; }
.choice:active { transform: translateY(1px); box-shadow: 0 2px 0 #d8cff0; }
.choice > span { flex: 0 0 auto; width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; color: #765cae; background: #eee9f8; }
.choice.correct { color: #166743; border-color: #49bf86; background: #e8fff2; box-shadow: 0 4px 0 #a9e6c7; }
.choice.wrong { color: #9d303c; border-color: #f0787f; background: #fff0f0; box-shadow: 0 4px 0 #f3b5b9; }
.choice:disabled { cursor: default; transform: none; }
.feedback { position: relative; overflow: hidden; align-self: end; justify-self: center; width: min(740px, 100%); display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px; padding: 12px 16px 16px; background: rgba(20,17,57,.96); border: 1.5px solid rgba(115,228,162,.48); border-radius: 19px; box-shadow: 0 15px 45px rgba(4,3,25,.42); cursor: pointer; }
.feedback.wrong { border-color: rgba(255,109,113,.58); }
.feedback-mark { width: 46px; height: 46px; display: grid; place-items: center; color: #123f2c; background: var(--green); border-radius: 50%; font-size: 27px; font-weight: 900; }
.feedback.wrong .feedback-mark { color: #5b2024; background: #ff8a91; }
.feedback-body { min-width: 0; }
.feedback-head-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 2px; }
.feedback h3 { margin: 0; color: var(--green); font-size: 16px; }
.feedback.wrong h3 { color: #ff969d; }
.feedback-damage-tag { padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 900; color: #2b1d07; background: var(--gold); }
.feedback.wrong .feedback-damage-tag { color: #fff; background: #d4425c; }
.feedback p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.auto-next-pill { padding: 6px 11px; border-radius: 99px; background: rgba(255,255,255,.1); color: #efeaff; font-size: 11px; font-weight: 900; white-space: nowrap; }
.auto-next-track { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.12); }
.auto-next-track i { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); transform-origin: left center; }
.feedback.wrong .auto-next-track i { background: linear-gradient(90deg, #ff7e88, var(--gold)); }
.primary-btn { border: 0; border-radius: 13px; padding: 12px 20px; color: #272041; background: linear-gradient(135deg, var(--gold), #ff9f69); box-shadow: 0 7px 0 #af6044; cursor: pointer; font-weight: 900; }
.primary-btn:active { transform: translateY(4px); box-shadow: 0 3px 0 #af6044; }

.modal { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(7,5,30,.72); backdrop-filter: blur(12px); }
.modal-card { position: relative; width: min(500px, 94vw); max-height: 92vh; overflow: auto; padding: 34px; background: linear-gradient(145deg, rgba(37,30,94,.98), rgba(17,14,51,.99)); border: 1px solid rgba(255,255,255,.2); border-radius: 29px; box-shadow: 0 35px 100px rgba(3,2,20,.65), inset 0 1px rgba(255,255,255,.12); text-align: center; }
.start-card h1 { margin: 6px 0 12px; font-family: "Zen Maru Gothic", sans-serif; font-size: clamp(29px, 7vw, 43px); }
.start-card h1 i { color: var(--gold); font-style: normal; }
.start-card > p:not(.logo-kicker) { color: var(--muted); line-height: 1.8; font-size: 14px; }
.player-select { margin-top: 17px; text-align: left; }
.player-select h2 { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.player-list { display: grid; gap: 8px; max-height: 178px; overflow-y: auto; padding: 2px; }
.player-card { width: 100%; min-height: 62px; display: grid; grid-template-columns: 43px 1fr auto; align-items: center; gap: 10px; padding: 8px 11px; color: var(--ink); background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.11); border-radius: 14px; cursor: pointer; text-align: left; transition: transform .16s, border-color .16s, background .16s; }
.player-card:hover { transform: translateY(-2px); border-color: var(--gold); background: rgba(255,212,95,.1); }
.player-card > i { width: 40px; height: 40px; display: grid; place-items: center; background: linear-gradient(145deg,#7260d5,#35276e); border-radius: 12px; font-size: 22px; font-style: normal; }
.player-card > span { display: grid; }
.player-card b { font-size: 15px; }
.player-card small { color: var(--muted); font-size: 10px; }
.player-card > em { color: var(--gold); font-size: 18px; font-style: normal; }
.empty-players { padding: 12px; color: #9995bb; background: rgba(255,255,255,.04); border: 1px dashed rgba(255,255,255,.16); border-radius: 12px; font-size: 12px; text-align: center; }
.start-divider { position: relative; margin: 18px 0 12px; color: #8e8aaf; font-size: 11px; font-weight: 800; text-align: center; }
.start-divider::before { content: ""; position: absolute; z-index: 0; top: 50%; left: 0; right: 0; height: 1px; background: rgba(255,255,255,.12); }
.start-divider span { position: relative; z-index: 1; padding: 0 10px; background: #201a59; }
.logo-orbit { height: 78px; display: flex; justify-content: center; align-items: center; gap: 17px; }
.logo-orbit span { width: 55px; height: 55px; display: grid; place-items: center; border-radius: 50%; background: linear-gradient(145deg, #8b6bdd, #513c92); font-size: 24px; font-weight: 900; box-shadow: 0 0 30px rgba(143,108,236,.45); }
.logo-orbit span:last-child { background: linear-gradient(145deg, #29a9c2, #3855ab); }
.logo-orbit strong { color: var(--gold); font-size: 25px; animation: twinkle 1.6s ease-in-out infinite; }
.start-card label { display: block; margin: 22px 0 7px; color: var(--muted); font-size: 13px; font-weight: 700; text-align: left; }
.start-card input { width: 100%; padding: 14px 16px; color: var(--ink); background: rgba(255,255,255,.09); border: 2px solid rgba(255,255,255,.16); border-radius: 13px; font-size: 17px; }
.start-card input::placeholder { color: #9995bb; }
.start-card .primary-btn { width: 100%; margin-top: 17px; font-size: 17px; }
.start-card > small { display: block; margin-top: 14px; color: #8e8aaf; font-size: 11px; }
.grade-picker { margin: 20px 0 4px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border: 0; }
.grade-picker legend { width: 100%; margin-bottom: 8px; color: var(--muted); font-size: 13px; font-weight: 800; text-align: left; }
.grade-option { min-height: 88px; padding: 10px; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; color: var(--ink); background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.12); border-radius: 15px; cursor: pointer; text-align: left; transition: transform .16s, border-color .16s, background .16s; }
.grade-option:hover { transform: translateY(-2px); border-color: rgba(255,212,95,.55); }
.grade-option.active { border-color: var(--gold); background: rgba(255,212,95,.12); box-shadow: 0 0 0 3px rgba(255,212,95,.09); }
.grade-option > span { grid-row: 1 / 3; font-size: 25px; }
.grade-option b { font-size: 14px; }
.grade-option small { color: var(--muted); font-size: 10px; }
.modal-close { position: absolute; top: 15px; right: 15px; width: 40px; height: 40px; color: var(--muted); }
.record-card { text-align: left; }
.record-card h2 { margin: 5px 0 21px; font-size: 24px; }
.record-card h3 { margin: 21px 0 10px; color: var(--muted); font-size: 13px; }
.record-grade { margin-bottom: 13px; padding: 11px 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(255,255,255,.06); border-radius: 14px; }
.record-grade > span { color: var(--muted); font-size: 12px; font-weight: 800; }
.grade-toggle { display: flex; padding: 3px; background: rgba(5,4,25,.3); border-radius: 10px; }
.grade-toggle button { padding: 6px 11px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 900; }
.grade-toggle button.active { color: #2e2545; background: var(--gold); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats-grid div { padding: 14px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; display: grid; }
.stats-grid span { color: var(--muted); font-size: 12px; }
.stats-grid b { color: var(--gold); font-size: 25px; }
.avatar-picker { display:grid; grid-template-columns:repeat(3,1fr); gap:8px; }
.avatar-picker button { min-height:72px; display:grid; place-items:center; gap:2px; padding:7px 5px; color:var(--muted); background:rgba(255,255,255,.06); border:2px solid rgba(255,255,255,.1); border-radius:14px; cursor:pointer; transition:transform .16s,border-color .16s,background .16s; }
.avatar-picker button:hover { transform:translateY(-2px); border-color:rgba(255,212,95,.55); }
.avatar-picker button.selected { color:var(--ink); background:rgba(255,212,95,.12); border-color:var(--gold); box-shadow:0 0 14px rgba(255,212,95,.14); }
.avatar-picker i { font-size:28px; font-style:normal; }
.avatar-picker span { font-size:10px; font-weight:900; }
.mastery-row { display: grid; grid-template-columns: 42px 1fr 45px; align-items: center; gap: 9px; margin: 9px 0; font-size: 13px; font-weight: 800; }
.mastery-row i { display: block; height: 9px; overflow: hidden; background: rgba(255,255,255,.1); border-radius: 99px; }
.mastery-row u { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--purple), var(--pink)); border-radius: inherit; text-decoration: none; }
.mastery-row:nth-of-type(2) u { background: linear-gradient(90deg, #368bca, var(--cyan)); }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { min-width: 70px; display: grid; place-items: center; gap: 3px; padding: 9px; color: var(--muted); background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 13px; font-size: 10px; text-align: center; }
.badge i { filter: grayscale(1); opacity: .35; font-size: 25px; font-style: normal; }
.badge.earned { color: var(--ink); border-color: rgba(255,212,95,.42); background: rgba(255,212,95,.1); }
.badge.earned i { filter: none; opacity: 1; }
.secondary-btn { padding: 10px 16px; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.profile-actions { display: flex; gap: 9px; margin-top: 24px; }
.profile-actions .secondary-btn { flex: 1; }
.victory-card { overflow: visible; }
.treasure { margin-top: -76px; font-size: 88px; filter: drop-shadow(0 18px 24px rgba(0,0,0,.3)); animation: treasureBounce 1.1s ease-in-out infinite; }
.victory-card h2 { margin: 7px 0; font-size: 28px; }
.victory-card > p:not(.logo-kicker) { color: var(--muted); }
.reward-row { display: flex; justify-content: center; gap: 13px; margin: 20px 0; }
.reward-row span { min-width: 105px; padding: 11px; color: var(--gold); background: rgba(255,255,255,.08); border-radius: 13px; font-size: 18px; }
.victory-card .primary-btn { width: 100%; }
.toast { position: absolute; z-index: 40; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); padding: 9px 18px; color: #29223d; background: var(--gold); border-radius: 99px; box-shadow: 0 13px 35px rgba(6,4,29,.42); font-size: 13px; font-weight: 900; max-width: min(90vw, 460px); text-align: center; pointer-events: none; animation: toastIn .35s both; }
.impact-flash { position:absolute; z-index:45; inset:0; pointer-events:none; opacity:0; background:radial-gradient(circle at 50% 35%,rgba(255,255,255,.92),rgba(255,204,92,.38) 26%,transparent 58%); }
.impact-flash.enemy-hit { background:radial-gradient(circle at 50% 50%,rgba(255,70,95,.55),rgba(195,20,52,.32) 38%,transparent 72%); }
.impact-flash.hit { animation:impactFlash .38s ease-out; }
#game.screen-shake { animation:screenShake .38s ease-out; }
.loading { position: absolute; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 13px; background: #17123f; transition: opacity .5s ease; }
.loading span { width: 54px; height: 54px; border: 5px solid rgba(255,255,255,.14); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
.loading p { color: var(--muted); font-size: 13px; letter-spacing: .08em; }
.loading.done { opacity: 0; pointer-events: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes twinkle { 50% { transform: scale(1.35) rotate(15deg); filter: brightness(1.4); } }
@keyframes treasureBounce { 50% { transform: translateY(-7px) rotate(-3deg); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -12px); } }
@keyframes bossPulse { 50% { opacity: .58; } }
@keyframes introFade { 0% { opacity:0; transform:scale(1.08); } 12%,76% { opacity:1; transform:scale(1); } 100% { opacity:0; transform:scale(.96); } }
@keyframes warningPulse { to { transform:scale(1.06); box-shadow:0 0 25px rgba(255,75,104,.65); } }
@keyframes impactFlash { 0% { opacity:1; } 100% { opacity:0; } }
@keyframes screenShake { 0%,100% { transform:translate(0); } 20% { transform:translate(-8px,4px); } 40% { transform:translate(7px,-4px); } 60% { transform:translate(-5px,-2px); } 80% { transform:translate(4px,2px); } }
@keyframes enemyFloat { 0%,100% { transform:translateY(0) scale(1); } 50% { transform:translateY(-5px) scale(1.04); } }
@keyframes auraSpin { 0%,100% { opacity:.5; transform:scale(1); } 50% { opacity:1; transform:scale(1.05); } }
@keyframes bossAura { 0%,100% { box-shadow: 0 20px 55px rgba(84,10,36,.52), 0 0 24px rgba(255,95,125,.24); } 50% { box-shadow: 0 20px 58px rgba(105,12,42,.6), 0 0 38px rgba(255,112,135,.44); } }
@keyframes enragedPulse { 0%,100% { box-shadow: 0 20px 58px rgba(128,12,34,.65), 0 0 28px rgba(255,74,98,.42); } 50% { box-shadow: 0 20px 64px rgba(168,14,40,.8), 0 0 46px rgba(255,156,74,.65); } }
@keyframes enemyHit { 0%,100% { transform:translateX(0); } 20% { transform:translateX(-11px) rotate(-2deg); } 45% { transform:translateX(10px) rotate(2deg); } 70% { transform:translateX(-6px); } }
@keyframes enemyAttack { 0% { transform:scale(1) translateY(0); } 35% { transform:scale(1.04) translateY(8px); } 100% { transform:scale(1) translateY(0); } }
@keyframes enemyDefeat { 0% { transform:scale(1) rotate(0); opacity:1; } 100% { transform:scale(.2) rotate(520deg); opacity:0; } }
@keyframes damageFloat { 0% { opacity:0; transform:translate(-50%, 10px) scale(.6); } 22% { opacity:1; transform:translate(-50%, -14px) scale(1.18); } 100% { opacity:0; transform:translate(-50%, -56px) scale(.94); } }
@keyframes autoBarShrink { from { transform:scaleX(1); } to { transform:scaleX(0); } }

@media (max-width: 1000px) and (min-width: 761px) {
  .subject-button { width:180px; }
  .subject-icon { width:47px; height:47px; }
  .subject-button b { font-size:19px; }
  .enemy-stage, .question-card, .feedback, .battle-head { width: min(700px, 94vw); }
}

@media (max-width: 760px) {
  #game { min-height: 500px; }
  .topbar { top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; }
  .hero-card { min-width: 0; width: 205px; padding-right: 9px; }
  .avatar { width: 41px; height: 41px; font-size: 22px; }
  .hero-info small { display: none; }
  .hero-rank i { display: none; }
  .resource-group { padding: 7px; gap: 9px; }
  .resource-group > span { font-size: 14px; }
  .resource-group span i { display: none; }
  .quest-card { top: 76px; left: 10px; width: 215px; padding: 10px 13px; }
  .quest-kicker { font-size: 10px; }
  .quest-card h2 { font-size: 13px; margin-bottom: 7px; }
  .stage-card { top: 76px; right: 10px; width: 145px; padding: 9px 10px; }
  .stage-card h2 { margin: 3px 0 7px; font-size: 12px; }
  .stage-card-head { font-size: 8px; }
  .stage-route { row-gap: 5px; }
  .stage-route::before { inset:11px 11px 16px; border-width:2px; }
  .stage-node { width: 20px; font-size: 6px; }
  .stage-node i { width: 19px; height: 19px; border-width:1px; font-size: 7px; }
  .subject-seals { gap:2px; margin-top:4px; }
  .subject-seals span { padding:2px 4px; font-size:6px; }
  .stage-card > p { margin-top: 5px; font-size: 8px; }
  .world-title { top: 27%; }
  .subject-dock { width: calc(100% - 20px); flex-wrap:wrap; gap: 8px; bottom: max(13px, env(safe-area-inset-bottom)); }
  .subject-button { width: calc(50% - 4px); min-height: 66px; padding: 8px; border-radius: 17px; gap: 7px; }
  .subject-icon { width: 43px; height: 43px; border-radius: 13px; font-size: 21px; }
  .subject-button b { font-size: 19px; }
  .subject-button small { font-size: 9px; }
  .subject-button em { display: none; }
  .hint { display: none; }
  .battle-panel { padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); gap: 7px; }
  .battle-intro .versus { gap:18px; }
  .battle-head { grid-template-columns: 38px 1fr auto; gap: 6px; }
  .round-btn { width: 38px; height: 38px; font-size: 23px; }
  .battle-meta-pill { padding: 4px 8px; font-size: 10px; gap: 5px; }
  .question-number { padding: 2px 6px; font-size: 9px; }
  .player-hp-pill { min-width: 124px; padding: 4px 8px 4px 5px; gap: 6px; }
  .player-hp-avatar { width: 26px; height: 26px; font-size: 15px; }
  .player-hp-row small { display: none; }
  .enemy-card { grid-template-columns: 68px 1fr; gap: 10px; padding: 9px 11px; border-radius: 18px; }
  .enemy-portrait { width: 64px; height: 64px; border-radius: 15px; }
  .enemy-emoji { font-size: 36px; }
  .enemy-boss-crown { top: -12px; font-size: 16px; }
  .enemy-title-row h2 { font-size: 16px; }
  .enemy-hp-text { font-size: 11px; }
  .enemy-tags span { font-size: 9px; padding: 2px 6px; }
  .enemy-speech { font-size: 10px; }
  .question-card { width: 100%; padding: 14px 15px; max-height: 50vh; overflow-y: auto; border-radius: 20px; }
  .question-card h2 { font-size: 17px; line-height: 1.5; margin: 10px 0 13px; }
  .passage { font-size: 13px; line-height: 1.65; padding: 9px 11px; }
  .choices { grid-template-columns: 1fr; gap: 7px; }
  .choice { min-height: 45px; padding: 8px 10px; font-size: 14px; }
  .choice > span { width: 26px; height: 26px; }
  .feedback { width: 100%; grid-template-columns: 38px 1fr auto; padding: 9px 10px 13px; gap: 8px; }
  .feedback-mark { width: 36px; height: 36px; font-size: 21px; }
  .feedback h3 { font-size: 13px; }
  .feedback-damage-tag { font-size: 10px; }
  .feedback p { font-size: 11px; max-height: 44px; overflow-y: auto; }
  .auto-next-pill { font-size: 10px; padding: 4px 8px; }
  .modal-card { padding: 26px 21px; }
  .grade-option { min-height: 76px; padding: 8px; }
  .grade-option > span { font-size: 21px; }
}

@media (max-height: 700px) and (min-width: 761px) {
  .quest-card { top: 92px; }
  .world-title { top: 20%; }
  .battle-panel { gap: 7px; }
  .enemy-card { padding: 10px 14px; grid-template-columns: 78px 1fr; }
  .enemy-portrait { width: 74px; height: 74px; }
  .enemy-emoji { font-size: 42px; }
  .question-card { padding: 15px 22px; }
  .question-card h2 { margin: 9px 0 13px; font-size: 20px; }
  .choice { min-height: 46px; }
}

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