:root {
  color-scheme: dark;
  --app-left: 0px;
  --app-top: 0px;
  --app-width: 100vw;
  --app-height: 100vh;
  --bg: #121319;
  --panel: rgba(21, 23, 31, 0.86);
  --panel-strong: rgba(18, 19, 25, 0.94);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f5f0e7;
  --muted: rgba(245, 240, 231, 0.68);
  --gold: #f7bd40;
  --red: #e4514f;
  --green: #77d26f;
  --blue: #61b7ff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-text-size-adjust: 100%;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  user-select: none;
}

#app {
  position: fixed;
  left: var(--app-left);
  top: var(--app-top);
  width: var(--app-width);
  height: var(--app-height);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0)),
    #121319;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #151823;
}

.hidden {
  display: none !important;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.screen--select {
  display: grid;
  grid-template-columns: minmax(220px, 0.82fr) minmax(520px, 1.6fr);
  grid-template-rows: 1fr auto;
  gap: 18px;
  align-items: center;
  background:
    radial-gradient(circle at 18% 18%, rgba(247, 189, 64, 0.18), transparent 34%),
    radial-gradient(circle at 78% 12%, rgba(97, 183, 255, 0.16), transparent 34%),
    linear-gradient(135deg, rgba(8, 9, 13, 0.9), rgba(22, 25, 34, 0.94));
}

.select-copy {
  align-self: center;
  max-width: 430px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: clamp(12px, 1.6vw, 14px);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(40px, 8vw, 86px);
  line-height: 0.95;
}

.summary {
  max-width: 360px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 17px);
  line-height: 1.7;
}

.asset-status {
  min-height: 20px;
  margin: 12px 0 0;
  color: rgba(255, 226, 162, 0.88);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
}

.asset-status.is-ready {
  color: rgba(148, 235, 190, 0.9);
}

.asset-status.is-error {
  color: rgba(255, 122, 122, 0.95);
}

.start-button {
  width: min(260px, 100%);
  min-height: 48px;
  margin-top: 20px;
  padding: 12px 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #ff8f57);
  color: #1b1204;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

.start-button:disabled {
  cursor: default;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.28);
  box-shadow: none;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(138px, 1fr));
  gap: 12px;
  height: min(78vh, 600px);
  min-height: 340px;
}

.character-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0;
  overflow: hidden;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 22%, color-mix(in srgb, var(--accent), transparent 72%), transparent 36%),
    linear-gradient(180deg, #303443, #161922);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  isolation: isolate;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    filter 180ms ease;
}

.character-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image: var(--card-image);
  background-size: var(--card-size, auto 106%);
  background-position: var(--card-position, 25% 50%);
  background-repeat: no-repeat;
  transform: scale(1);
  opacity: 0.96;
  filter: saturate(0.95) contrast(1.03);
}

.character-card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.22) 48%, rgba(0, 0, 0, 0.86)),
    radial-gradient(circle at 50% 25%, rgba(255, 255, 255, 0.12), transparent 34%);
}

.character-card:hover,
.character-card:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent), white 16%);
  outline-offset: 2px;
}

.character-card.is-selected {
  border-color: color-mix(in srgb, var(--accent), white 28%);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--accent), transparent 35%),
    0 24px 70px rgba(0, 0, 0, 0.44);
  transform: translateY(-6px) scale(1.015);
}

.character-card.is-selected::before {
  filter: saturate(1.08) contrast(1.08) brightness(1.08);
}

.character-card.is-selected::after {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.18) 48%, rgba(0, 0, 0, 0.78)),
    radial-gradient(circle at 50% 28%, color-mix(in srgb, var(--accent), transparent 64%), transparent 38%);
}

.character-card.is-selected h3::after {
  content: " 已选";
  color: var(--gold);
  font-size: 0.42em;
  vertical-align: middle;
}

.character-card:disabled {
  cursor: default;
}

.character-card:disabled:not(.is-selected):not(.is-card-ready) {
  filter: saturate(0.68) brightness(0.62);
}

.character-card.is-loading-image::before {
  opacity: 0;
}

.character-card.is-loading-image h3::before {
  content: "Loading ";
  color: rgba(255, 226, 162, 0.78);
  font-size: 0.45em;
  vertical-align: middle;
}

.character-card h3 {
  margin: 0 0 6px;
  font-size: clamp(20px, 3vw, 30px);
  letter-spacing: 0;
}

.character-card p {
  margin: 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  line-height: 1.5;
}

.skill-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.skill-tags span {
  max-width: 100%;
  padding: 5px 7px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  color: rgba(255, 255, 255, 0.86);
  font-size: 11px;
  white-space: nowrap;
}

.hint-bar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  z-index: 12;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.hud-card {
  width: min(42vw, 360px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.25);
}

.enemy-card {
  text-align: right;
}

.fighter-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.fighter-meta span {
  font-size: 17px;
  font-weight: 800;
}

.fighter-meta small {
  color: var(--muted);
  font-size: 11px;
}

.bars {
  display: grid;
  gap: 6px;
}

.bar {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 10px;
  font-weight: 800;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

.bar-track i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e6564f, #ff9865);
  transition: width 120ms linear;
}

.bar-track--energy i {
  background: linear-gradient(90deg, #4ea3ff, #6df0cb);
}

.lyric-overlay {
  position: absolute;
  left: 46%;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 18;
  width: clamp(260px, 34vw, 460px);
  padding: 9px 13px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(12, 14, 20, 0.62);
  color: rgba(255, 244, 214, 0.94);
  font-size: clamp(12px, 1.35vw, 15px);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transform: translateX(-50%);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
}

.touch-controls {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 14;
  display: flex;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
}

.stick,
.actions {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.actions {
  align-items: end;
}

.control-button {
  width: 66px;
  height: 66px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(16, 18, 24, 0.7);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 34px;
  font-weight: 900;
  backdrop-filter: blur(10px);
}

.control-button--small {
  width: 58px;
  height: 58px;
  font-size: 17px;
}

.control-button--skill {
  width: 82px;
  height: 58px;
  border-radius: 999px;
  background: rgba(247, 189, 64, 0.2);
  color: #ffe2a2;
  font-size: 14px;
}

.control-button.is-down {
  transform: translateY(2px) scale(0.98);
  background: rgba(247, 189, 64, 0.28);
}

.control-button.is-cooling {
  color: rgba(255, 255, 255, 0.48);
  background: rgba(16, 18, 24, 0.55);
}

.screen--result {
  display: grid;
  place-items: center;
  background: rgba(7, 8, 11, 0.74);
  backdrop-filter: blur(8px);
}

.screen--result.has-ending {
  place-items: end center;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(5, 6, 10, 0.1), rgba(5, 6, 10, 0.18) 45%, rgba(5, 6, 10, 0.84)),
    var(--result-image) center / cover no-repeat,
    #11131a;
  backdrop-filter: none;
}

.result-panel {
  width: min(520px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.screen--result.has-ending .result-panel {
  width: min(780px, calc(100vw - 28px));
  padding: 20px 22px;
  background: rgba(8, 9, 13, 0.72);
  text-align: left;
}

.result-panel h2 {
  font-size: clamp(32px, 6vw, 54px);
}

.screen--result.has-ending .result-panel h2 {
  font-size: clamp(28px, 4.8vw, 48px);
}

.result-panel p {
  color: var(--muted);
  line-height: 1.7;
}

.screen--result.has-ending .result-panel p {
  max-width: 620px;
  color: rgba(245, 240, 231, 0.86);
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 22px;
}

.screen--result.has-ending .result-actions {
  justify-content: flex-start;
  margin-top: 16px;
}

.primary-button,
.ghost-button {
  min-width: 120px;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  background: var(--gold);
  color: #1c1405;
}

.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
}

.portrait-notice {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(9, 10, 14, 0.92);
  text-align: center;
}

.portrait-notice h2 {
  font-size: 34px;
}

.portrait-notice p {
  color: var(--muted);
}

@media (orientation: portrait) and (max-width: 820px) {
  .portrait-notice {
    display: grid;
  }
}

@media (max-width: 860px) {
  .screen--select {
    grid-template-columns: 190px 1fr;
    gap: 12px;
  }

  h1 {
    font-size: clamp(38px, 6.4vw, 56px);
  }

  .summary {
    margin-top: 12px;
    font-size: 14px;
    line-height: 1.55;
  }

  .asset-status {
    margin-top: 8px;
    font-size: 12px;
  }

  .character-grid {
    gap: 8px;
    min-height: 286px;
  }

  .character-card {
    padding: 10px;
  }

  .lyric-overlay {
    width: clamp(250px, 34vw, 340px);
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 10px));
    font-size: 12px;
  }

  .start-button {
    min-height: 44px;
    margin-top: 12px;
    font-size: 15px;
  }

  .skill-tags span {
    font-size: 10px;
    padding: 4px 6px;
  }

  .control-button {
    width: 58px;
    height: 58px;
  }

  .control-button--small {
    width: 52px;
    height: 52px;
  }

  .control-button--skill {
    width: 74px;
    height: 52px;
  }
}

@media (orientation: landscape) and (max-height: 520px), (pointer: coarse) and (orientation: landscape) {
  .screen {
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .screen--select {
    grid-template-columns: minmax(150px, 0.58fr) minmax(0, 1.7fr);
    gap: 10px;
  }

  .select-copy {
    max-width: 270px;
  }

  .eyebrow {
    margin-bottom: 6px;
    font-size: 12px;
  }

  h1 {
    font-size: 44px;
    line-height: 0.96;
  }

  .summary {
    max-width: 260px;
    margin-top: 10px;
    font-size: 13px;
    line-height: 1.45;
  }

  .asset-status {
    margin-top: 7px;
    font-size: 11px;
    line-height: 1.35;
  }

  .start-button {
    width: min(230px, 100%);
    min-height: 40px;
    margin-top: 12px;
    font-size: 16px;
  }

  .character-grid {
    grid-template-columns: repeat(4, minmax(96px, 1fr));
    gap: 8px;
    height: min(74dvh, 330px);
    min-height: 245px;
  }

  .character-card {
    padding: 9px;
  }

  .character-card h3 {
    margin-bottom: 5px;
    font-size: 22px;
  }

  .skill-tags {
    gap: 5px;
    margin-top: 7px;
  }

  .skill-tags span {
    padding: 4px 6px;
    font-size: 10px;
  }

  .hint-bar {
    font-size: 11px;
  }

  .hud {
    top: max(5px, env(safe-area-inset-top));
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    gap: 8px;
  }

  .hud-card {
    width: min(32vw, 245px);
    padding: 5px 7px;
    border-radius: 7px;
  }

  .fighter-meta {
    margin-bottom: 4px;
  }

  .fighter-meta span {
    font-size: 13px;
  }

  .fighter-meta small {
    font-size: 9px;
  }

  #enemySkill {
    display: none;
  }

  .bars {
    gap: 0;
  }

  .sp-bar {
    display: none;
  }

  .enemy-card .fighter-meta {
    justify-content: flex-start;
  }

  .bar {
    grid-template-columns: 22px 1fr;
    gap: 5px;
    font-size: 9px;
  }

  .bar-track {
    height: 7px;
  }

  .touch-controls {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .stick,
  .actions {
    gap: 8px;
  }

  .control-button {
    width: 54px;
    height: 54px;
    font-size: 30px;
  }

  .control-button--small {
    width: 50px;
    height: 50px;
    font-size: 16px;
  }

  .control-button--skill {
    width: 72px;
    height: 50px;
    font-size: 12px;
  }

  .lyric-overlay {
    left: 45%;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: clamp(230px, 30vw, 310px);
    padding: 8px 11px;
    font-size: 12px;
  }

  .screen--result.has-ending {
    place-items: end start;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background:
      linear-gradient(90deg, rgba(5, 6, 10, 0.72), rgba(5, 6, 10, 0.2) 48%, rgba(5, 6, 10, 0.44)),
      var(--result-image) center / contain no-repeat,
      #08090d;
  }

  .screen--result.has-ending .result-panel {
    width: min(430px, 47vw);
    max-height: calc(var(--app-height) - 18px);
    padding: 12px 14px;
    background: rgba(8, 9, 13, 0.58);
    overflow: hidden;
  }

  .screen--result.has-ending .eyebrow {
    margin-bottom: 5px;
    font-size: 11px;
  }

  .screen--result.has-ending .result-panel h2 {
    font-size: clamp(24px, 3.4vw, 34px);
    line-height: 1.05;
  }

  .screen--result.has-ending .result-panel p {
    margin: 8px 0 0;
    max-width: 100%;
    font-size: 13px;
    line-height: 1.45;
  }

  .screen--result.has-ending .result-actions {
    gap: 8px;
    margin-top: 10px;
  }

  .screen--result.has-ending .primary-button,
  .screen--result.has-ending .ghost-button {
    min-width: 92px;
    padding: 8px 12px;
    font-size: 14px;
  }
}
