:root {
  --ink: #110e24;
  --text: #f8f1ff;
  --muted: #d1c5ef;
  --lavender: #b9a5ff;
  --line: #bba7ff45;
  --surface: #18142de8;
  --panel: #201936;
  --gold: #ffe6aa;
}

html, body {
  color: var(--text);
  background: var(--ink);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body, #game-wrapper {
  touch-action: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  user-select: none;
}
button { font: inherit; touch-action: none; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid #a7edff; outline-offset: 2px; }

.lobby {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(316px, .82fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px 20px;
  overflow: hidden;
  padding: max(12px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 48% 0%, #483979, transparent 72%), #100e24;
}
.lobby-top, .lobby-deck, .dream-hero { min-width: 0; }
.lobby-top { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.brand { font-size: 15px; font-weight: 900; letter-spacing: .11em; }
.brand span { color: var(--gold); text-shadow: 0 0 13px #ffc573; margin-right: 4px; }
.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #cef8e9;
  background: #1c1e3bbd;
  font-size: 12px;
}
.online-pill i { width: 7px; height: 7px; border-radius: 50%; background: #9bf9cd; box-shadow: 0 0 9px #87ffcb; }
.online-pill:has(.disconnected) i { background: #ffd5a1; box-shadow: none; }
.dream-hero {
  position: relative;
  min-height: 0;
  border: 1px solid #c5aaff87;
  border-radius: 19px;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 11px 30px #0406157d, inset 0 0 25px #b39dff26;
  background: #221b48;
}
.dream-hero::before, .dream-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
}
.dream-hero::before { background: url("assets/dream-gate.webp") 66% 50% / cover no-repeat; }
.dream-hero::after {
  background: linear-gradient(0deg, #0c0e26f2, #14102e9c 18%, transparent 45%),
    radial-gradient(ellipse at 5% 95%, #25244bb3, transparent 60%);
}
.hero-content { position: absolute; inset: auto 6% 7%; }
.hero-kicker { margin: 0; color: #e2cdff; font-size: clamp(10px, 1.6vw, 15px); font-weight: 700; letter-spacing: .31em; }
.hero-content h1 {
  margin: 3px 0 2px;
  color: #fff0cc;
  font-family: "STKaiti", "KaiTi", "Noto Serif CJK SC", serif;
  font-size: clamp(44px, 7.7vw, 105px);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: .01em;
  text-shadow: 0 3px 0 #6c4787, 0 0 23px #dda7f9a1, 0 6px 18px #0a0828;
}
.hero-lead { margin: 7px 0 0; color: #eee3fa; font-size: clamp(11px, 1.75vw, 18px); letter-spacing: .08em; }
.dream-motes { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.dream-motes b {
  --time: 5s;
  position: absolute;
  color: #fff3cb;
  font-size: 19px;
  font-weight: 500;
  text-shadow: 0 0 10px #f0c6ff, 0 0 21px #ad96ff;
  animation: drift var(--time) ease-in-out infinite alternate;
}
.dream-motes b:nth-child(1) { left: 14%; top: 29%; }
.dream-motes b:nth-child(2) { left: 34%; top: 41%; --time: 4s; animation-delay: -2s; }
.dream-motes b:nth-child(3) { left: 78%; top: 14%; --time: 6s; animation-delay: -4s; }
.dream-motes b:nth-child(4) { left: 7%; top: 14%; --time: 5.3s; animation-delay: -1s; }
.dream-motes b:nth-child(5) { left: 83%; top: 72%; --time: 4.7s; animation-delay: -2s; }
.dream-motes b:nth-child(6) { left: 47%; top: 11%; --time: 5.7s; animation-delay: -4s; }
@keyframes drift { from { opacity: .24; transform: translateY(8px) scale(.7); } to { opacity: 1; transform: translateY(-10px) scale(1.17); } }

.lobby-deck {
  align-self: center;
  justify-self: center;
  width: min(100%, 600px);
  max-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.7vh, 18px);
  padding: clamp(12px, 2.1vw, 26px);
  border: 1px solid var(--line);
  border-radius: 19px;
  background: linear-gradient(145deg, #30244be5, #18152eea 72%);
  box-shadow: 0 10px 36px #0807187d, inset 0 1px #fcf3ff18;
}
.deck-nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; border-bottom: 1px solid var(--line); }
.deck-nav button {
  position: relative;
  min-width: 0;
  padding: 8px 2px 11px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: clamp(12px, 1.6vw, 16px);
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}
.deck-nav button[aria-pressed="true"] { color: var(--gold); }
.deck-nav button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: auto 11% -1px;
  height: 2px;
  background: #f1d5ff;
  box-shadow: 0 0 9px #dab8ff;
}
.deck-content, .deck-panel { min-height: 0; }
.deck-panel[hidden] { display: none; }
.roster-section { display: grid; gap: 9px; }
.cat-detail, .deck-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.section-kicker { margin: 0 0 3px; color: var(--lavender); font-size: 11px; font-weight: 850; letter-spacing: .12em; }
.cat-info h3 { margin: 0; font-size: clamp(16px, 2.3vw, 27px); color: #fff2e5; font-weight: 900; }
.cat-roster { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cat-card {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #9584bf67;
  border-radius: 9px;
  color: var(--text);
  background: #28203e;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
.cat-card[aria-pressed="true"] { border-color: #ffe19b; box-shadow: 0 0 12px #eec78175, inset 0 0 0 1px #fbe1ad; }
.card-art, .form-art {
  position: relative;
  display: block;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 74%, var(--cat-color), #52518c 63%, #30264f);
}
.card-art { height: clamp(40px, 10vh, 102px); }
.card-art::before, .form-art::before {
  position: absolute;
  content: "";
  inset: 0;
  background: radial-gradient(circle at 14% 24%, #fff8 0 1px, transparent 2px),
    radial-gradient(circle at 83% 38%, #fff9 0 1px, transparent 2px),
    radial-gradient(circle at 71% 14%, #fff8 0 1px, transparent 2px);
}
.card-art canvas, .form-art canvas { position: relative; object-fit: contain; }
.card-form {
  position: absolute;
  z-index: 1;
  right: 4px;
  top: 3px;
  padding: 2px 4px;
  border-radius: 4px;
  background: #1f193cd9;
  color: #f2e5fd;
  font-size: 9px;
  font-weight: 800;
}
.cat-card[aria-pressed="true"] .card-form { background: #ffdfa4; color: #3d254b; }
.cat-card-caption { padding: 3px 4px 4px; display: flex; justify-content: center; align-items: center; }
.cat-card-caption strong { font-size: clamp(11px, 1.5vw, 15px); }
.cat-card-caption small { display: none; }
.form-guide { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.form-card { min-width: 0; margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #30264b; }
.form-art { height: clamp(55px, 16vh, 150px); }
.form-card.is-locked .form-art canvas { filter: saturate(.6); }
.form-card figcaption { padding: 5px 6px 7px; font-size: 12px; text-align: center; }
.form-card figcaption p { margin: 0 0 4px; font-size: 10px; color: var(--muted); }
.form-card figcaption span { margin-left: 3px; white-space: nowrap; }
.form-card figcaption strong { white-space: nowrap; }
.deck-note { color: var(--muted); font-size: 12px; line-height: 1.4; margin: 8px 0 0; }
.controls-grid { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.controls-grid div { border-radius: 9px; background: #352954; border: 1px solid var(--line); padding: 7px 8px; }
.controls-grid dt { color: var(--gold); font-size: 13px; font-weight: 800; }
.controls-grid dd { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.deck-footer { padding-top: 5px; }
#cat-desc { min-width: 0; color: var(--muted); font-size: clamp(10px, 1.35vw, 13px); line-height: 1.4; }
.lobby:not([data-panel="roster"]) #cat-desc { visibility: hidden; }
.poster-button, .secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #c6aaff8e;
  border-radius: 10px;
  padding: 10px 15px;
  min-height: 41px;
  background: linear-gradient(125deg, #e2cfff, #ab99fc 79%);
  color: #241839;
  box-shadow: inset 0 1px #fff9, 0 0 16px #c29cff65;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .15s, filter .15s;
}
.poster-button:hover, .secondary-button:hover { filter: brightness(1.13); }
.poster-button:active, .secondary-button:active { transform: scale(.96); }
.poster-button:disabled { opacity: .65; cursor: wait; }
.secondary-button { color: var(--text); background: #312549; box-shadow: none; }
.secondary-button.compact { min-height: 31px; padding: 4px 9px; font-size: 12px; }
kbd { font: 700 10px/1.3 system-ui, sans-serif; border: 1px solid currentColor; border-radius: 3px; padding: 2px 4px; }

.result-overlay { overflow: hidden; padding: 9px; background: #15122aa6; backdrop-filter: blur(5px); }
.result-overlay .card {
  max-width: 490px;
  max-height: 100%;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 0%, #4c3076, transparent 69%), #201831;
  border: 1px solid #c9a9fb99;
  border-radius: 20px;
  box-shadow: 0 0 31px #b47deb4d, 0 14px 40px #0a0922a6;
  padding: clamp(10px, 3vh, 22px);
}
.result-overlay .game-title { background: linear-gradient(90deg, #fff2be, #f7deff, #cec0ff); -webkit-background-clip: text; font-size: clamp(23px, 4.8vh, 39px); }
.result-overlay .subtitle { margin-bottom: 7px; }
.result-actions { display: flex; justify-content: center; gap: 8px; }
.stats-row { margin: 9px 0; gap: 7px; }
.stat-box { padding: 6px; }
.stat-box .num { color: #ffe4ac; }
.victory-cat { height: clamp(74px, 19vh, 155px); object-fit: contain; background: radial-gradient(ellipse, #7450a9, #362355 66%); border-radius: 12px; }
.evolution-scene {
  height: clamp(83px, 31vh, 220px);
  position: relative;
  margin: 8px 0 4px;
  background: radial-gradient(ellipse at center, var(--evolution-color, #ae90e6), #453788 67%, #241c50);
  border: 1px solid #e4ccffa3;
  border-radius: 14px;
  overflow: hidden;
  isolation: isolate;
}
.evolution-scene canvas, .evolution-rays, .evolution-ring, .evolution-flash { position: absolute; inset: 0; margin: auto; }
.evolution-scene canvas { object-fit: contain; filter: drop-shadow(0 5px 0 #171c1970); }
#evolution-before { opacity: 0; }
.evolution-rays { inset: -110%; background: repeating-conic-gradient(from 1deg, #ffffff40 0deg 5deg, transparent 7deg 19deg); }
.evolution-ring { inset: auto 0 11%; width: 52%; height: 29%; border: 2px solid #fff2b3; border-radius: 50%; box-shadow: 0 0 24px #ffdf99; }
.evolution-flash { pointer-events: none; opacity: 0; background: #fffdf7; }
.spark { position: absolute; color: #ffefae; font-size: 34px; text-shadow: 0 0 12px #fff; }
.spark-a { left: 15%; top: 12%; }
.spark-b { right: 17%; top: 15%; font-size: 44px; }
.spark-c { right: 11%; bottom: 12%; font-size: 22px; }
.evolution-scene.is-revealing #evolution-before { animation: form-before .95s both; }
.evolution-scene.is-revealing #evolution-after { animation: form-after 1.55s both; }
.evolution-scene.is-revealing .evolution-flash { animation: form-flash 1.25s both; }
.evolution-scene.is-revealing .evolution-rays { animation: rays-turn 1.7s both; }
.evolution-scene.is-revealing .spark { animation: spark-pop 1.45s both; }
.evolution-caption h3 { font-size: clamp(16px, 3.5vh, 24px); margin: 0; font-weight: 900; }
.evolution-caption p { margin: 2px 0 6px; color: var(--muted); font-size: 11px; }
#evolution-level { color: var(--gold); font-size: clamp(12px, 3vh, 20px); font-weight: 900; letter-spacing: .09em; }
@keyframes form-before { 0%, 35% { opacity: 1; transform: scale(.86); } 88% { opacity: 1; transform: scale(1.06); filter: brightness(3); } to { opacity: 0; } }
@keyframes form-after { 0%, 53% { opacity: 0; transform: scale(.7); } 72% { opacity: 1; transform: scale(1.16); } to { transform: scale(1); } }
@keyframes form-flash { 0%, 52%, 100% { opacity: 0; } 66% { opacity: .77; } 81% { opacity: .05; } }
@keyframes rays-turn { from { transform: rotate(-35deg) scale(.65); opacity: .55; } to { transform: rotate(12deg); opacity: 1; } }
@keyframes spark-pop { 0%, 51% { transform: scale(0); opacity: 0; } 79% { transform: scale(1.5) rotate(20deg); } to { transform: scale(1); opacity: 1; } }

#hud {
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(9px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.pill, .mute-btn, .skill-btn, .skill-btn.ready, .buff-badge {
  background: #1c1b3ae8;
  color: #fbf1ff;
  border: 1px solid #c7adff90;
  border-radius: 9px;
  box-shadow: 0 3px 11px #15133177, inset 0 1px #ffffff28;
  backdrop-filter: none;
}
.hud-top { align-items: center; }
.timer-pill { background: #2d2857; color: #ffe6b3; font-size: 20px; line-height: 1.15; }
.timer-pill.open { background: #27596a; color: #b8fff2; }
.timer-pill.urgent { background: #703754; color: #ffe4cc; }
.hud-sub { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 5px; margin-top: 6px; }
.hud-sub .pill, .buff-badge { padding: 4px 8px; font-size: 11px; }
.hud-cat { color: #f1dfff; }
.hud-phase { color: #ffe2a0; }
.hud-online { color: #aaf7e3; }
.hud-sub .buffs-bar { margin: 0; }
#btn-arena-lobby { width: auto; padding-inline: 8px; font-size: 11px; font-weight: 800; }
.skill-btn, .skill-btn.ready {
  --skill-color: #7f73e3;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 26%, var(--skill-color), #332251 68%);
}
.skill-btn.ready:nth-child(2) { --skill-color: #c16ba9; }
.skill-btn.ready:nth-child(3) { --skill-color: #477db9; }
.skill-btn.ready[data-tier="1"] { border-color: #c8bbff; box-shadow: 0 0 14px #a895fba0, inset 0 1px #fff8; }
.skill-btn.ready[data-tier="2"] { border-color: #ffe2a1; box-shadow: 0 0 19px #ffd68fa0, inset 0 0 12px #fdbc8fa1; }
.skill-btn .skill-key { color: #ffead3; }
.skill-cd-mask { background: #191429da; }
#portal-banner, .stage-toast-inner {
  color: #fff0cb;
  border: 1px solid #d5aeff;
  border-radius: 12px;
  background: linear-gradient(126deg, #2a2149f5, #45316bf2, #271e4cf5);
  box-shadow: 0 0 22px #b17dff7d;
}
#portal-banner { top: 78px; }
.stage-toast-inner { margin: 10px; padding: 11px 20px; }
.stage-toast-inner h2 { color: #fff0ce; font-size: clamp(17px, 4.1vh, 27px); }
.stage-toast-inner p { color: #f1ddff; font-size: clamp(11px, 2.5vh, 14px); }
.stage-toast-inner .chapter-label { color: #d3b2ff; margin-bottom: 4px; font-size: 10px; letter-spacing: .13em; }
#skill-bar, #joystick-zone { bottom: max(14px, env(safe-area-inset-bottom)); }
#skill-bar { right: max(14px, env(safe-area-inset-right)); }
#joystick-zone { left: max(14px, env(safe-area-inset-left)); border-color: #d0aeff9c; background: #30215f68; }
#joystick-knob { background: radial-gradient(circle at 38% 28%, #fff2ff, #b79aff 49%, #6656ac); }

@media (orientation: portrait) {
  .lobby { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(100px, 1fr) auto; padding-inline: max(12px, env(safe-area-inset-left)); gap: 8px; }
  .lobby-deck { justify-self: stretch; align-self: end; width: 100%; gap: 9px; }
  .dream-hero::before { background-position: 61% 46%; }
  .hero-content { inset: auto 5% 6%; }
  .hero-content h1 { font-size: clamp(33px, 12vw, 64px); }
  .card-art { height: clamp(38px, 8.5vh, 89px); }
}
@media (orientation: landscape) and (max-height: 550px) {
  .lobby { grid-template-columns: minmax(0, 1fr) minmax(270px, .94fr); padding-block: max(6px, env(safe-area-inset-top)) max(7px, env(safe-area-inset-bottom)); gap: 6px 10px; }
  .lobby-deck { padding: 8px 11px; gap: 5px; }
  .deck-nav button { padding: 4px 2px 6px; }
  .roster-section { gap: 5px; }
  .cat-roster { gap: 5px; }
  .card-art { height: clamp(31px, 11vh, 56px); }
  .cat-card-caption { padding-block: 2px; }
  .hero-content h1 { font-size: clamp(32px, 8vw, 68px); }
  .deck-footer { padding-top: 2px; }
  .poster-button { min-height: 34px; padding: 5px 10px; }
  #joystick-zone { width: 92px; height: 92px; }
  #joystick-knob { width: 40px; height: 40px; margin: -20px; }
  .touch-hint { display: none; }
  .result-overlay .game-title { margin-bottom: 3px; }
}
@media (max-width: 500px) {
  #hud { padding-inline: 7px; }
  .hud-top, .hud-group { gap: 4px; }
  .pill, .timer-pill { padding: 5px 6px; }
  .timer-pill { font-size: 15px; }
  .mute-btn { width: 30px; height: 30px; }
  #portal-banner { top: 102px; max-width: calc(100% - 15px); font-size: 11px; }
}
@media (orientation: portrait) and (max-height: 690px) {
  .lobby-deck { padding: 7px 10px; gap: 4px; }
  .deck-nav button { padding-block: 5px; }
  .roster-section { gap: 5px; }
  .cat-roster { gap: 5px; }
  .card-art { height: clamp(32px, 8vh, 55px); }
  .deck-footer { padding-top: 1px; }
  .poster-button { min-height: 35px; padding: 5px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
