* { box-sizing: border-box; }

:root {
  --bg: #08060e;
  --panel: rgba(16, 12, 28, 0.88);
  --border: rgba(255, 90, 60, 0.35);
  --text: #f2eefc;
  --muted: #9a92b4;
  --red: #ff3a3a;
  --gold: #ffcc33;
  --blue: #3aa0ff;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.invisible { visibility: hidden; }
.muted { color: var(--muted); }
.center { justify-content: center; text-align: center; }

#bg-canvas {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
  transition: filter .4s;
}
#bg-canvas.dim { filter: brightness(0.35) blur(2px); }

.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }
.screen.scroll { overflow-y: auto; background: rgba(8, 6, 14, 0.55); }

/* ===== Main menu ===== */
#screen-menu {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 45%, rgba(8, 6, 14, 0.35) 0%, rgba(8, 6, 14, 0.78) 70%, rgba(8, 6, 14, 0.92) 100%);
}
.menu-wrap {
  width: min(980px, 94vw);
  margin: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.logo { text-align: center; line-height: 0.82; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.6)) drop-shadow(0 0 30px rgba(255, 90, 30, 0.35)); }
.logo span { display: inline-block; font-weight: 900; font-style: italic; letter-spacing: 3px; padding: 0 6px; }
.logo-top {
  font-size: clamp(42px, 7vw, 78px);
  background: linear-gradient(180deg, #fff 0%, #c9c9d6 50%, #6d6d80 51%, #e9e9f2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo-bot {
  font-size: clamp(42px, 7vw, 78px);
  background: linear-gradient(180deg, #ffe066 0%, #ff8a00 50%, #c4120b 51%, #ff5a1a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo-sub { font-size: 15px; color: #ffcfa8; letter-spacing: 1px; font-weight: 700; margin-top: -4px; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8); }

.main-menu {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 10px;
}
@media (max-width: 820px) { .main-menu { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .main-menu { grid-template-columns: 1fr; } }
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: right;
  padding: 16px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(160deg, rgba(36, 26, 56, 0.86), rgba(14, 10, 24, 0.9));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: transform .14s, border-color .14s, box-shadow .14s, background .14s;
  animation: rise .35s ease-out both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.menu-item.featured {
  grid-column: 1 / -1;
  padding: 20px 22px;
  background: linear-gradient(120deg, rgba(196, 18, 11, 0.85), rgba(255, 110, 30, 0.7));
  border-color: rgba(255, 210, 120, 0.5);
}
.menu-item.featured .mi-he { font-size: 26px; }
.menu-item.featured .mi-icon { font-size: 40px; }
.menu-item:hover, .menu-item:focus {
  outline: none;
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(255, 204, 51, 0.35);
}
.mi-icon { font-size: 32px; flex: none; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5)); }
.mi-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mi-he { font-size: 19px; font-weight: 900; }
.mi-en { font-size: 11px; font-weight: 900; font-style: italic; color: var(--gold); letter-spacing: 2px; text-align: right; }
.mi-desc { font-size: 13px; color: #d6cfee; opacity: 0.85; }
.menu-item.featured .mi-en { color: #fff3c4; }
.menu-item.featured .mi-desc { color: #fff; }

.menu-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.pill {
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(14, 10, 24, 0.75);
  color: #e6def8;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.pill:hover, .pill:focus { outline: none; border-color: var(--gold); background: rgba(60, 30, 40, 0.9); }

/* ===== Buttons / chips ===== */
.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  padding: 11px 22px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(40, 30, 60, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: filter .12s, transform .1s;
}
.btn:hover, .btn:focus { filter: brightness(1.3); outline: 2px solid var(--gold); outline-offset: 1px; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, #e0261b, #ff7a1a); border-color: transparent; }
.btn.danger { background: #7a1220; }
.btn.small { padding: 6px 14px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(30, 24, 48, 0.9);
  color: var(--text);
  cursor: pointer;
}
.chip.active { background: linear-gradient(135deg, #e0261b, #ff7a1a); border-color: transparent; }

/* ===== Character select ===== */
#screen-select {
  background: radial-gradient(ellipse at 50% 30%, rgba(70, 14, 14, 0.75), rgba(8, 6, 14, 0.95) 70%);
  padding: 14px 18px 16px;
  gap: 12px;
}
.sel-head { display: flex; align-items: center; gap: 16px; flex: none; }
.sel-head h2 { margin: 0; font-size: 28px; font-style: italic; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5); }
.sel-hint {
  margin-inline-start: auto;
  font-size: 13px;
  color: #cfc6e6;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 12px;
  border-radius: 999px;
}
.sel-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(420px, 640px) minmax(220px, 1fr);
  gap: 18px;
  align-items: stretch;
}
.sel-side {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(10, 8, 18, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: border-color .2s, box-shadow .2s;
}
#sel-side-0.locked { border-color: var(--red); box-shadow: 0 0 34px rgba(255, 58, 58, 0.45); }
#sel-side-1.locked { border-color: var(--blue); box-shadow: 0 0 34px rgba(58, 160, 255, 0.45); }
.big-wrap { position: relative; flex: 1; min-height: 140px; }
.big-portrait { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tag {
  position: absolute;
  top: 10px;
  left: 10px;
  font-weight: 900;
  font-style: italic;
  font-size: 20px;
  padding: 2px 12px;
  border-radius: 6px;
  z-index: 2;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}
.tag.p1 { background: var(--red); }
.tag.p2 { background: var(--blue); }
.info { padding: 12px 16px 14px; background: linear-gradient(0deg, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.55)); }
.info-name { font-size: 26px; font-weight: 900; font-style: italic; line-height: 1.1; }
.info-name small { font-size: 15px; color: var(--muted); font-style: normal; font-weight: 700; }
.info-style { color: var(--gold); font-weight: 800; margin: 2px 0 8px; }
.stat-row { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.bar { height: 8px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffcc33, #ff3a3a); border-radius: 4px; }
.bio { font-size: 13px; color: #d6cfee; margin: 10px 0 0; line-height: 1.5; }

.sel-center { display: flex; flex-direction: column; gap: 14px; min-height: 0; justify-content: center; }
.sel-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.tile {
  position: relative;
  aspect-ratio: 3 / 4;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: #111;
  cursor: pointer;
  transition: transform .1s, border-color .1s, box-shadow .1s;
}
.tile:hover { border-color: rgba(255, 255, 255, 0.4); }
.tile canvas { width: 100%; height: 100%; display: block; }
.tile-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 0 3px;
  font-weight: 900;
  font-style: italic;
  font-size: 13px;
  color: #fff;
  text-align: center;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.92), transparent);
}
.tile-flag { position: absolute; top: 4px; right: 5px; font-size: 14px; }
.cur {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 11px;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 3px;
  display: none;
}
.cur.c0 { background: var(--red); }
.cur.c1 { top: 22px; background: var(--blue); }
.tile.p0 { border-color: var(--red); transform: scale(1.06); z-index: 1; box-shadow: 0 0 16px rgba(255, 58, 58, 0.6); }
.tile.p1 { border-color: var(--blue); transform: scale(1.06); z-index: 1; box-shadow: 0 0 16px rgba(58, 160, 255, 0.6); }
.tile.p0 .c0, .tile.p1 .c1 { display: block; }
.tile.p0.p1 { border-color: #c050ff; }
.tile.locked0, .tile.locked1 { box-shadow: 0 0 22px rgba(255, 204, 51, 0.85); }

.sel-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.opt { display: flex; align-items: center; gap: 12px; font-weight: 800; }
.opt > span { min-width: 44px; color: var(--muted); font-size: 14px; }

@media (max-width: 1000px) {
  .sel-body { grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; }
  .sel-center { grid-column: 1 / 3; grid-row: 1; }
  .sel-side .bio { display: none; }
}
@media (max-width: 600px) {
  .sel-grid { grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 6px; }
  .tile-name { font-size: 9px; }
  .info-name { font-size: 18px; }
}

/* ===== Fight ===== */
#screen-fight { background: #000; }
.fight-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.fight-wrap canvas { display: block; }
.pause-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 40px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.5;
  z-index: 2;
}
.pause-btn:hover { opacity: 1; }
.mute-btn { right: 56px; }

.vs-splash {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background:
    radial-gradient(ellipse at 25% 50%, rgba(255, 80, 40, 0.45), transparent 60%),
    radial-gradient(ellipse at 75% 50%, rgba(40, 120, 255, 0.45), transparent 60%),
    linear-gradient(100deg, #3a0606 0%, #8a1010 49.6%, #fff 49.8%, #fff 50.2%, #0a2a7a 50.4%, #040c2a 100%);
  z-index: 3;
  cursor: pointer;
  overflow: hidden;
  animation: fadeIn .25s ease-out;
}
.vs-splash::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(100deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 26px);
  animation: streak 1.2s linear infinite;
}
@keyframes streak { from { background-position: 0 0; } to { background-position: 260px 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.vs-side { position: relative; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: center; }
.vs-side canvas { width: min(34vw, 420px); height: min(66vh, 560px); filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.25)); }
.vs-side.left { animation: inL .4s ease-out; }
.vs-side.right { animation: inR .4s ease-out; }
@keyframes inL { from { transform: translateX(-60%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes inR { from { transform: translateX(60%); opacity: 0; } to { transform: none; opacity: 1; } }
.vs-name { font-size: clamp(28px, 5vw, 56px); font-weight: 900; font-style: italic; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.5); }
.vs-mid { text-align: center; }
.vs-text {
  font-size: clamp(60px, 12vw, 150px);
  font-weight: 900;
  font-style: italic;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255, 200, 50, 0.8), 0 6px 0 #7a3a00;
  animation: pulse .6s ease-in-out infinite alternate;
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
.vs-stage, .vs-round { font-size: 18px; font-weight: 800; margin-top: 8px; }

/* touch */
.touch {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  touch-action: none;
}
.touch button {
  font-family: inherit;
  font-weight: 900;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(40, 30, 60, 0.75);
  touch-action: none;
}
.touch button.down { background: #e0261b; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 46px);
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: 4px;
}
.dpad button { border-radius: 10px; font-size: 20px; }
.d-up { grid-area: up; } .d-left { grid-area: left; } .d-right { grid-area: right; } .d-down { grid-area: down; }
.tside { display: flex; flex-direction: column; gap: 6px; }
.small-t { border-radius: 8px; font-size: 13px; padding: 8px 10px; }
.face {
  display: grid;
  grid-template-columns: repeat(2, 60px);
  grid-template-rows: repeat(2, 60px);
  gap: 8px;
}
.face button { border-radius: 50%; font-size: 22px; }
.f1, .f2 { background: rgba(200, 60, 40, 0.7) !important; }
.f3, .f4 { background: rgba(40, 90, 200, 0.7) !important; }
.face button.down { filter: brightness(1.6); }

/* ===== Pages ===== */
.page { width: 100%; max-width: 860px; margin: 0 auto; padding: 22px 16px 40px; }
.page h2 { text-align: center; font-size: 32px; font-style: italic; margin: 0 0 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; margin: 12px 0; }
.card h3 { margin: 0 0 10px; color: var(--gold); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.row:last-child { border-bottom: none; }
.range { display: flex; align-items: center; gap: 10px; }
.range output { min-width: 46px; color: var(--gold); font-weight: 800; }
select {
  font-family: inherit;
  font-size: 15px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a1428;
  color: var(--text);
}
input[type=range] { accent-color: #ff5a1a; width: 180px; }
input.switch { width: 22px; height: 22px; accent-color: #ff5a1a; }
.page-actions, .modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.modal-actions.col { flex-direction: column; align-items: stretch; }

table.keys, table.moves { width: 100%; border-collapse: collapse; }
table.keys th, table.keys td, table.moves th, table.moves td {
  padding: 7px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  text-align: right;
  font-size: 14px;
}
table th { color: var(--muted); font-weight: 700; font-size: 13px; }
kbd {
  display: inline-block;
  min-width: 26px;
  padding: 2px 7px;
  margin: 1px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 3px;
  background: #221a36;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}
.help-list { margin: 0; padding-inline-start: 20px; line-height: 1.9; }
.hh { color: #ff8a8a; font-weight: 800; }
.hm { color: #ffd84a; font-weight: 800; }
.hl { color: #6fc3ff; font-weight: 800; }

.cmd { font-size: 16px; font-weight: 800; white-space: nowrap; }
.bi {
  display: inline-flex;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  margin: 0 1px;
  color: #fff;
}
.b1, .b2 { background: #c43a28; }
.b3, .b4 { background: #2a5ec4; }
.sep { color: var(--muted); margin: 0 3px; font-size: 11px; }
.hgt { font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 4px; }
.hgt.hh { background: rgba(255, 90, 90, 0.2); }
.hgt.hm { background: rgba(255, 216, 74, 0.2); }
.hgt.hl { background: rgba(111, 195, 255, 0.2); }
.hgt.ht { background: rgba(200, 120, 255, 0.25); color: #e0b0ff; }
tr.special td:first-child { color: var(--gold); font-weight: 800; }
td.notes { font-size: 12px; color: #cfc6e6; }
.ml-head { margin-bottom: 8px; font-size: 18px; }
.ml-head p { margin: 4px 0 0; font-size: 14px; }
.general { margin-top: 12px; font-size: 13px; color: #cfc6e6; line-height: 1.7; }
.wl { display: flex; gap: 30px; justify-content: center; font-size: 20px; font-weight: 900; }
.wl .w { color: #7dff8a; }
.wl .l { color: #ff5a5a; }

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(4, 2, 8, 0.72);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(160deg, #2a1420, #120c1c);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  animation: pop .18s ease-out;
}
.modal-card.narrow { max-width: 360px; }
.modal-card.wide { max-width: 860px; }
@keyframes pop { from { transform: scale(0.93); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h2 { margin: 0 0 6px; text-align: center; font-size: 30px; font-style: italic; }
.res-sub { text-align: center; color: #ffcf9a; font-weight: 700; margin-bottom: 8px; }
.record { text-align: center; color: var(--gold); font-weight: 900; font-size: 20px; margin: 6px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px; margin-top: 10px; }
.stat { display: flex; justify-content: space-between; padding: 7px 10px; background: rgba(255, 255, 255, 0.05); border-radius: 6px; }
.stat span { color: var(--muted); }
#pause-training .chips { margin: 8px 0 4px; }

/* ===== Key bindings ===== */
#bind-list .row { padding: 6px 0; }
.keybtn {
  min-width: 130px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 3px;
  background: #221a36;
  color: var(--text);
  cursor: pointer;
}
.keybtn:hover, .keybtn:focus { outline: none; border-color: var(--gold); }
.keybtn.wait { border-color: var(--gold); color: var(--gold); animation: pulse .6s ease-in-out infinite alternate; }

/* ===== Online ===== */
.ol-link-row { display: flex; gap: 8px; margin: 12px 0 4px; }
.ol-link-row input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a1428;
  color: var(--text);
}
.net-wait {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  font-weight: 800;
  z-index: 2;
}
.net-badge {
  position: absolute;
  bottom: 12px;
  left: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 13px;
  font-weight: 800;
  z-index: 2;
}
#modal-pause.online #p-restart, #modal-pause.online #p-select { display: none; }
