*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: #060a10;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 12px;
  font-family: 'Segoe UI', 'Malgun Gothic', sans-serif;
  color: #e0e6f0;
  -webkit-tap-highlight-color: transparent;
}

/* Layout */

.game-wrapper {
  width: fit-content;
  max-width: 100%;
}

.game-container {
  position: relative;
  z-index: 1;
  width: 640px;
  max-width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  overflow: visible;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}

canvas {
  display: block;
  visibility: hidden; /* Hide canvas outside battle. */
  background: transparent;
  touch-action: none;
  user-select: none;
}

.game-container:has(#hud:not(.hidden)) canvas {
  visibility: visible;
}

/* Overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(10, 14, 22, 0.75);
  backdrop-filter: blur(2px);
  padding: 24px 20px 60px;
}

.overlay.hidden { display: none; }

#settingsScreen {
  position: fixed;
  inset: 0;
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;
  padding: 20px 32px 16px;
  gap: 10px;
}

/* Title Screen */

#titleScreen {
  position: fixed;
  inset: 0;
  backdrop-filter: none;
  gap: 1.6vh;
  padding: 4vh 2.8vh 4vh;
}

.title-loading-content {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.title-loading-spinner {
  width: 54px;
  height: 54px;
  border: 5px solid rgba(255,255,255,0.18);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: title-loading-spin 0.82s linear infinite;
}

.title-loading-message {
  max-width: min(82vw, 420px);
  color: rgba(232, 240, 255, 0.9);
  font-size: clamp(0.86rem, 2.6vw, 1rem);
  font-weight: 800;
  line-height: 1.45;
  text-shadow: 0 2px 14px rgba(0,0,0,0.65);
}

@keyframes title-loading-spin {
  to { transform: rotate(360deg); }
}

.game-container:has(#titleScreen:not(.hidden)) {
  border-color: transparent;
  box-shadow: none;
  background: transparent;
}

.title-main-logo {
  position: relative;
  width: min(50vw, 87vh);
  max-height: 30vh;
  object-fit: contain;
  margin-bottom: 0.8vh;
  animation: logo-thump 0.75s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
  transform-origin: center bottom;
}

#titleScreen.title-loading .title-main-logo,
#titleScreen.title-loading .title-mode-select,
#titleScreen.title-loading #openCharacterEditorBtn,
#titleScreen.title-loading #openHelpPanelBtn,
#titleScreen.title-loading #openOfficialVersionBtn,
#titleScreen.title-loading #titleInfo {
  opacity: 0;
  pointer-events: none;
}

#titleScreen.title-ui-visible .title-main-logo,
#titleScreen.title-ui-visible .title-mode-select,
#titleScreen.title-ui-visible #openCharacterEditorBtn,
#titleScreen.title-ui-visible #openHelpPanelBtn,
#titleScreen.title-ui-visible #openOfficialVersionBtn,
#titleScreen.title-ui-visible #titleInfo {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.28s ease-out;
}

#titleScreen:not(.title-loading) .title-loading-content {
  display: none;
}

@keyframes logo-thump {
  0%   { transform: scale(1)    translateY(0);   }
  8%   { transform: scale(1.02) translateY(-5px); }
  18%  { transform: scale(0.99) translateY(3px);  }
  28%  { transform: scale(1.03) translateY(-1px); }
  38%, 100% { transform: scale(0.98) translateY(0);  }
}

#titleScreen .title-mode-select {
  position: relative;
  margin-top: 0.8vh;
  gap: 0.9vh;
  width: min(32vw, 57vh);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#titleScreen > * {
  position: relative;
}

/* Title mode button styling. */
#titleScreen .mode-btn {
  aspect-ratio: 2 / 1;
  min-height: 0;
  gap: 0.55vh;
  padding: 0.9vh;
  background: rgba(12, 20, 36, 0.82);
  border-color: rgba(255,255,255,0.28);
  color: #e8f0ff;
  backdrop-filter: blur(4px);
}

#titleScreen .mode-title {
  font-size: min(2.7vh, 1.55vw);
}

#titleScreen .mode-desc {
  font-size: min(1.9vh, 1.1vw);
}

#titleScreen .mode-btn:hover {
  background: rgba(20, 35, 60, 0.92);
  border-color: rgba(255,255,255,0.45);
}

#titleScreen .mode-btn.active {
  background: rgba(79,195,247,0.28);
  border-color: rgba(79,195,247,0.8);
}

#titleScreen .title-info {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 8;
}

.title-info-btn {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 50%;
  background: rgba(10, 16, 28, 0.58);
  color: rgba(238,246,255,0.9);
  font: 700 14px/1 'Segoe UI', sans-serif;
  cursor: default;
  backdrop-filter: blur(5px);
}

.title-info-panel {
  position: absolute;
  top: 31px;
  right: 0;
  min-width: 184px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 6px;
  background: rgba(5, 9, 16, 0.9);
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
  color: #dbe7f6;
  font-size: 12px;
  line-height: 1.55;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  white-space: pre-line;
}

.title-info:hover .title-info-panel,
.title-info:focus-within .title-info-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.title-info-status {
  font-weight: 800;
}

.title-info-line {
  color: #b8c7d9;
}

/* Title secondary button styling. */
#titleScreen .btn.secondary {
  background: rgba(12, 20, 36, 0.82);
  border-color: rgba(255,255,255,0.3);
  color: #dce8ff;
  backdrop-filter: blur(4px);
  min-width: min(15vw, 27vh);
  padding: 1.25vh 2.6vh;
  font-size: min(2.35vh, 1.35vw);
}

.language-setting {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #8a9bbb;
  font-size: 0.78rem;
}

.language-setting select {
  min-height: 32px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: rgba(6,10,16,0.72);
  color: #e0e6f0;
  font-family: inherit;
  padding: 4px 8px;
}

/* Settings Screen */

.screen-title {
  flex-shrink: 0;
  font-size: clamp(1rem, 3vw, 1.3rem);
  color: #c8d8f0;
  letter-spacing: 0.04em;
}

.mode-select {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 520px);
}

.mode-btn {
  min-height: 72px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: #c8d8f0;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.mode-btn:hover {
  background: rgba(255,255,255,0.11);
  border-color: rgba(255,255,255,0.24);
}

.mode-btn:active { transform: scale(0.98); }

.mode-btn.active {
  background: rgba(79,195,247,0.16);
  border-color: rgba(79,195,247,0.7);
  box-shadow: inset 0 0 0 1px rgba(79,195,247,0.18);
}

.mode-title {
  font-size: 1.05rem;
  font-weight: 900;
  color: #e0e6f0;
  white-space: nowrap;
}

.mode-desc {
  font-size: 0.82rem;
  color: #8a9bbb;
  text-align: center;
  line-height: 1.2;
}

.official-version-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.official-version-logo {
  width: 1.2em;
  height: 1.2em;
  object-fit: contain;
  flex-shrink: 0;
}

.mode-help {
  display: none;
}

.battle-setting-row {
  flex-shrink: 0;
  display: inline-grid;
  grid-template-columns: auto 86px auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: #c8d8f0;
  font-size: 0.82rem;
  font-weight: 800;
}

.battle-setting-row input {
  min-width: 0;
  height: 28px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(6,10,16,0.72);
  color: #e0e6f0;
  font-family: inherit;
  font-weight: 900;
  text-align: center;
  padding: 3px 6px;
}

.battle-setting-row input:focus {
  outline: none;
  border-color: rgba(79,195,247,0.75);
  box-shadow: 0 0 0 2px rgba(79,195,247,0.14);
}

.image-setup {
  width: min(100%, 560px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
}

.image-setup h3 {
  font-size: 0.82rem;
  color: #c8d8f0;
  text-align: center;
  margin-bottom: 8px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.image-card {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  background: rgba(6,10,16,0.35);
  padding: 8px;
}

.image-card-title {
  font-size: 0.76rem;
  font-weight: 800;
  color: #e0e6f0;
  text-align: center;
  margin-bottom: 7px;
}

.image-slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.image-card[data-type="charger"] .image-slots {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.image-slot {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #8a9bbb;
  font-size: 0.82rem;
  cursor: pointer;
}

.image-slot input,
.sound-upload-target input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.image-preview {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px dashed rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.06);
  color: #8a9bbb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  overflow: hidden;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.image-preview.loaded {
  border-style: solid;
  color: transparent;
}

.sound-slot {
  grid-column: 1 / -1;
  cursor: default;
}

.sound-edit-controls {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.sound-upload-target {
  position: relative;
  min-width: 0;
  display: block;
  cursor: pointer;
}

.sound-preview.loaded {
  width: 100%;
  min-height: 34px;
  color: #c8d8f0;
  font-size: 0.86rem;
  font-weight: 800;
}

.editor-sound-play {
  min-height: 34px;
}

.preset-editor {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 20px 24px;
  z-index: 120;
}

.preset-editor-layout {
  width: min(100%, calc(420px + 134vh + 18px));
  max-height: calc(100vh - 88px);
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 18px;
  min-height: 0;
}

.preset-type-tabs {
  width: min(100%, 420px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
  position: relative;
}


.preset-type-btn {
  min-height: 86px;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: #c8d8f0;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 5px;
}

.preset-type-btn.active {
  background: rgba(79,195,247,0.16);
  border-color: rgba(79,195,247,0.7);
  color: #e0e6f0;
}

.preset-type-art {
  width: 48px;
  height: 48px;
  font-size: 1.35rem;
}

.preset-editor-main {
  width: 420px;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preset-editor-page.hidden {
  display: none;
}

.preset-editor-tab-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(6,10,16,0.45);
}

.preset-editor-tab {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #8a9bbb;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 900;
  cursor: pointer;
}

.preset-editor-tab:hover {
  background: rgba(255,255,255,0.07);
  color: #c8d8f0;
}

.preset-editor-tab.active {
  background: rgba(79,195,247,0.16);
  border-color: rgba(79,195,247,0.56);
  color: #e0e6f0;
}

.preset-sandbox-settings-btn {
  width: 100%;
}

.battle-setting-row input[type="number"]::-webkit-inner-spin-button,
.battle-setting-row input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.preset-sandbox-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sandbox-setting-row {
  width: 100%;
  grid-template-columns: 82px 86px 58px 52px;
  justify-content: start;
}

.sandbox-setting-value {
  min-width: 52px;
  color: #b9f6ca;
  text-align: right;
  font-weight: 900;
}

.sandbox-stepper {
  display: inline-grid;
  grid-template-columns: repeat(2, 26px);
  gap: 4px;
}

.sandbox-step-btn {
  width: 26px;
  height: 28px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(6,10,16,0.72);
  color: #c8d8f0;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}

.sandbox-step-btn:hover {
  border-color: rgba(79,195,247,0.72);
  background: rgba(79,195,247,0.12);
  color: #e0e6f0;
}

.sandbox-step-btn:active {
  border-color: rgba(185,246,202,0.8);
  background: rgba(185,246,202,0.12);
  color: #f4fff7;
}

.preset-character-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preset-preview-panel {
  align-self: center;
  flex: 0 0 auto;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#presetPreviewCanvas {
  display: block;
  visibility: visible;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  max-width: 100%;
  max-height: 75vh;
}

.preset-preview-actions {
  display: flex;
  justify-content: center;
  width: 100%;
}

.stage-editor-panel {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage-editor-title {
  color: #c8d8f0;
  font-size: 0.88rem;
  font-weight: 900;
}

.stage-asset-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.10);
}

.stage-asset-section.hidden {
  display: none;
}

.stage-asset-section:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.stage-asset-title {
  color: #8a9bbb;
  font-size: 0.74rem;
  font-weight: 900;
}

.stage-preset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.stage-preset-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(6,10,16,0.45);
  padding: 8px;
  cursor: pointer;
}

.stage-preset-wrap.active {
  border-color: rgba(79,195,247,0.78);
  background: rgba(79,195,247,0.13);
}

.stage-preset-preview {
  position: relative;
  display: block;
}

.stage-card-name-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.stage-preset-art {
  position: relative;
  width: 54px;
  height: 38px;
  font-size: 1.2rem;
  background-size: cover;
  background-position: center;
}

.stage-preset-art-arena {
  width: 42px;
  height: 42px;
}

.stage-default-art {
  background: #14284d;
}

.stage-card-name-input {
  min-width: 0;
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(6,10,16,0.5);
  color: #e0e6f0;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preset-name-field input {
  width: 100%;
  min-height: 34px;
  border: 1px dashed rgba(255,213,79,0.45);
  border-radius: 8px;
  background: rgba(6,10,16,0.7);
  color: #e0e6f0;
  font-family: inherit;
  padding: 6px 9px;
}

.preset-name-field input:focus {
  outline: none;
  border-color: rgba(255,213,79,0.85);
  box-shadow: 0 0 0 2px rgba(255,213,79,0.12);
}

.preset-name-field input:disabled {
  cursor: default;
  opacity: 0.72;
  border-style: solid;
}

.preset-icon-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.preset-edit-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.preset-edit-action {
  min-height: 34px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(6,10,16,0.72);
  color: #c8d8f0;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 900;
  cursor: pointer;
}

.preset-edit-action:hover:not(:disabled) {
  border-color: rgba(79,195,247,0.72);
  background: rgba(79,195,247,0.12);
  color: #e0e6f0;
}

.preset-edit-action:disabled {
  cursor: default;
  opacity: 0.42;
}

.preset-edit-toggle.active {
  border-color: rgba(185,246,202,0.72);
  background: rgba(185,246,202,0.12);
  color: #d7ffe2;
}

.preset-edit-delete {
  color: #ffb4b4;
}

.add-preset-portrait {
  border-style: dashed;
  border-color: rgba(255,213,79,0.42);
  background: rgba(255,213,79,0.055);
}

.preset-portrait-wrap {
  position: relative;
}

.preset-portrait-wrap .preset-portrait {
  width: 100%;
}

.preset-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(239, 68, 68, 0.75);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 1;
}

.preset-portrait-wrap:hover .preset-delete-btn {
  opacity: 1;
}

.preset-delete-btn:hover {
  background: rgba(239, 68, 68, 1);
}

.add-preset-portrait:hover,
.add-preset-portrait:focus-visible {
  border-color: rgba(255,213,79,0.82);
  background: rgba(255,213,79,0.11);
}

.add-preset-art {
  border-style: dashed;
  border-color: rgba(255,213,79,0.5);
  color: #ffe082;
  font-size: 1.6rem;
  font-weight: 900;
}

.preset-name-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: #8a9bbb;
  font-size: 0.88rem;
}

.preset-image-slots {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
  gap: 8px;
}

.preset-image-slots .image-slot {
  border: 1px dashed rgba(255,213,79,0.38);
  border-radius: 8px;
  background: rgba(255,213,79,0.035);
  padding: 8px 6px;
}

.preset-image-slots .image-slot.locked {
  cursor: default;
  opacity: 0.72;
  border-style: solid;
}

.preset-image-slots .image-slot:not(.sound-slot)::after,
.sound-upload-target::after {
  content: "^";
  position: absolute;
  top: 5px;
  right: 6px;
  width: 17px;
  height: 17px;
  border-radius: 999px;
  background: rgba(255,213,79,0.16);
  border: 1px solid rgba(255,213,79,0.42);
  color: #ffe082;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 900;
  pointer-events: none;
  transform: rotate(90deg);
}

.preset-image-slots .image-slot.locked:not(.sound-slot)::after,
.sound-upload-target.locked::after {
  display: none;
}

.preset-image-slots .image-slot:not(.sound-slot):hover,
.preset-image-slots .image-slot:not(.sound-slot):focus-within,
.preset-image-slots .image-slot.drop-over,
.sound-upload-target.drop-over,
.sound-upload-target:hover,
.sound-upload-target:focus-within {
  border-color: rgba(255,213,79,0.8);
  background: rgba(255,213,79,0.08);
}

.preset-image-slots .image-slot.drop-over {
  border-style: solid;
  box-shadow: inset 0 0 0 1px rgba(255,213,79,0.38), 0 0 0 2px rgba(255,213,79,0.10);
}

.preset-image-slots .image-slot.locked:hover,
.preset-image-slots .image-slot.locked:focus-within,
.sound-upload-target.locked:hover,
.sound-upload-target.locked:focus-within {
  border-color: rgba(255,213,79,0.38);
  background: rgba(255,213,79,0.035);
}

.sound-upload-target:hover .sound-preview,
.sound-upload-target:focus-within .sound-preview {
  border-color: rgba(255,213,79,0.8);
}

.confirm-panel {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.58);
  backdrop-filter: blur(3px);
}

.confirm-panel.hidden {
  display: none;
}

.confirm-panel-content {
  width: min(100%, 360px);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: rgba(10,14,22,0.96);
  box-shadow: 0 18px 48px rgba(0,0,0,0.56);
  padding: 18px;
}

.confirm-panel-message {
  color: #e0e6f0;
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1.45;
  text-align: center;
  overflow-wrap: anywhere;
}

.confirm-panel-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.confirm-panel-btn {
  min-height: 36px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  background: rgba(6,10,16,0.72);
  color: #c8d8f0;
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
}

.confirm-panel-yes {
  border-color: rgba(239,83,80,0.56);
  color: #ffd0d0;
}

.confirm-panel-no {
  border-color: rgba(79,195,247,0.46);
}

.confirm-panel-btn:hover,
.confirm-panel-btn:focus-visible {
  outline: none;
  background: rgba(255,255,255,0.1);
}

.duel-character-select {
  width: min(100%, 600px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.duel-roster-section {
  flex-shrink: 0;
  max-height: 25vh;
  overflow-y: auto;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
  margin-top: 8px;
  position: relative;
}

.settings-picker-row {
  flex-shrink: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(190px, 240px);
  gap: 12px;
  align-items: stretch;
  overflow: visible;
}

.settings-duel-picker-row {
  grid-template-columns: minmax(190px, 240px) minmax(260px, 1fr) minmax(190px, 240px);
}

.settings-picker-row .duel-roster-section {
  margin-top: 0;
}

.settings-stage-balance-space {
  min-width: 0;
  pointer-events: none;
}

.settings-stage-panel {
  position: relative;
  overflow: visible;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
  padding: 10px;
  justify-content: center;
}

.settings-stage-panel .stage-editor-title {
  font-size: 0.78rem;
}

.settings-stage-select {
  min-width: 0;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.settings-stage-label {
  color: #8a9bbb;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.settings-stage-dropdown {
  position: relative;
  min-width: 0;
}

.settings-stage-trigger,
.settings-stage-option {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(6,10,16,0.56);
  color: #c8d8f0;
  font-family: inherit;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  font-size: 0.78rem;
}

.settings-stage-trigger::after {
  content: "^";
  justify-self: end;
  color: #8a9bbb;
  font-weight: 900;
}

.settings-stage-trigger {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.settings-stage-trigger:hover,
.settings-stage-option:hover,
.settings-stage-option.active {
  border-color: rgba(79,195,247,0.72);
  background: rgba(79,195,247,0.12);
  color: #e0e6f0;
}

.settings-stage-current,
.settings-stage-option-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.settings-stage-dropdown-menu {
  position: absolute;
  z-index: 80;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  display: none;
  max-height: min(42vh, 330px);
  overflow-y: auto;
  gap: 5px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: rgba(8,12,20,0.98);
  box-shadow: 0 -16px 32px rgba(0,0,0,0.42);
}

.settings-stage-dropdown.open .settings-stage-dropdown-menu {
  display: grid;
}

.settings-stage-panel .stage-preset-art {
  width: 34px;
  height: 24px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.settings-stage-panel .stage-preset-art-arena {
  width: 28px;
  height: 28px;
}

.roster-section-label {
  position: absolute;
  top: -9px;
  left: 10px;
  padding: 0 7px;
  background: #0d1117;
  color: #8a9bbb;
  font-size: 0.62rem;
  font-weight: 900;
  pointer-events: none;
}

.duel-roster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.duel-roster-title {
  font-size: 0.9rem;
  color: #e0e6f0;
}

.duel-main-roster .portrait-art {
  width: clamp(40px, 5vw, 58px);
  height: clamp(40px, 5vw, 58px);
  font-size: clamp(1rem, 2vw, 1.65rem);
}

.duel-vs-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  font-size: clamp(1.2rem, 3vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #fff;
  text-shadow: 0 0 32px rgba(255,255,255,0.5), 0 0 12px rgba(79,195,247,0.45);
  padding: 0 4px;
  user-select: none;
}

.duel-character-select {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.duel-selection-panels {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: 1fr;
  align-items: stretch;
  gap: 16px;
}

.duel-character-select.hidden { display: none; }

.duel-select-side {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  background: rgba(255,255,255,0.035);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.duel-select-side[data-team="blue"] { border-color: rgba(79,195,247,0.45); }
.duel-select-side[data-team="red"] { border-color: rgba(239,83,80,0.45); }

.duel-side-title {
  font-size: 1.15rem;
  color: #e0e6f0;
  text-align: center;
}

.fighter-roster {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.fighter-portrait,
.preset-portrait {
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(6,10,16,0.45);
  color: #c8d8f0;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 9px 7px;
  touch-action: manipulation;
}

.fighter-portrait:disabled {
  cursor: default;
  opacity: 0.45;
}

.preset-portrait.locked {
  border-style: solid;
}

.fighter-portrait.active,
.preset-portrait.active {
  border-color: rgba(79,195,247,0.78);
  background: rgba(79,195,247,0.13);
  color: #e0e6f0;
}

.portrait-art {
  width: 62px;
  height: 62px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.82rem;
}

.portrait-name {
  width: 100%;
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fighter-panel {
  flex: 1;
  min-height: 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  overflow-y: auto;
}

.fighter-empty {
  min-height: clamp(60px, 15vh, 211px);
  border: 1px dashed rgba(255,255,255,0.14);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8a9bbb;
  font-size: 1rem;
  text-align: center;
  padding: 16px;
}

.fighter-panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-remove-btn {
  margin-left: auto;
  border: 1px solid rgba(239,83,80,0.45);
  border-radius: 6px;
  background: rgba(239,83,80,0.12);
  color: #ffcdd2;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  padding: 7px 11px;
}

.fighter-panel-title {
  min-width: 0;
}

.fighter-panel-name {
  font-size: 1.16rem;
  font-weight: 900;
  color: #e0e6f0;
}

.fighter-panel-preset {
  margin-top: 3px;
  font-size: 0.92rem;
  color: #8a9bbb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-section {
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 8px;
  background: rgba(6,10,16,0.24);
  padding: 11px;
}

.profile-section-title {
  flex-shrink: 0;
  margin-bottom: 8px;
  color: #c8d8f0;
  font-size: 0.86rem;
  font-weight: 900;
}

.profile-image-section {
  flex-shrink: 0;
  border-color: rgba(79,195,247,0.18);
}

.profile-sound-section {
  flex-shrink: 0;
  border-color: rgba(255,213,79,0.18);
}

.profile-preset-section {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
  border-color: rgba(171,71,188,0.18);
}

.preset-preview-row {
  display: flex;
  gap: 8px;
}

.preset-preview-slot {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: #8a9bbb;
  font-size: 0.84rem;
}

.preset-preview-slot .image-preview {
  width: 51px;
  height: 51px;
}

.preset-sound-preview {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 8px;
}

.preset-sound-label {
  color: #8a9bbb;
  font-size: 0.84rem;
  white-space: nowrap;
}

.preset-sound-file {
  min-width: 0;
  min-height: 41px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #c8d8f0;
  display: flex;
  align-items: center;
  padding: 7px 11px;
  font-size: 0.92rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-sound-play {
  min-height: 41px;
  border: 1px solid rgba(79,195,247,0.45);
  border-radius: 8px;
  background: rgba(79,195,247,0.12);
  color: #d7f1ff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 900;
  padding: 7px 12px;
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 8px;
}

.settings-duel .teams {
  display: none;
}

.teams {
  display: flex;
  align-items: center;
  gap: 12px;
}

.team-card {
  min-height: 0;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 22px 27px;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.team-card h3 {
  font-size: 1.28rem;
  text-align: center;
  color: #c8d8f0;
}

.royale-setup {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.royale-setup.hidden { display: none; }

.royale-setup h3 {
  font-size: 1.28rem;
  text-align: center;
  color: #c8d8f0;
}

.royale-profile-list {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(415px, 1fr));
  grid-template-rows: minmax(294px, 1fr);
  gap: 8px;
  overflow: auto;
}

.royale-profile-list > .fighter-empty {
  grid-column: 1 / -1;
}

.royale-profile-card {
  min-height: 0;
}

.team-character-select {
  flex: 1;
  min-height: 0;
  width: 100%;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

.team-selection-panels {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: 1fr;
  align-items: stretch;
  gap: 16px;
  overflow: hidden;
}

.team-select-panel {
  min-width: 0;
  cursor: pointer;
}

.team-select-panel.active {
  background: rgba(79,195,247,0.10);
  border-color: rgba(79,195,247,0.75);
  box-shadow: inset 0 0 0 1px rgba(79,195,247,0.18);
}

.team-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.team-profile-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.settings-duel .team-card {
  min-width: 160px;
}

.settings-duel .team-card h3 {
  color: #e0e6f0;
}

.settings-duel .blue-card { border-color: rgba(79,195,247,0.55); }
.settings-duel .red-card  { border-color: rgba(239,83,80,0.55); }

.settings-royale .teams { display: none; }

.blue-card { border-color: rgba(79,195,247,0.35); }
.red-card  { border-color: rgba(239,83,80,0.35); }

.unit-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 2px 0;
}

.settings-duel .unit-row {
  padding: 6px 8px;
  border: 1px solid transparent;
}

.settings-duel .unit-row.selected {
  background: rgba(79,195,247,0.10);
  border-color: rgba(79,195,247,0.30);
}

.settings-duel .cnt-btn[data-dir="-1"] {
  opacity: 0.32;
  pointer-events: none;
}

.unit-label { font-size: 0.82rem; color: #8a9bbb; white-space: nowrap; }

.counter {
  display: flex;
  align-items: center;
  gap: 6px;
}

.counter > span {
  font-size: 1rem;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
  color: #e0e6f0;
}

.cnt-btn {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: #e0e6f0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  padding: 0;
}

.cnt-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.3); }
.cnt-btn:active { background: rgba(255,255,255,0.22); }

.charger-row {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 10px;
  margin-top: 2px;
}

.vs-divider {
  font-size: 1.1rem;
  font-weight: 900;
  color: rgba(255,255,255,0.2);
  letter-spacing: 0.1em;
}

/* Result Screen */

#resultScreen {
  justify-content: flex-start;
  gap: 0;
  overflow: hidden;
  padding: 0;
}

.result-title {
  max-width: min(92%, 560px);
  font-size: clamp(1.8rem, 8.5vw, 4.6rem);
  font-weight: 900;
  line-height: 0.95;
  text-align: center;
  overflow-wrap: anywhere;
  text-shadow: 0 0 20px currentColor;
  animation: victory-title-slam 0.72s cubic-bezier(0.18, 1.55, 0.28, 1) both;
}

.result-winner-portrait {
  --winner-color: #fff2a8;
  position: relative;
  display: grid;
  flex: 0 0 66.666%;
  width: 100%;
  min-height: 0;
  justify-items: center;
  align-items: stretch;
  margin: 0;
  isolation: isolate;
  pointer-events: none;
  animation: victory-panel-rise 0.86s cubic-bezier(0.16, 1.22, 0.24, 1) both;
}

.result-winner-portrait.hidden { display: none; }

.result-winner-portrait.hidden + .result-summary {
  flex-basis: 100%;
}

.result-winner-logo {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  width: 17%;
  height: 25%;
  padding: 0;
  object-fit: contain;
  object-position: left top;
  pointer-events: none;
  filter:
    drop-shadow(0 5px 0 rgba(0,0,0,0.44))
    drop-shadow(0 0 18px rgba(255,255,255,0.26));
}

.result-winner-portrait::before {
  content: "WINNER!";
  position: absolute;
  z-index: 2;
  top: clamp(8px, 2.2vw, 16px);
  left: 50%;
  padding: 5px 18px 6px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--winner-color), white 35%);
  background: linear-gradient(90deg, rgba(255,255,255,0.14), rgba(255,255,255,0.28), rgba(255,255,255,0.12));
  color: #fff7bc;
  font-size: clamp(0.86rem, 2.8vw, 1.18rem);
  font-weight: 1000;
  letter-spacing: 0.12em;
  text-shadow: 0 2px 0 rgba(0,0,0,0.55), 0 0 18px var(--winner-color);
  box-shadow: 0 0 22px color-mix(in srgb, var(--winner-color), transparent 45%);
  transform: translateX(-50%) rotate(-4deg);
  animation: victory-badge-pop 0.76s 0.08s cubic-bezier(0.16, 1.8, 0.22, 1) both;
}

.result-winner-portrait::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: 132%;
  height: 132%;
  border-radius: 50%;
  background:
    radial-gradient(circle,
      color-mix(in srgb, var(--winner-color), transparent 18%) 0 16%,
      rgba(255,255,255,0.18) 17% 19%,
      transparent 20% 34%,
      color-mix(in srgb, var(--winner-color), transparent 58%) 35% 37%,
      transparent 38% 52%,
      rgba(255,255,255,0.12) 53% 55%,
      transparent 56% 100%);
  filter: blur(0.4px);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.28);
  animation: victory-burst 1.05s 0.08s cubic-bezier(0.16, 1.1, 0.24, 1) both;
}

.result-winner-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  border-radius: 0;
  border: clamp(4px, 1vw, 8px) solid color-mix(in srgb, var(--winner-color), white 18%);
  background:
    radial-gradient(circle at 50% 38%, rgba(255,255,255,0.26), transparent 34%),
    radial-gradient(circle, color-mix(in srgb, var(--winner-color), transparent 76%), rgba(255,255,255,0.08));
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow:
    0 0 0 10px rgba(255,255,255,0.06),
    0 0 52px color-mix(in srgb, var(--winner-color), transparent 25%),
    0 26px 60px rgba(0,0,0,0.52);
  animation: victory-portrait-slam 0.78s 0.14s cubic-bezier(0.16, 1.55, 0.24, 1) both,
             victory-portrait-glow 1.7s 0.9s ease-in-out infinite;
}

.result-winner-image img {
  width: 100%;
  height: 100%;
  padding: clamp(12px, 3vw, 28px);
  object-fit: contain;
  filter: drop-shadow(0 18px 16px rgba(0,0,0,0.45));
  animation: victory-art-pop 0.74s 0.26s cubic-bezier(0.16, 1.45, 0.24, 1) both;
}

.result-winner-emoji {
  font-size: clamp(7rem, calc(var(--arena-size, 640px) * 0.36), 16rem);
  line-height: 1;
  filter: drop-shadow(0 18px 16px rgba(0,0,0,0.45));
  animation: victory-art-pop 0.74s 0.26s cubic-bezier(0.16, 1.45, 0.24, 1) both;
}

.result-winner-name {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: clamp(8px, 2.2vw, 16px);
  max-width: 92%;
  padding: 4px 16px 5px;
  border-radius: 999px;
  background: rgba(3,6,12,0.62);
  font-size: clamp(1rem, 3.8vw, 1.55rem);
  font-weight: 900;
  color: #eef6ff;
  overflow-wrap: anywhere;
  text-shadow: 0 2px 0 rgba(0,0,0,0.6), 0 0 18px var(--winner-color);
  transform: translateX(-50%);
  animation: victory-name-pop 0.62s 0.34s cubic-bezier(0.16, 1.65, 0.24, 1) both;
}

.result-summary {
  flex: 0 0 33.334%;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 16px);
  padding: clamp(12px, 3vw, 24px) 18px max(14px, env(safe-area-inset-bottom));
}

.result-desc {
  max-width: min(92%, 520px);
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  text-align: center;
  color: #8a9bbb;
  animation: victory-desc-fade 0.42s 0.62s ease-out both;
}

#resultScreen .btn-row {
  position: relative;
  z-index: 10;
  gap: clamp(10px, 2.5vw, 16px);
}

#resultScreen .btn {
  padding: clamp(9px, 2.4vw, 13px) clamp(18px, 5vw, 34px);
  font-size: clamp(0.9rem, 2.7vw, 1.08rem);
}

@keyframes victory-title-slam {
  0% { opacity: 0; transform: translateY(-26px) scale(1.45) rotate(-4deg); filter: blur(3px); }
  58% { opacity: 1; transform: translateY(4px) scale(0.94) rotate(1deg); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

@keyframes victory-panel-rise {
  0% { opacity: 0; transform: translateY(38px) scale(0.82); }
  62% { opacity: 1; transform: translateY(-8px) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes victory-badge-pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(18px) scale(0.25) rotate(-16deg); }
  60% { opacity: 1; transform: translateX(-50%) translateY(-4px) scale(1.18) rotate(-3deg); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1) rotate(-4deg); }
}

@keyframes victory-burst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
  35% { opacity: 0.9; }
  100% { opacity: 0.34; transform: translate(-50%, -50%) scale(1); }
}

@keyframes victory-portrait-slam {
  0% { opacity: 0; transform: scale(0.18) rotate(-18deg); filter: brightness(2.4) blur(2px); }
  48% { opacity: 1; transform: scale(1.18) rotate(4deg); filter: brightness(1.25) blur(0); }
  74% { transform: scale(0.95) rotate(-1deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); filter: brightness(1); }
}

@keyframes victory-portrait-glow {
  0%, 100% { box-shadow: 0 0 0 10px rgba(255,255,255,0.06), 0 0 52px color-mix(in srgb, var(--winner-color), transparent 25%), 0 26px 60px rgba(0,0,0,0.52); }
  50% { box-shadow: 0 0 0 14px rgba(255,255,255,0.08), 0 0 76px color-mix(in srgb, var(--winner-color), transparent 8%), 0 30px 72px rgba(0,0,0,0.58); }
}

@keyframes victory-art-pop {
  0% { opacity: 0; transform: translateY(24px) scale(0.72); }
  68% { opacity: 1; transform: translateY(-4px) scale(1.08); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes victory-name-pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(0.8); }
  70% { opacity: 1; transform: translateX(-50%) translateY(2px) scale(1.08); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes victory-desc-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Buttons */

.btn {
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  padding: 8px 20px;
  font-size: 0.85rem;
  touch-action: manipulation;
}

.btn:hover  { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }

.btn.primary   { background: #4fc3f7; color: #070c14; }
.btn.secondary { background: rgba(255,255,255,0.08); color: #c8d8f0; border: 1px solid rgba(255,255,255,0.15); }
.btn.small     { background: rgba(255,255,255,0.08); color: #c8d8f0; border: 1px solid rgba(255,255,255,0.12); padding: 5px 12px; font-size: 0.78rem; }
.btn.lg        { padding: 11px 32px; font-size: 1rem; }

.btn-row {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Battle HUD */

.hud {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 44px;
  background: rgba(7, 11, 18, 0.88);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
}

.hud.hidden { display: none; }

.hud-side {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.red-side { justify-content: flex-end; }

.hud-label { color: #8a9bbb; }

.hud-count {
  font-size: 1rem;
  font-weight: 900;
}

.blue-side .hud-count { color: #4fc3f7; }
.red-side  .hud-count { color: #ef5350; }

.hud-center {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Display Settings */

.display-settings-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  width: 8vh;
  height: 8vh;
  border: 1.5px solid rgb(255, 255, 255);
  border-radius: 2vh;
  background: rgba(20, 30, 50, 0.92);
  color: #4fc3f7;
  font-size: 5.5vh;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s, opacity 0.28s ease-out;
  padding: 0;
  font-family: inherit;
  line-height: 1;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6), 0 0 12px rgba(79,195,247,0.15);
}

body:has(#titleScreen.title-loading:not(.hidden)) .display-settings-btn {
  opacity: 0;
  pointer-events: none;
}

body:has(#titleScreen.title-ui-visible:not(.hidden)) .display-settings-btn {
  opacity: 1;
  pointer-events: auto;
}

.display-settings-btn:hover {
  background: rgba(30, 50, 80, 0.97);
  border-color: rgba(79,195,247,0.8);
  color: #81d4fa;
  box-shadow: 0 4px 24px rgba(0,0,0,0.7), 0 0 18px rgba(79,195,247,0.3);
}

.display-settings-btn:active { transform: scale(0.95); }

.display-settings-btn.hidden { display: none; }

.help-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(18px, 4vw, 42px);
  background: rgba(6, 10, 16, 0.78);
  backdrop-filter: blur(6px);
  z-index: 320;
}

.help-panel.hidden { display: none; }

.help-panel-content {
  position: relative;
  width: 80vw;
  height: 80vh;
  height: 80dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(18px, 3vw, 32px);
  background: linear-gradient(180deg, rgba(18, 28, 46, 0.98), rgba(8, 13, 22, 0.98));
  border: 1px solid rgba(79,195,247,0.38);
  border-radius: 14px;
  padding: clamp(22px, 3.4vw, 34px);
  box-shadow:
    0 18px 58px rgba(0,0,0,0.78),
    0 0 0 1px rgba(255,255,255,0.05),
    0 0 30px rgba(79,195,247,0.14);
  overflow-y: auto;
}

.help-panel-top {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  padding-right: 38px;
}

.help-panel-language {
  min-height: 86px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(79,195,247,0.42);
  border-radius: 8px;
  background: rgba(6,10,16,0.44);
  padding: 10px;
  color: #8fb7d2;
  font-size: 0.74rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.03em;
}

.help-panel-language select {
  width: 100%;
  min-height: 30px;
  border: 1px solid rgba(79,195,247,0.32);
  border-radius: 6px;
  background: rgba(6,10,16,0.82);
  color: #eaf6ff;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 7px;
}

.help-panel-title {
  margin: 0;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(79,195,247,0.42);
  border-radius: 8px;
  background: rgba(6,10,16,0.44);
  padding: 12px 18px;
  font-size: clamp(1.35rem, 4vw, 2.45rem);
  font-weight: 800;
  color: #eaf6ff;
  text-align: center;
  text-shadow: 0 0 18px rgba(79,195,247,0.24);
  overflow-wrap: anywhere;
}

.help-panel-main {
  min-height: 0;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) minmax(0, 1fr) 52px;
  gap: clamp(12px, 2vw, 18px);
  align-items: center;
}

.help-panel-image-frame,
.help-panel-body {
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(79,195,247,0.34);
  border-radius: 8px;
  background: rgba(6,10,16,0.42);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.035);
}

.help-panel-image-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.help-panel-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.help-panel-body {
  padding: clamp(16px, 2.6vw, 26px);
  color: #d7e8f7;
  font-size: clamp(2rem, 4vw, 2rem);
  font-weight: 600;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-y: auto;
  overflow-wrap: anywhere;
}

.help-panel-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 4px;
  padding: 10px 16px;
  border: 1px solid rgba(79,195,247,0.72);
  border-radius: 8px;
  background: rgba(79,195,247,0.14);
  color: #ffd54f;
  font-weight: 900;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  box-shadow: 0 0 18px rgba(79,195,247,0.16);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.help-panel-link::after {
  content: "↗";
  font-size: 0.82em;
  line-height: 1;
}

.help-panel-link-logo {
  width: 1.25em;
  height: 1.25em;
  object-fit: contain;
  flex-shrink: 0;
}

.help-panel-link:hover,
.help-panel-link:focus-visible {
  border-color: rgba(185,246,202,0.86);
  background: rgba(185,246,202,0.14);
  color: #ffe082;
  transform: translateY(-1px);
}

.help-panel-arrow {
  position: relative;
  width: 52px;
  height: 74px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(79,195,247,0.34);
  border-radius: 10px;
  background: rgba(6,10,16,0.34);
  color: #d8f2ff;
  font-size: 0;
  font-family: inherit;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  text-shadow: 0 0 14px rgba(79,195,247,0.34);
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.help-panel-arrow::before {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  font-size: 4rem;
  line-height: 1;
  transform: translateY(-0.04em);
}

.help-panel-arrow-prev::before {
  content: "‹";
}

.help-panel-arrow-next::before {
  content: "›";
}

.help-panel-arrow:hover {
  color: #81d4fa;
  border-color: rgba(79,195,247,0.72);
  background: rgba(79,195,247,0.12);
  box-shadow: 0 0 18px rgba(79,195,247,0.14);
}

.help-panel-arrow:active {
  transform: scale(0.94);
}

.help-panel-arrow:disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

.help-panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(79,195,247,0.30);
  border-radius: 8px;
  background: rgba(6,10,16,0.62);
  color: #d8f2ff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.help-panel-close:hover {
  color: #81d4fa;
  border-color: rgba(79,195,247,0.7);
  background: rgba(79,195,247,0.12);
}

.display-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 16, 0.78);
  backdrop-filter: blur(6px);
  z-index: 300;
}

.display-modal.hidden { display: none; }

.display-modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  background: rgba(14, 20, 32, 0.99);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 28px 32px 24px;
  box-shadow: 0 16px 56px rgba(0,0,0,0.75);
  min-width: 280px;
}

.display-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #c8d8f0;
  letter-spacing: 0.04em;
  align-self: flex-start;
}

.display-modal-lang {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: #8a9bbb;
  font-size: 0.84rem;
}

.display-modal-lang select {
  flex: 1;
  min-height: 34px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  background: rgba(6,10,16,0.72);
  color: #e0e6f0;
  font-family: inherit;
  padding: 4px 8px;
}

.display-modal-section-label {
  align-self: flex-start;
  font-size: 0.78rem;
  color: #8a9bbb;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.display-modal-volume {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-size: 0.84rem;
  color: #c8d8f0;
}

.display-modal-volume-label {
  width: 30px;
  flex-shrink: 0;
  font-weight: 600;
}

.display-modal-volume input[type="range"] {
  flex: 1;
  accent-color: #4fc3f7;
  height: 4px;
  cursor: pointer;
}

.display-modal-volume-val {
  width: 36px;
  text-align: right;
  flex-shrink: 0;
  color: #8a9bbb;
  font-size: 0.8rem;
}

.display-modal-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  color: #c8d8f0;
  font-size: 0.84rem;
  cursor: pointer;
}

.display-modal-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.display-toggle-control {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  background: rgba(6,10,16,0.72);
  transition: background 0.15s, border-color 0.15s;
}

.display-toggle-control::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #8a9bbb;
  transition: transform 0.15s, background 0.15s;
}

.display-modal-toggle input:checked + .display-toggle-control {
  border-color: rgba(79,195,247,0.72);
  background: rgba(79,195,247,0.2);
}

.display-modal-toggle input:checked + .display-toggle-control::after {
  transform: translateX(20px);
  background: #4fc3f7;
}

.display-modal-toggle:focus-within .display-toggle-control {
  box-shadow: 0 0 0 3px rgba(79,195,247,0.22);
}

.display-mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.display-mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: #c8d8f0;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.display-mode-btn:hover {
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.24);
}

.display-mode-btn:active { transform: scale(0.97); }

.display-mode-btn.active {
  background: rgba(79,195,247,0.14);
  border-color: rgba(79,195,247,0.7);
  box-shadow: inset 0 0 0 1px rgba(79,195,247,0.18);
}

.display-mode-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.display-mode-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: #e0e6f0;
}

.display-mode-desc {
  font-size: 0.7rem;
  color: #8a9bbb;
  text-align: center;
}

@media (max-width: 560px) {
  html,
  body {
    width: 100%;
    height: 100%;
  }

  body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .game-wrapper {
    max-width: 100%;
  }

  .overlay {
    gap: 12px;
    padding: max(14px, env(safe-area-inset-top)) 12px max(68px, calc(env(safe-area-inset-bottom) + 58px));
  }

  #titleScreen {
    padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    gap: 12px;
  }

  .title-main-logo {
    width: min(86vw, 52vh);
    max-height: 24vh;
  }

  #titleScreen .title-mode-select {
    width: min(100%, 420px);
    gap: 8px;
  }

  #titleScreen .mode-btn {
    min-height: 74px;
    aspect-ratio: auto;
    padding: 10px 8px;
    flex-direction: column;
    justify-content: center;
  }

  #titleScreen .mode-title {
    font-size: 1rem;
  }

  #titleScreen .mode-desc {
    font-size: 0.76rem;
  }

  #titleScreen .btn.secondary {
    width: min(100%, 300px);
    min-width: 0;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  #settingsScreen {
    position: fixed;
    overflow-y: auto;
    overflow-x: hidden;
    align-items: stretch;
    padding: max(12px, env(safe-area-inset-top)) 10px max(78px, calc(env(safe-area-inset-bottom) + 62px));
    gap: 8px;
  }

  .duel-character-select,
  .royale-setup,
  .team-character-select {
    flex: none;
    width: 100%;
    overflow: visible;
  }

  .duel-selection-panels,
  .team-selection-panels {
    flex: none;
    grid-template-rows: auto;
  }

  .settings-picker-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .settings-stage-balance-space {
    display: none;
  }

  .settings-stage-panel {
    max-height: none;
    overflow: visible;
    padding: 8px;
  }

  .royale-profile-list,
  .team-profile-list {
    flex: none;
    overflow: visible;
    min-height: auto;
  }

  .fighter-panel {
    flex: none;
    overflow-y: visible;
    min-height: auto;
    gap: 8px;
    padding-top: 10px;
  }

  .royale-profile-card {
    max-height: none;
  }

  .mode-select {
    grid-template-columns: 1fr;
  }

  #titleScreen .title-mode-select {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .image-grid,
  .duel-selection-panels,
  .royale-profile-list,
  .team-selection-panels {
    grid-template-columns: 1fr;
  }

  .preset-type-tabs,
  .preset-icon-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .royale-profile-list {
    grid-template-columns: 1fr !important;
    grid-template-rows: none !important;
  }

  .duel-selection-panels,
  .team-selection-panels {
    gap: 8px;
  }

  .duel-select-side,
  .team-card {
    padding: 10px;
    gap: 10px;
  }

  .duel-roster-section {
    max-height: none;
    margin-top: 0;
    padding: 8px;
  }

  .duel-main-roster {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .duel-main-roster .fighter-portrait {
    min-height: 78px;
    padding: 6px 4px;
  }

  .duel-main-roster .portrait-art,
  .portrait-art {
    width: 42px;
    height: 42px;
    font-size: 1.25rem;
  }

  .portrait-name {
    font-size: 0.72rem;
  }

  .fighter-panel-head {
    gap: 8px;
  }

  .fighter-panel-name {
    font-size: 0.95rem;
  }

  .fighter-panel-preset,
  .profile-section-title,
  .preset-preview-slot,
  .preset-sound-label {
    font-size: 0.76rem;
  }

  .profile-section {
    padding: 8px;
  }

  .profile-image-section,
  .profile-sound-section {
    display: none;
  }

  .preset-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .preset-portrait {
    min-height: 62px;
    padding: 6px 5px;
  }

  .preset-editor-layout {
    flex-direction: column;
    align-items: center;
    max-height: none;
    gap: 12px;
  }

  .preset-editor {
    justify-content: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
    padding: max(12px, env(safe-area-inset-top)) 10px max(72px, env(safe-area-inset-bottom));
  }

  .preset-editor-main {
    width: 100%;
    overflow: visible;
  }

  .preset-preview-panel {
    width: 100%;
  }

  #presetPreviewCanvas {
    width: min(100%, 360px);
    height: auto;
    max-height: 36vh;
  }

  .help-panel {
    align-items: center;
    overflow: hidden;
    padding: 0;
  }

  .help-panel-content {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border-radius: 0;
    padding: max(14px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    gap: 12px;
  }

  .help-panel-top {
    grid-template-columns: 1fr;
    padding-right: 38px;
  }

  .help-panel-language {
    min-height: 54px;
  }

  .help-panel-title {
    min-height: 54px;
    font-size: 1.15rem;
  }

  .help-panel-main {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .help-panel-image-frame,
  .help-panel-body {
    grid-column: 1 / -1;
    height: auto;
    min-height: 0;
  }

  .help-panel-image-frame {
    height: 40dvh;
  }

  .help-panel-body {
    max-height: 24dvh;
    padding: 12px;
    font-size: 1rem;
    line-height: 1.45;
  }

  .help-panel-arrow {
    width: 44px;
    height: 56px;
  }

  .help-panel-arrow::before {
    font-size: 3.25rem;
  }

  .help-panel-arrow-prev {
    grid-column: 1;
    grid-row: 3;
    justify-self: start;
  }

  .help-panel-arrow-next {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
  }

  .duel-vs-separator {
    display: none;
  }

  .mode-btn {
    min-height: 44px;
    flex-direction: row;
    justify-content: space-between;
    padding-inline: 12px;
  }

  .screen-title {
    font-size: 1rem;
  }

  .teams {
    width: 100%;
    align-items: stretch;
    gap: 8px;
  }

  .team-card {
    min-width: 0;
    flex: 1;
    padding: 12px 10px;
  }

  .btn-row {
    position: static;
    z-index: 90;
    gap: 8px;
    padding: 4px 0 0;
    background: transparent;
  }

  .btn-row .btn {
    min-height: 44px;
    flex: 1 1 0;
    max-width: 220px;
  }

  .hud {
    height: 50px;
    padding: 0 max(8px, env(safe-area-inset-left)) max(2px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    gap: 6px;
  }

  .hud-label {
    display: none;
  }

  .hud-count {
    font-size: 1.1rem;
  }

  .hud-center .btn.small {
    min-width: 58px;
    min-height: 36px;
    padding: 6px 9px;
    font-size: 0.76rem;
  }

  .display-settings-btn {
    width: 48px;
    height: 48px;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    border-radius: 12px;
    font-size: 30px;
  }
}
