/* Batalla de Aura YiYi — PlayYiYi. Giao diện thích ứng PC / Android / iOS / iframe. */
:root {
  --gold: #ffd23f; --purple: #7b3cff; --deep: #1c0d45; --pink: #ff4fd8; --cyan: #33d6ff;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --ui: clamp(12px, 1.6vmin + 6px, 18px);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0420; color: #fff; overscroll-behavior: none; }
body { position: fixed; inset: 0; }
#app { position: absolute; inset: 0; overflow: hidden; background: #0b0420; }
#stage { position: absolute; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; background: #1a0b45; }
#game { position: absolute; left: 0; top: 0; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 2.6em; padding: .45em 1.2em; border-radius: 14px; border: 3px solid #2a1640;
  background: linear-gradient(#fff, #e7dcff); color: #2a1640; font-weight: 900; font-size: var(--ui);
  box-shadow: 0 4px 0 #2a1640; text-transform: uppercase; letter-spacing: .02em; transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #2a1640; }
.btn.primary { background: linear-gradient(#ffe46b, #ffb21f); }
.btn.danger { background: linear-gradient(#ffb3c0, #ff5a7a); }
.btn.big { font-size: calc(var(--ui) * 1.35); min-height: 2.5em; padding: .4em 1.8em; }
.pill { border: 2px solid #2a1640; background: #fff; color: #2a1640; border-radius: 999px; padding: .25em .9em; font-weight: 900; min-width: 3.2em; min-height: 2.2em; }
.pill.on { background: var(--gold); }
.icon-btn { width: 2.6em; height: 2.6em; border-radius: 12px; border: 2px solid rgba(255,255,255,.7); background: rgba(30,10,70,.55); color: #fff; font-weight: 900; font-size: var(--ui); display: grid; place-items: center; backdrop-filter: blur(4px); }
.row { display: flex; gap: .6em; flex-wrap: wrap; justify-content: center; }
.row.end { justify-content: flex-end; margin-top: .6em; }

/* ---------- Screens ---------- */
.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) calc(8px + var(--sab)) calc(10px + var(--sal)); }
.screen.show { display: flex; animation: fadeIn .2s ease-out; }
.screen.dim { background: rgba(12,4,35,.55); backdrop-filter: blur(2px); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.panel { background: linear-gradient(160deg, rgba(70,30,160,.96), rgba(35,12,90,.96)); border: 3px solid var(--gold); border-radius: 22px;
  padding: clamp(10px, 2.2vmin, 22px); box-shadow: 0 10px 40px rgba(0,0,0,.5), inset 0 0 0 3px rgba(255,255,255,.08);
  max-width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: .55em; }
.panel.small { min-width: min(340px, 92%); align-items: stretch; }
.panel h2 { margin: 0 0 .2em; text-align: center; font-size: calc(var(--ui) * 1.6); color: var(--gold); text-shadow: 0 3px 0 #2a1640; letter-spacing: .02em; }

/* Title */
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: .7em; text-align: center; }
.logo { position: relative; line-height: .9; transform: rotate(-4deg); font-weight: 900; filter: drop-shadow(0 6px 0 #2a1640) drop-shadow(0 0 24px rgba(255,79,216,.6)); animation: logoPulse 2.4s ease-in-out infinite; }
@keyframes logoPulse { 50% { transform: rotate(-4deg) scale(1.04); } }
.logo-l1, .logo-l2 { font-size: clamp(38px, 11vmin, 104px); -webkit-text-stroke: 3px #2a1640; paint-order: stroke fill; letter-spacing: .01em; }
.logo-l1 { background: linear-gradient(#fff38a, #ffb21f 60%, #ff7a1a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-l2 { background: linear-gradient(#ffffff, #b7f0ff 50%, #5fd0ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-crown { position: absolute; left: -.2em; top: -.75em; font-size: clamp(28px, 7vmin, 60px); color: var(--gold); transform: rotate(-18deg); -webkit-text-stroke: 2px #2a1640; }
.logo-badge { position: absolute; right: -.6em; bottom: -.35em; background: var(--pink); color: #fff; border: 3px solid #2a1640; border-radius: 12px; padding: .05em .4em;
  font-size: clamp(16px, 4vmin, 34px); transform: rotate(8deg); box-shadow: 0 3px 0 #2a1640; }
.subtitle { margin: .3em 0 .2em; font-weight: 800; font-size: calc(var(--ui) * 1.05); text-shadow: 0 2px 0 #2a1640; max-width: 34em; }
.title-stats { font-size: calc(var(--ui) * .85); opacity: .9; font-weight: 700; }
.corner-tools { position: absolute; top: calc(10px + var(--sat)); right: calc(10px + var(--sar)); display: flex; gap: .5em; align-items: center; }
.brand { position: absolute; left: calc(12px + var(--sal)); bottom: calc(8px + var(--sab)); font-weight: 900; opacity: .75; font-size: calc(var(--ui) * .9); }

/* Character select */
.select-panel { width: min(980px, 100%); }
.select-body { display: flex; gap: 1em; min-height: 0; flex: 1; }
.char-detail { flex: 0 0 34%; display: flex; flex-direction: column; align-items: center; background: rgba(0,0,0,.2); border-radius: 16px; padding: .4em; min-width: 0; }
#detail-cv { width: 100%; height: clamp(90px, 28vmin, 240px); }
.detail-info { width: 100%; }
.detail-name { font-weight: 900; font-size: calc(var(--ui) * 1.4); text-align: center; color: var(--gold); }
.detail-quote { font-style: italic; text-align: center; opacity: .9; font-size: calc(var(--ui) * .85); margin-bottom: .3em; min-height: 1.2em; }
.stat { display: grid; grid-template-columns: 6.5em 1fr; align-items: center; gap: .4em; font-size: calc(var(--ui) * .85); font-weight: 800; margin: .15em 0; }
.stat i { display: block; height: .7em; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; }
.stat b { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--cyan), var(--gold)); transition: width .25s; }
.char-grid { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: .55em; align-content: center; }
.card { position: relative; border-radius: 16px; border: 3px solid #2a1640; padding: 0; overflow: hidden; aspect-ratio: 1 / 1; box-shadow: 0 4px 0 #2a1640; transition: transform .1s; }
.card canvas { width: 100%; height: 100%; display: block; }
.card .nm { position: absolute; left: 0; right: 0; bottom: 0; font-size: calc(var(--ui) * .7); font-weight: 900; background: rgba(20,8,40,.7); padding: .15em 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.sel { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold), 0 0 22px var(--gold); transform: translateY(-3px); }
.card.locked { filter: saturate(.3); }

/* Stage select */
.stages-panel { width: min(980px, 100%); }
.stage-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7em; overflow-y: auto; touch-action: pan-y; padding: .2em; }
.stage-card { text-align: left; border-radius: 16px; border: 3px solid #2a1640; padding: .6em .8em; background: linear-gradient(150deg, #fff, #e8deff); color: #2a1640; box-shadow: 0 4px 0 #2a1640; display: flex; flex-direction: column; gap: .15em; min-height: 6.6em; }
.stage-card .no { font-weight: 900; font-size: calc(var(--ui) * .8); opacity: .7; }
.stage-card .nm { font-weight: 900; font-size: calc(var(--ui) * 1.1); }
.stage-card .ds { font-size: calc(var(--ui) * .78); font-weight: 700; opacity: .85; }
.stage-card .st { color: #ff9d00; font-size: calc(var(--ui) * 1.1); letter-spacing: .1em; -webkit-text-stroke: 1px #2a1640; }
.stage-card.locked { background: linear-gradient(150deg, #9b93b5, #6e6690); opacity: .8; }
.stage-card.boss { background: linear-gradient(150deg, #ffe08a, #ff8a5c); }
.stage-card.boss.locked { background: linear-gradient(150deg, #b59a8a, #7d6070); }
#scr-title { background: radial-gradient(ellipse 60% 55% at 50% 50%, rgba(18,6,48,.55), rgba(18,6,48,.1) 70%, rgba(0,0,0,0)); }

/* Help / settings / result */
.help { width: min(640px, 100%); }
.help ol { margin: 0; padding-left: 1.4em; overflow-y: auto; touch-action: pan-y; font-weight: 700; font-size: calc(var(--ui) * .95); line-height: 1.35; }
.help li { margin: .3em 0; }
.help li.keys { list-style: none; margin-left: -1.4em; padding: .4em .6em; background: rgba(0,0,0,.25); border-radius: 10px; font-size: calc(var(--ui) * .82); }
.set-row { display: flex; align-items: center; gap: .5em; font-weight: 800; }
.set-row > span { flex: 0 0 6.5em; }
.set-row input[type=range] { flex: 1; accent-color: var(--gold); min-width: 80px; touch-action: pan-x; }
.result { text-align: center; }
.result h2 { font-size: calc(var(--ui) * 2); }
.result p { margin: 0; font-weight: 800; }
.res-stars { font-size: calc(var(--ui) * 2.4); letter-spacing: .15em; color: #ffcc1a; -webkit-text-stroke: 2px #2a1640; }
.res-stars .off { color: rgba(255,255,255,.2); }
.res-score { font-weight: 800; }
.res-unlock { color: #7dfcff; font-weight: 900; min-height: 1.2em; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: .5em;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) 0 calc(10px + var(--sal)); pointer-events: none; font-size: var(--ui); }
#hud .icon-btn { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: .3em; min-width: 0; }
.hud-stage { font-weight: 900; font-size: .85em; text-shadow: 0 2px 0 #2a1640; }
.aura-bar { position: relative; width: clamp(110px, 22vw, 240px); height: 1.25em; border-radius: 99px; border: 3px solid #2a1640; background: rgba(20,8,40,.7); overflow: hidden; }
#hud-aura-fill { position: absolute; inset: 0; width: 0; background: linear-gradient(90deg, #7b3cff, #ff4fd8, #ffd23f); transition: width .12s; }
.aura-bar.full { animation: auraFull .5s ease-in-out infinite alternate; }
@keyframes auraFull { to { box-shadow: 0 0 18px #ffd23f, 0 0 4px #fff; border-color: #fff; } }
.aura-lbl { position: absolute; inset: 0; display: grid; place-items: center; font-size: .72em; font-weight: 900; letter-spacing: .1em; text-shadow: 0 1px 2px #000; }
.hud-center { flex: 1; display: flex; justify-content: center; }
.rounds { display: flex; gap: .35em; background: rgba(20,8,40,.6); padding: .3em .6em; border-radius: 99px; border: 2px solid rgba(255,255,255,.3); }
.rounds i { width: .95em; height: .95em; border-radius: 50%; border: 2px solid #fff; display: block; }
.rounds i.w { background: var(--gold); } .rounds i.l { background: #ff5a6e; }
.rounds .sep { width: 2px; background: rgba(255,255,255,.4); }
.hud-right { display: flex; align-items: center; gap: .5em; }
.hud-score { font-weight: 900; font-size: 1.15em; color: var(--gold); text-shadow: 0 2px 0 #2a1640; white-space: nowrap; }
.hud-score small { color: #fff; font-size: .65em; }

/* ---------- Touch controls ---------- */
#touch { position: absolute; inset: 0; pointer-events: none; }
#joy-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 70%; pointer-events: auto; touch-action: none; }
#joy-base { position: absolute; left: calc(70px + var(--sal)); top: calc(100% - 80px - var(--sab)); width: clamp(96px, 26vmin, 150px); height: clamp(96px, 26vmin, 150px);
  transform: translate(-50%, -50%); border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.12), rgba(255,255,255,.05)); border: 3px solid rgba(255,255,255,.45); opacity: .7; }
#joy-base.active { opacity: 1; border-color: var(--gold); }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 44%; height: 44%; transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #ffd23f 60%, #e09a00); border: 3px solid #2a1640; box-shadow: 0 4px 10px rgba(0,0,0,.4); }
#btns { position: absolute; right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); width: clamp(170px, 40vmin, 250px); height: clamp(150px, 36vmin, 230px); pointer-events: none; }
.act { position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; border: 3px solid #2a1640; font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 #2a1640; box-shadow: 0 5px 0 #2a1640; display: grid; place-items: center; font-size: clamp(10px, 2.4vmin, 15px); }
.act.pressed { transform: translateY(3px) scale(.95); box-shadow: 0 2px 0 #2a1640; }
.act.blast { right: 0; bottom: 0; width: 48%; aspect-ratio: 1; background: radial-gradient(circle at 35% 30%, #ff9ff0, #c04dff 70%); }
.act.dash { right: 52%; bottom: 0; width: 34%; aspect-ratio: 1; background: radial-gradient(circle at 35% 30%, #9af0ff, #2b8cff 70%); }
.act.super { right: 6%; bottom: 56%; width: 36%; aspect-ratio: 1; background: radial-gradient(circle at 35% 30%, #fff3a0, #9a8a50 70%); filter: grayscale(.7) brightness(.8); }
.act.super.ready { filter: none; background: radial-gradient(circle at 35% 30%, #fff8c0, #ffb21f 70%); animation: superReady .45s ease-in-out infinite alternate; }
@keyframes superReady { to { box-shadow: 0 5px 0 #2a1640, 0 0 24px #ffd23f; transform: scale(1.06); } }

/* Banner & toast */
#banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); pointer-events: none; font-weight: 900; text-align: center; white-space: nowrap;
  font-size: clamp(30px, 10vmin, 92px); color: #fff; -webkit-text-stroke: 3px #2a1640; paint-order: stroke fill; text-shadow: 0 6px 0 #2a1640; opacity: 0; }
#banner.play { animation: bannerPop 1.1s ease-out forwards; }
#banner.go { color: var(--gold); } #banner.win { color: var(--gold); } #banner.lose { color: #ff6b81; }
#banner.warn { color: #ff6b81; font-size: clamp(18px, 5vmin, 44px); white-space: normal; width: 90%; }
#banner.round { color: #b9f3ff; }
@keyframes bannerPop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2) rotate(-6deg); } 18% { opacity: 1; transform: translate(-50%, -50%) scale(.95) rotate(-3deg); }
  28% { transform: translate(-50%, -50%) scale(1.05) rotate(-3deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1) rotate(-3deg); } }
#toast { position: absolute; left: 50%; bottom: calc(14px + var(--sab)); transform: translateX(-50%); background: rgba(20,8,40,.9); border: 2px solid var(--gold); border-radius: 12px;
  padding: .5em 1em; font-weight: 800; font-size: calc(var(--ui) * .9); opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 90%; text-align: center; z-index: 30; }
#toast.show { opacity: 1; }

/* Rotate hint */
#rotate { position: absolute; inset: 0; z-index: 40; background: rgba(12,4,35,.94); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1em; text-align: center; padding: 2em; font-weight: 800; }
.rot-icon { font-size: 64px; animation: rot 1.6s ease-in-out infinite; }
@keyframes rot { 50% { transform: rotate(-90deg); } }

/* Pseudo-fullscreen (fallback khi không hỗ trợ Fullscreen API) */
body.pseudo-fs #app { position: fixed; inset: 0; z-index: 9999; }

/* ---------- Compact (mobile ngang, khung nhỏ) ---------- */
#stage.compact { --ui: clamp(11px, 2.6vmin + 4px, 15px); }
#stage.compact .select-body { gap: .6em; }
#stage.compact .char-grid { gap: .4em; }
#stage.compact .panel { border-radius: 16px; gap: .4em; }
#stage.compact .panel h2 { font-size: calc(var(--ui) * 1.3); }
#stage.compact .stage-card { min-height: 5.2em; padding: .4em .6em; }
#stage.compact .btn { min-height: 2.3em; }
#stage.compact .help ol { font-size: calc(var(--ui) * .88); }
#stage.tiny .logo-l1, #stage.tiny .logo-l2 { font-size: clamp(30px, 13vmin, 60px); }
#stage.tiny .subtitle { display: none; }
#stage.tiny .title-wrap { gap: .45em; }
#stage.tiny .detail-quote { display: none; }
#stage.tiny #detail-cv { height: 26vmin; }
@media (max-aspect-ratio: 1/1) {
  .select-body { flex-direction: column; }
  .char-detail { flex: 0 0 auto; flex-direction: row; }
  #detail-cv { width: 40%; height: 22vh; }
  .stage-grid { grid-template-columns: repeat(2, 1fr); }
}
