:root {
  color-scheme: dark;
  --bg: #050a13;
  --panel: rgba(12, 22, 37, .78);
  --panel-solid: #0b1422;
  --line: rgba(148, 163, 184, .16);
  --muted: #8b9bb2;
  --text: #eef6ff;
  --cyan: #21d4fd;
  --blue: #4f7cff;
  --purple: #a970ff;
  --green: #38e7a6;
  --danger: #ff5876;
  --radius: 22px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -20%, rgba(55, 111, 255, .18), transparent 40%),
    linear-gradient(180deg, #07101d 0%, var(--bg) 58%, #03070d 100%);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  z-index: -1;
  width: 34rem;
  height: 34rem;
  border-radius: 999px;
  filter: blur(110px);
  opacity: .11;
  pointer-events: none;
}
.ambient-one { top: 9%; left: -18rem; background: var(--cyan); }
.ambient-two { right: -17rem; bottom: 2%; background: var(--purple); }

.app { min-height: 100vh; min-height: 100dvh; }
.site-header {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1180px, calc(100% - 40px));
  height: 78px;
  margin: 0 auto;
}
.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  padding: 0;
  border: 0;
  color: var(--text);
  background: none;
  cursor: pointer;
  text-align: left;
}
.brand > span:last-child { display: grid; line-height: .92; letter-spacing: .12em; }
.brand b { font-size: 14px; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 9px; letter-spacing: .32em; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 9px); grid-template-rows: repeat(2, 9px); gap: 2px; transform: rotate(-8deg); }
.brand-mark i { border-radius: 2px; background: var(--cyan); box-shadow: 0 0 13px rgba(33, 212, 253, .4); }
.brand-mark i:nth-child(2) { background: var(--blue); }
.brand-mark i:nth-child(3) { grid-column: 2; background: var(--purple); }
.brand-mark i:nth-child(4) { display: none; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.connection-state {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: #657086; }
.connection-state.is-online i { background: var(--green); box-shadow: 0 0 10px rgba(56, 231, 166, .7); }
.connection-state.is-offline i { background: var(--danger); }
.icon-link {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-decoration: none;
}
.icon-link:hover { color: var(--text); border-color: rgba(33, 212, 253, .5); }
.utility-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #9aabc0;
  background: rgba(8, 16, 28, .58);
  cursor: pointer;
  font-size: 10px;
}
.utility-button:hover { color: var(--text); border-color: rgba(33, 212, 253, .45); }

.view { display: none; width: min(1180px, calc(100% - 40px)); margin: 0 auto; animation: view-in .35s ease both; }
.view.is-active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } }
.menu-view.is-active {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .72fr);
  gap: clamp(44px, 8vw, 110px);
  align-items: center;
  min-height: calc(100vh - 112px);
  min-height: calc(100dvh - 112px);
  padding: 36px 0 86px;
}
.eyebrow { margin: 0 0 18px; color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: .24em; }
.hero-copy h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(50px, 7vw, 88px);
  line-height: .98;
  letter-spacing: -.055em;
}
.hero-copy h1 em { color: transparent; background: linear-gradient(90deg, var(--cyan), #7d8cff 52%, #c879ff); background-clip: text; font-style: normal; }
.hero-lead { max-width: 570px; margin: 30px 0 24px; color: #9cabc0; font-size: 16px; line-height: 1.85; }
.rule-pills { display: flex; flex-wrap: wrap; gap: 9px; }
.rule-pills span { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: #94a7c1; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; letter-spacing: .1em; }
.glass-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(17, 30, 49, .85), rgba(7, 14, 25, .82));
  box-shadow: 0 28px 70px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .035);
  backdrop-filter: blur(20px);
}
.menu-card { padding: 30px; }
.field-label { display: flex; justify-content: space-between; margin: 0 0 9px; color: #a7b6ca; font-size: 12px; font-weight: 650; }
.field-label output { color: var(--cyan); }
.name-field { display: flex; align-items: center; height: 48px; margin-bottom: 5px; border: 1px solid var(--line); border-radius: 13px; background: rgba(4, 9, 16, .7); }
.name-field:focus-within { border-color: rgba(33, 212, 253, .55); box-shadow: 0 0 0 3px rgba(33, 212, 253, .08); }
.name-field span { padding-left: 15px; color: #5d708a; }
.name-field input { min-width: 0; flex: 1; height: 100%; padding: 0 13px 0 7px; border: 0; outline: 0; color: var(--text); background: transparent; }
.field-error { min-height: 18px; margin: 0 0 8px; color: #ff8398; font-size: 11px; }
.mode-button {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 76px;
  margin-top: 12px;
  padding: 13px 17px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(7, 15, 26, .62);
  cursor: pointer;
  text-align: left;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.mode-button:hover { transform: translateY(-2px); border-color: rgba(33, 212, 253, .42); background: rgba(14, 28, 46, .88); }
.mode-button > span:nth-child(2) { display: grid; gap: 5px; }
.mode-button b { font-size: 15px; }
.mode-button small { color: var(--muted); font-size: 11px; }
.mode-button > i { color: #62738c; font-style: normal; }
.mode-icon { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 13px; color: var(--cyan); background: rgba(33, 212, 253, .1); font-size: 19px; }
.mode-battle .mode-icon { color: #c293ff; background: rgba(169, 112, 255, .12); }
.mode-battle:hover { border-color: rgba(169, 112, 255, .5); }
.menu-foot { display: flex; justify-content: space-between; margin-top: 22px; color: #66778e; font-size: 10px; }
.menu-foot a { color: #8496ae; text-decoration: none; }
.menu-foot a:hover { color: var(--cyan); }

.browser-view, .lobby-view { padding: 44px 0 90px; }
.view-heading { max-width: 650px; margin-bottom: 38px; }
.view-heading h2 { margin: 0 0 12px; font-size: clamp(36px, 5vw, 58px); letter-spacing: -.045em; }
.view-heading > p:last-child { color: var(--muted); line-height: 1.7; }
.back-button { margin: 0 0 28px; padding: 0; border: 0; color: #8395ae; background: none; cursor: pointer; font-size: 12px; }
.back-button:hover { color: var(--text); }
.browser-grid { display: grid; grid-template-columns: .8fr .8fr 1.25fr; gap: 18px; }
.action-card, .rooms-card { position: relative; min-height: 390px; padding: 28px; }
.action-card { display: flex; flex-direction: column; }
.card-index { color: #53647b; font-family: ui-monospace, monospace; font-size: 10px; letter-spacing: .14em; }
.action-card h3, .rooms-card h3 { margin: 19px 0 8px; font-size: 20px; }
.action-card > p { min-height: 48px; margin: 0 0 30px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.primary-button, .secondary-button {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 13px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  transition: filter .15s ease, transform .15s ease, opacity .15s ease;
}
.primary-button { border: 0; color: #03111a; background: linear-gradient(100deg, var(--cyan), #65e9f8); box-shadow: 0 10px 25px rgba(33, 212, 253, .14); }
.secondary-button { border: 1px solid rgba(111, 132, 255, .55); color: #dce5ff; background: rgba(67, 91, 206, .16); }
.primary-button:hover, .secondary-button:hover { filter: brightness(1.1); transform: translateY(-1px); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; filter: none; opacity: .42; transform: none; }
.action-card .primary-button, .action-card .secondary-button { width: 100%; margin-top: auto; }
.range-input { width: 100%; margin: 14px 0 4px; accent-color: var(--cyan); }
.range-marks { display: flex; justify-content: space-between; margin-bottom: 30px; color: #65758a; font-size: 9px; }
.code-input { width: 100%; height: 60px; padding: 0 14px; border: 1px solid var(--line); border-radius: 13px; outline: 0; color: var(--text); background: rgba(4, 9, 16, .7); font-family: ui-monospace, monospace; font-size: 23px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.code-input:focus { border-color: rgba(169, 112, 255, .7); }
.rooms-heading { display: flex; justify-content: space-between; align-items: center; }
.rooms-heading h3 { margin-top: 19px; }
.text-button { padding: 8px; border: 0; color: var(--cyan); background: none; cursor: pointer; font-size: 11px; }
.room-list { max-height: 285px; overflow: auto; padding-right: 3px; scrollbar-width: thin; }
.room-entry { display: grid; grid-template-columns: 1fr auto auto; gap: 13px; align-items: center; width: 100%; margin-top: 9px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: rgba(5, 12, 21, .62); cursor: pointer; text-align: left; }
.room-entry:hover { border-color: rgba(33, 212, 253, .45); }
.room-entry strong { font-family: ui-monospace, monospace; letter-spacing: .12em; }
.room-entry span { color: var(--muted); font-size: 11px; }
.room-entry i { color: var(--cyan); font-style: normal; }
.empty-state { display: grid; min-height: 210px; margin: 0; place-items: center; color: #66768b; font-size: 12px; text-align: center; }

.compact-heading { margin-bottom: 26px; }
.compact-heading h2 { font-size: clamp(32px, 4vw, 48px); }
.lobby-layout { display: grid; grid-template-columns: 260px minmax(340px, 1fr) 240px; gap: 18px; align-items: stretch; }
.room-identity { display: flex; flex-direction: column; min-height: 390px; padding: 27px; }
.room-identity > span { color: var(--muted); font-size: 11px; }
.room-identity > button { display: grid; margin: auto 0; padding: 22px 4px; border: 0; border-radius: 15px; color: var(--text); background: rgba(4, 10, 18, .45); cursor: pointer; }
.room-identity strong { font-family: ui-monospace, monospace; font-size: 29px; letter-spacing: .15em; }
.room-identity small { margin-top: 9px; color: #66788f; font-size: 9px; }
.capacity { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.capacity > span { height: 5px; overflow: hidden; border-radius: 9px; background: #1e2a3c; }
.capacity i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--cyan); transition: width .25s ease; }
.capacity b { color: var(--muted); font-size: 10px; }
.roster-card { min-height: 390px; padding: 27px; }
.roster-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.roster-heading h3 { margin: 0; }
.roster-heading span { color: var(--muted); font-size: 10px; }
.roster-list { max-height: 308px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.roster-player { display: grid; grid-template-columns: 30px 1fr auto; gap: 11px; align-items: center; min-height: 50px; border-bottom: 1px solid rgba(148, 163, 184, .09); }
.roster-avatar { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 9px; color: var(--cyan); background: rgba(33, 212, 253, .09); font-size: 10px; font-weight: 800; }
.roster-player strong { font-size: 12px; }
.roster-player small { margin-left: 8px; color: #71839b; font-size: 9px; }
.ready-chip { padding: 5px 8px; border-radius: 999px; color: #728298; background: rgba(99, 115, 136, .12); font-size: 9px; }
.ready-chip.is-ready { color: var(--green); background: rgba(56, 231, 166, .1); }
.lobby-actions { display: flex; flex-direction: column; gap: 11px; padding: 20px 5px; }
.lobby-note { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: rgba(8, 15, 25, .55); }
.lobby-note b { font-size: 11px; }
.lobby-note p, .status-copy { margin: 7px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.lobby-actions .primary-button, .lobby-actions .secondary-button { width: 100%; }

.game-view { width: min(1440px, calc(100% - 28px)); padding: 4px 0 max(24px, env(safe-area-inset-bottom)); }
.game-view.is-active { display: block; }
.app[data-mode="game"] .site-header { display: none; }
.game-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 58px; border-bottom: 1px solid rgba(148, 163, 184, .11); }
.game-topbar .back-button { margin: 0; justify-self: start; }
.game-topbar-actions { display: flex; gap: 11px; align-items: center; justify-self: start; }
.topbar-tool {
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #8496ae;
  background: rgba(8, 16, 28, .65);
  cursor: pointer;
  font-size: 10px;
}
.topbar-tool:hover { color: var(--cyan); border-color: rgba(33, 212, 253, .45); }
.match-title { display: flex; gap: 12px; align-items: center; font-size: 12px; }
.match-title strong { color: var(--cyan); font-family: ui-monospace, monospace; font-size: 10px; }
.top-stats { display: flex; justify-self: end; gap: 22px; }
.top-stats span { display: grid; text-align: right; }
.top-stats small { color: #687a92; font-size: 8px; letter-spacing: .12em; }
.top-stats b { margin-top: 2px; font-family: ui-monospace, monospace; font-size: 15px; }
.target-toolbar { display: flex; gap: 7px; align-items: center; justify-content: center; min-height: 48px; }
.target-toolbar > span { margin-right: 7px; color: #75879e; font-size: 9px; }
.target-toolbar button { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; color: #8799b0; background: rgba(9, 17, 29, .75); cursor: pointer; font-size: 10px; }
.target-toolbar button:hover, .target-toolbar button.is-active { border-color: rgba(33, 212, 253, .45); color: var(--cyan); background: rgba(33, 212, 253, .08); }
.battle-stage { display: flex; gap: 14px; align-items: stretch; justify-content: center; min-height: 0; }
.opponent-panel { width: min(520px, 38vw); padding: 10px 10px 12px; border: 1px solid rgba(148, 163, 184, .1); border-radius: 15px; background: rgba(6, 12, 21, .52); }
.opponent-heading { display: flex; justify-content: space-between; padding: 1px 2px 8px; color: #8ea0b7; font-size: 9px; }
.opponent-heading small { color: #56677e; font-size: 8px; }
.opponent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(57px, 1fr)); gap: 5px; align-content: start; max-height: calc(100dvh - 125px); overflow: auto; scrollbar-width: thin; }
.opponent-card { position: relative; display: grid; justify-items: center; min-width: 0; padding: 5px 3px; overflow: hidden; border: 1px solid rgba(148, 163, 184, .1); border-radius: 8px; background: #08111e; cursor: pointer; }
.opponent-card:hover { border-color: rgba(169, 112, 255, .5); }
.opponent-card.is-target { border-color: var(--danger); box-shadow: 0 0 0 1px rgba(255, 88, 118, .2), 0 0 13px rgba(255, 88, 118, .13); }
.opponent-card.is-target::before { content: "TARGET"; position: absolute; z-index: 1; top: 4px; left: 4px; padding: 2px 3px; border-radius: 2px; color: #fff; background: var(--danger); font-size: 5px; font-weight: 900; letter-spacing: .05em; }
.opponent-card.is-out { opacity: .43; filter: grayscale(.8); }
.opponent-board { width: min(42px, 100%); aspect-ratio: 1 / 2; border-radius: 2px; }
.opponent-name { width: 100%; margin-top: 4px; overflow: hidden; font-size: 7px; font-weight: 700; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.opponent-meta { color: #66798f; font-size: 5px; white-space: nowrap; }
.play-area { display: grid; grid-template-columns: 88px minmax(220px, 300px) 88px; gap: 10px; align-items: start; justify-content: center; }
.side-stack { display: grid; gap: 10px; }
.piece-panel, .metric-panel { overflow: hidden; border: 1px solid rgba(148, 163, 184, .13); border-radius: 12px; background: rgba(7, 14, 25, .7); }
.piece-panel h3 { margin: 0; padding: 8px 10px 5px; color: #687b93; font-size: 8px; letter-spacing: .18em; }
.piece-panel canvas { display: block; width: 100%; aspect-ratio: 4 / 3; }
.next-panel .next-canvas { border-top: 1px solid rgba(148, 163, 184, .06); }
.metric-panel { display: grid; }
.metric-panel span { display: grid; padding: 10px; border-bottom: 1px solid rgba(148, 163, 184, .08); }
.metric-panel span:last-child { border: 0; }
.metric-panel small { color: #607188; font-size: 7px; letter-spacing: .12em; }
.metric-panel b { margin-top: 3px; font-family: ui-monospace, monospace; font-size: 12px; }
.board-column { min-width: 0; }
.board-frame { position: relative; padding: 3px; border: 1px solid rgba(85, 150, 255, .35); border-radius: 8px; background: linear-gradient(145deg, rgba(33, 212, 253, .3), rgba(169, 112, 255, .22)); box-shadow: 0 18px 55px rgba(0, 0, 0, .5), 0 0 35px rgba(42, 115, 255, .08); }
#board-canvas { display: block; width: 100%; aspect-ratio: 1 / 2; border-radius: 5px; background: #050a12; }
.incoming-meter { position: absolute; top: 3px; right: calc(100% + 5px); width: 7px; height: calc(100% - 6px); overflow: visible; border-radius: 5px; background: rgba(44, 54, 70, .7); }
.incoming-meter i { position: absolute; right: 0; bottom: 0; left: 0; height: 0; border-radius: inherit; background: linear-gradient(0deg, #ff4c6d, #ffad55); transition: height .16s ease; }
.incoming-meter span { position: absolute; right: 10px; bottom: 0; color: #ff8296; font-family: ui-monospace, monospace; font-size: 8px; }
.board-overlay { position: absolute; z-index: 6; inset: 3px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 22px; border-radius: 5px; background: rgba(3, 8, 16, .87); backdrop-filter: blur(7px); text-align: center; }
.board-overlay p { margin: 0 0 8px; color: var(--cyan); font-size: 9px; font-weight: 800; letter-spacing: .17em; }
.board-overlay strong { font-size: clamp(28px, 4vw, 43px); letter-spacing: -.045em; }
.board-overlay > span { margin-top: 10px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.overlay-actions { display: flex; flex-direction: column; gap: 7px; width: 82%; margin-top: 20px; }
.overlay-actions button { min-height: 39px; border-radius: 10px; cursor: pointer; font-size: 10px; font-weight: 700; }
.countdown { position: absolute; z-index: 8; inset: 3px; display: grid; place-items: center; border-radius: 5px; color: var(--text); background: rgba(3, 8, 16, .82); font-family: ui-monospace, monospace; font-size: clamp(70px, 12vw, 120px); font-weight: 900; text-shadow: 0 0 40px rgba(33, 212, 253, .55); }
.clear-callout { position: absolute; z-index: 4; right: 9px; bottom: 18%; color: #fff; font-size: 11px; font-weight: 900; letter-spacing: .07em; opacity: 0; text-align: right; text-shadow: 0 2px 12px #000; pointer-events: none; transform: translateY(5px); }
.clear-callout.is-visible { animation: callout 1.05s ease both; }
@keyframes callout { 15%, 75% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-8px); } }
.mobile-quick-stats { display: none; }
.mobile-controls { display: none; }
.keyboard-help { margin: 11px 0 0; color: #526279; font-size: 8px; letter-spacing: .06em; text-align: center; }

.music-player {
  position: fixed;
  z-index: 90;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 8px 13px 8px 8px;
  border: 1px solid rgba(79, 124, 255, .3);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(12, 22, 38, .96), rgba(15, 20, 41, .94));
  box-shadow: 0 12px 35px rgba(0, 0, 0, .42), 0 0 25px rgba(79, 124, 255, .08);
  backdrop-filter: blur(16px);
  transition: opacity .2s ease, transform .2s ease, border-color .2s ease;
}
.music-player:hover { border-color: rgba(33, 212, 253, .5); transform: translateY(-2px); }
body:has(.app[data-mode="game"]) .music-player { display: none; }
body.settings-open .music-player { opacity: 0; pointer-events: none; }
.music-disc {
  position: relative;
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid rgba(79, 124, 255, .38);
  border-radius: 50%;
  background: repeating-radial-gradient(circle, #202c42 0 2px, #101827 3px 5px);
  box-shadow: inset 0 0 13px rgba(0, 0, 0, .65), 0 0 12px rgba(79, 124, 255, .16);
}
.music-disc::after { content: ""; position: absolute; inset: 7px; border: 1px solid rgba(255,255,255,.06); border-radius: 50%; }
.music-disc i { position: relative; z-index: 1; width: 11px; height: 11px; border-radius: 50%; background: linear-gradient(135deg, var(--cyan), var(--blue)); box-shadow: 0 0 8px rgba(33, 212, 253, .6); }
.music-disc.is-playing { animation: disc-spin 3s linear infinite; }
@keyframes disc-spin { to { transform: rotate(360deg); } }
.music-info { display: grid; gap: 5px; min-width: 105px; }
.music-info > strong { max-width: 125px; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.music-controls { display: flex; gap: 4px; }
.music-controls button {
  display: grid;
  width: 25px;
  height: 25px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #a8b7ca;
  background: rgba(79, 124, 255, .12);
  cursor: pointer;
  font-size: 9px;
}
.music-controls button:hover { color: #fff; background: rgba(33, 212, 253, .22); }
.music-controls .music-play-button { width: 29px; height: 29px; margin-top: -2px; color: var(--cyan); border: 1px solid rgba(33, 212, 253, .3); }

.settings-shell { position: fixed; z-index: 200; inset: 0; display: grid; place-items: center; padding: 24px; }
.settings-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(2, 6, 12, .76); backdrop-filter: blur(10px); cursor: default; }
.settings-dialog {
  position: relative;
  width: min(980px, 100%);
  max-height: min(820px, calc(100dvh - 48px));
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, .2);
  border-radius: 24px;
  outline: 0;
  background: linear-gradient(145deg, rgba(15, 27, 45, .99), rgba(5, 11, 21, .99));
  box-shadow: 0 35px 100px rgba(0, 0, 0, .65), inset 0 1px rgba(255,255,255,.04);
  scrollbar-width: thin;
  animation: settings-in .22s ease both;
}
@keyframes settings-in { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.settings-header { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 85px; padding: 20px 25px; border-bottom: 1px solid var(--line); background: rgba(10, 19, 33, .94); backdrop-filter: blur(18px); }
.settings-header p { margin: 0 0 5px; color: var(--cyan); font-size: 8px; font-weight: 800; letter-spacing: .22em; }
.settings-header h2 { margin: 0; font-size: 22px; letter-spacing: -.025em; }
.settings-close { display: grid; width: 38px; height: 38px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 12px; color: #8798af; background: rgba(4, 9, 17, .55); cursor: pointer; font-size: 24px; font-weight: 300; }
.settings-close:hover { color: #fff; border-color: rgba(255, 88, 118, .45); }
.migration-note { display: flex; gap: 12px; align-items: center; margin: 19px 25px 0; padding: 12px 15px; border: 1px solid rgba(56, 231, 166, .2); border-radius: 13px; color: var(--green); background: rgba(56, 231, 166, .065); }
.migration-note > span:first-child { display: grid; width: 25px; height: 25px; flex: 0 0 auto; place-items: center; border-radius: 50%; background: rgba(56, 231, 166, .12); font-size: 11px; }
.migration-note > span:last-child { display: grid; gap: 3px; }
.migration-note b { color: #baf7df; font-size: 11px; }
.migration-note small { color: #779d91; font-size: 9px; line-height: 1.45; }
.settings-mode-note { margin: 12px 25px 0; padding: 9px 12px; border-radius: 10px; color: #ffd79a; background: rgba(255, 173, 85, .09); font-size: 9px; line-height: 1.5; }
.settings-content { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 18px 25px 27px; }
.settings-card { min-width: 0; padding: 19px; border: 1px solid var(--line); border-radius: 17px; background: rgba(5, 11, 20, .48); }
.settings-card-heading { display: grid; grid-template-columns: 25px 1fr; gap: 9px; margin-bottom: 15px; }
.settings-card-heading > span { padding-top: 3px; color: #536780; font-family: ui-monospace, monospace; font-size: 8px; }
.settings-card-heading h3 { margin: 0; font-size: 14px; }
.settings-card-heading p { margin: 4px 0 0; color: #697b92; font-size: 9px; line-height: 1.5; }
.toggle-setting { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 9px 0; border-top: 1px solid rgba(148, 163, 184, .08); cursor: pointer; }
.toggle-setting > span { display: grid; gap: 3px; }
.toggle-setting b, .slider-setting b { color: #b8c6d8; font-size: 10px; }
.toggle-setting small, .slider-setting > small { color: #61738b; font-size: 8px; line-height: 1.45; }
.toggle-setting input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-setting i { position: relative; width: 36px; height: 20px; flex: 0 0 auto; border: 1px solid #35445a; border-radius: 99px; background: #152033; transition: .18s ease; }
.toggle-setting i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: #77889e; transition: .18s ease; }
.toggle-setting input:checked + i { border-color: rgba(33, 212, 253, .5); background: rgba(33, 212, 253, .18); }
.toggle-setting input:checked + i::after { background: var(--cyan); box-shadow: 0 0 9px rgba(33, 212, 253, .45); transform: translateX(16px); }
.toggle-setting input:focus-visible + i { outline: 2px solid var(--cyan); outline-offset: 3px; }
.slider-setting { display: grid; gap: 7px; padding: 9px 0 12px; }
.slider-setting > span { display: flex; align-items: center; justify-content: space-between; }
.slider-setting output { color: var(--cyan); font-family: ui-monospace, monospace; font-size: 9px; }
.slider-setting input { width: 100%; margin: 2px 0; accent-color: var(--cyan); cursor: pointer; }
.handling-settings .slider-setting { padding: 10px 0 15px; border-top: 1px solid rgba(148, 163, 184, .08); }
.settings-reset { min-height: 32px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: #8294aa; background: rgba(10, 19, 31, .62); cursor: pointer; font-size: 8px; }
.settings-reset:hover { color: var(--text); border-color: rgba(33, 212, 253, .4); }
.key-settings { grid-column: 1 / -1; }
.key-bindings-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.key-binding {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 44px;
  padding: 7px 9px 7px 11px;
  border: 1px solid rgba(148, 163, 184, .12);
  border-radius: 10px;
  color: #9eafc3;
  background: rgba(10, 19, 32, .55);
  cursor: pointer;
  font-size: 9px;
  text-align: left;
}
.key-binding kbd { min-width: 37px; max-width: 80px; overflow: hidden; padding: 6px 7px; border: 1px solid rgba(33, 212, 253, .25); border-bottom-width: 2px; border-radius: 7px; color: #e3f8ff; background: rgba(33, 212, 253, .08); font-family: ui-monospace, monospace; font-size: 9px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.key-binding:hover { border-color: rgba(33, 212, 253, .38); }
.key-binding.is-rebinding { border-color: rgba(169, 112, 255, .7); color: #e8d6ff; background: rgba(169, 112, 255, .1); }
.key-binding.is-rebinding kbd { border-color: rgba(169, 112, 255, .75); color: #fff; background: rgba(169, 112, 255, .2); animation: rebind-pulse .85s ease-in-out infinite alternate; }
@keyframes rebind-pulse { to { box-shadow: 0 0 15px rgba(169, 112, 255, .32); } }
.key-settings-foot { display: flex; gap: 15px; align-items: center; justify-content: space-between; margin-top: 12px; }
.key-settings-foot > span { color: #63758c; font-size: 8px; line-height: 1.45; }

.toast-region { position: fixed; z-index: 100; top: max(18px, env(safe-area-inset-top)); left: 50%; display: grid; gap: 7px; width: min(360px, calc(100% - 28px)); pointer-events: none; transform: translateX(-50%); }
.toast { padding: 11px 15px; border: 1px solid rgba(148, 163, 184, .2); border-radius: 11px; color: #e9f4ff; background: rgba(10, 20, 34, .95); box-shadow: 0 12px 30px rgba(0, 0, 0, .38); font-size: 11px; text-align: center; animation: toast-in .2s ease both; }
.toast.is-error { border-color: rgba(255, 88, 118, .4); color: #ffb3c0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 960px) {
  .menu-view.is-active { grid-template-columns: 1fr 360px; gap: 35px; }
  .browser-grid { grid-template-columns: 1fr 1fr; }
  .rooms-card { grid-column: 1 / -1; min-height: 280px; }
  .room-list { max-height: 190px; }
  .empty-state { min-height: 145px; }
  .lobby-layout { grid-template-columns: 220px 1fr; }
  .lobby-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 180px 180px; align-items: center; }
  .status-copy { grid-column: 1 / -1; }
  .opponent-panel { width: min(300px, 32vw); }
}

@media (pointer: coarse), (max-width: 720px) {
  body:has(.game-view.is-active) { overflow: hidden; overscroll-behavior: none; }
  .site-header { width: calc(100% - 28px); height: 64px; }
  .view { width: calc(100% - 28px); }
  .menu-view.is-active { display: block; min-height: auto; padding: 34px 0 50px; }
  .hero-copy { margin-bottom: 32px; }
  .hero-copy h1 { font-size: clamp(44px, 15vw, 68px); }
  .hero-lead { margin: 21px 0; font-size: 13px; line-height: 1.7; }
  .menu-card { padding: 21px; }
  .browser-view, .lobby-view { padding: 25px 0 60px; }
  .browser-grid { grid-template-columns: 1fr; }
  .rooms-card { grid-column: auto; }
  .action-card { min-height: 330px; }
  .view-heading { margin-bottom: 25px; }
  .view-heading h2 { font-size: 39px; }
  .lobby-layout { grid-template-columns: 1fr; }
  .room-identity { min-height: 230px; }
  .roster-card { min-height: 300px; }
  .lobby-actions { display: flex; grid-column: auto; padding: 0; }

  .game-view { width: 100%; height: 100dvh; padding: max(4px, env(safe-area-inset-top)) 7px max(5px, env(safe-area-inset-bottom)); overflow: hidden; }
  .game-topbar { min-height: 37px; padding: 0 4px; }
  .game-topbar .back-button { margin: 0; font-size: 10px; }
  .game-topbar-actions { gap: 6px; }
  .topbar-tool { width: 25px; height: 25px; border-radius: 8px; font-size: 9px; }
  .match-title { font-size: 9px; }
  .top-stats { gap: 10px; }
  .top-stats small { font-size: 6px; }
  .top-stats b { font-size: 11px; }
  .target-toolbar { min-height: 34px; gap: 4px; overflow-x: auto; justify-content: flex-start; padding: 0 2px; scrollbar-width: none; }
  .target-toolbar > span { display: none; }
  .target-toolbar button { flex: 1 0 auto; padding: 5px 10px; font-size: 8px; }
  .battle-stage { display: flex; flex-direction: column; gap: 4px; height: calc(100dvh - 250px); min-height: 290px; }
  .opponent-panel { order: 2; width: 100%; height: 78px; flex: 0 0 78px; padding: 4px; border-radius: 9px; }
  .opponent-heading { display: none; }
  .opponent-grid { display: flex; gap: 4px; height: 68px; max-height: none; overflow-x: auto; overflow-y: hidden; }
  .opponent-card { width: 49px; min-width: 49px; height: 66px; padding: 3px 2px; }
  .opponent-board { width: 25px; height: 50px; }
  .opponent-name { position: absolute; right: 2px; bottom: 1px; left: 2px; width: auto; padding: 1px; color: #eef6ff; background: rgba(3, 8, 15, .76); font-size: 5px; }
  .opponent-meta { display: none; }
  .play-area { order: 1; grid-template-columns: 42px minmax(0, 1fr) 42px; gap: 4px; width: min(100%, 376px); height: 100%; min-height: 0; margin: 0 auto; align-items: start; }
  .board-column { height: 100%; min-height: 0; }
  .board-frame { width: auto; height: calc(100% - 23px); max-height: 100%; margin: 0 auto; padding: 2px; aspect-ratio: 1 / 2; }
  #board-canvas { width: 100%; height: 100%; }
  .piece-panel { border-radius: 7px; }
  .piece-panel h3 { padding: 5px 5px 2px; font-size: 6px; }
  .piece-panel canvas { aspect-ratio: 4 / 3; }
  .extra-preview { display: none !important; }
  .desktop-metrics { display: none; }
  .mobile-quick-stats { display: flex; height: 20px; justify-content: space-around; align-items: end; color: #5f7188; font-size: 6px; }
  .mobile-quick-stats b { margin-left: 2px; color: #b6c5d8; font-family: ui-monospace, monospace; font-size: 7px; }
  .incoming-meter { right: calc(100% + 3px); width: 4px; }
  .incoming-meter span { right: 6px; font-size: 6px; }
  .clear-callout { font-size: 8px; }
  .keyboard-help { display: none; }

  .music-player { right: max(9px, env(safe-area-inset-right)); bottom: max(9px, env(safe-area-inset-bottom)); gap: 8px; padding: 6px 9px 6px 6px; }
  .music-disc { width: 34px; height: 34px; }
  .music-info { min-width: 90px; }
  .music-info > strong { max-width: 95px; font-size: 9px; }
  .music-controls button { width: 22px; height: 22px; font-size: 8px; }
  .music-controls .music-play-button { width: 25px; height: 25px; }

  .settings-shell { align-items: end; padding: 0; }
  .settings-dialog { width: 100%; max-height: 94dvh; border-width: 1px 0 0; border-radius: 22px 22px 0 0; }
  .settings-header { min-height: 71px; padding: 14px 17px; }
  .settings-header h2 { font-size: 18px; }
  .migration-note { margin: 14px 14px 0; }
  .settings-mode-note { margin: 9px 14px 0; }
  .settings-content { grid-template-columns: 1fr; gap: 10px; padding: 13px 14px max(20px, env(safe-area-inset-bottom)); }
  .settings-card { padding: 16px; }
  .key-settings { grid-column: auto; }
  .key-bindings-grid { grid-template-columns: 1fr 1fr; }
  .key-binding { min-height: 42px; }
  .key-settings-foot { align-items: end; }

  .mobile-controls {
    position: absolute;
    right: max(7px, env(safe-area-inset-right));
    bottom: max(6px, env(safe-area-inset-bottom));
    left: max(7px, env(safe-area-inset-left));
    display: flex;
    height: 192px;
    align-items: end;
    justify-content: space-between;
    touch-action: none;
    user-select: none;
  }
  .dpad { position: relative; width: 174px; height: 174px; }
  .action-pad { position: relative; width: 174px; height: 174px; }
  .control-key {
    position: absolute;
    display: grid;
    width: 58px;
    height: 58px;
    place-items: center;
    border: 1px solid rgba(149, 170, 200, .24);
    border-radius: 18px;
    color: #d6e3f2;
    background: linear-gradient(145deg, rgba(28, 42, 61, .93), rgba(10, 18, 31, .94));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07), 0 6px 17px rgba(0, 0, 0, .3);
    font-size: 22px;
    font-weight: 750;
    touch-action: none;
  }
  .control-key small { color: #7e91aa; font-size: 7px; font-weight: 600; }
  .control-key span + small { margin-top: -10px; }
  .control-key.is-pressed { border-color: rgba(33, 212, 253, .62); background: rgba(33, 212, 253, .19); transform: scale(.95); }
  .hard-key { top: 0; left: 58px; color: var(--cyan); }
  .left-key { top: 58px; left: 0; }
  .down-key { top: 58px; left: 58px; }
  .right-key { top: 58px; left: 116px; }
  .hold-key { top: 0; left: 0; color: #facc15; }
  .ccw-key { top: 58px; left: 0; color: #c89bff; }
  .cw-key { top: 36px; left: 77px; width: 74px; height: 74px; color: var(--cyan); border-color: rgba(33, 212, 253, .28); border-radius: 24px; font-size: 28px; }
  .pause-key { top: 116px; left: 58px; width: 50px; height: 50px; border-radius: 15px; }
}

@media (pointer: coarse) and (orientation: portrait), (max-width: 720px) and (orientation: portrait) {
  .board-frame { width: 100%; height: auto; max-height: calc(100% - 23px); }
  .app[data-game-mode="battle"] .battle-stage { height: calc(100dvh - 260px); }
  .app[data-game-mode="battle"] .play-area {
    width: min(100%, calc((100dvh - 336px) / 2 + 92px));
    height: calc(100% - 56px);
    flex: 0 0 calc(100% - 56px);
  }
  .app[data-game-mode="battle"] .opponent-panel {
    height: 52px;
    flex: 0 0 52px;
    padding: 3px;
  }
  .app[data-game-mode="battle"] .opponent-grid { height: 44px; }
  .app[data-game-mode="battle"] .opponent-card { width: 39px; min-width: 39px; height: 42px; }
  .app[data-game-mode="battle"] .opponent-board { width: 20px; height: 40px; }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) and (max-height: 730px) {
  .game-topbar { min-height: 32px; }
  .battle-stage { height: calc(100dvh - 218px); }
  .mobile-controls { height: 169px; transform: scale(.88); transform-origin: bottom left; width: 113.6%; }
  .action-pad { transform-origin: bottom right; }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .game-view { padding-right: max(5px, env(safe-area-inset-right)); padding-left: max(5px, env(safe-area-inset-left)); }
  .game-topbar { position: absolute; z-index: 10; top: 4px; right: 8px; left: 8px; border: 0; pointer-events: none; }
  .game-topbar button { pointer-events: auto; }
  .match-title, .top-stats { opacity: .75; }
  .target-toolbar { position: absolute; z-index: 11; top: 5px; left: 50%; width: 290px; transform: translateX(-50%); }
  .battle-stage { height: calc(100dvh - 8px); padding: 2px 182px; }
  .opponent-panel { position: absolute; right: 5px; bottom: 5px; width: 168px; height: calc(100dvh - 50px); flex-basis: auto; }
  .opponent-grid { display: grid; grid-template-columns: repeat(3, 1fr); height: 100%; overflow-y: auto; }
  .play-area { width: auto; height: 100%; grid-template-columns: 55px minmax(140px, 1fr) 55px; }
  .board-frame { height: 100%; }
  .mobile-controls { inset: 0; height: 100%; pointer-events: none; }
  .dpad, .action-pad { position: absolute; bottom: max(5px, env(safe-area-inset-bottom)); pointer-events: auto; transform: scale(.86); }
  .dpad { left: 0; transform-origin: bottom left; }
  .action-pad { right: 0; transform-origin: bottom right; }
  .control-key { background: rgba(14, 25, 41, .84); }
  .settings-shell { align-items: center; padding: 5px; }
  .settings-dialog { width: min(820px, 94vw); max-height: calc(100dvh - 10px); border: 1px solid rgba(148, 163, 184, .2); border-radius: 17px; }
  .settings-header { min-height: 55px; padding: 8px 15px; }
  .migration-note { margin-top: 9px; }
}

@media (max-width: 360px) {
  .utility-button { width: 38px; padding: 0; justify-content: center; font-size: 0; }
  .utility-button span { font-size: 12px; }
  .connection-state { display: none; }
  .key-bindings-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
