/* ===== Reset & Base ===== */
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body {
  width:100%; height:100%; overflow:hidden;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  background:#000; color:#fff;
  -webkit-user-select:none; user-select:none; touch-action:none;
}
#app { position:fixed; inset:0; background:#000; }
.page { position:absolute; inset:0; display:none; flex-direction:column; }
.page.active { display:flex; }

/* ===== Login ===== */
#login-page, #register-page { align-items:center; justify-content:center; padding:24px; overflow-y:auto; }
.auth-box { width:100%; max-width:340px; }
.auth-box .logo { text-align:center; margin-bottom:36px; }
.auth-box .logo h1 { font-size:30px; font-weight:700; letter-spacing:-.5px; }
.auth-box .logo p { color:#666; font-size:14px; margin-top:4px; }
.field { margin-bottom:14px; }
.field input {
  width:100%; padding:16px; border:1px solid #222; border-radius:14px;
  background:#111; color:#fff; font-size:16px; outline:none;
}
.field input:focus { border-color:#007aff; }
.field input::placeholder { color:#444; }
.btn {
  width:100%; padding:16px; border:none; border-radius:14px;
  font-size:16px; font-weight:600; cursor:pointer; transition:opacity .15s;
}
.btn:active { opacity:.5; }
.btn-primary { background:#007aff; color:#fff; }
.btn-secondary { background:transparent; color:#007aff; margin-top:8px; }
.error-msg { color:#ff3b30; font-size:13px; text-align:center; min-height:20px; margin-top:8px; }
[hidden] { display:none!important; }
.auth-tabs { height:38px; padding:3px; margin-bottom:14px; display:grid; grid-template-columns:1fr 1fr; border:1px solid #262626; border-radius:8px; background:#111; }
.auth-tabs button { border:0; border-radius:6px; background:transparent; color:#777; font-size:13px; }
.auth-tabs button.active { background:#282828; color:#fff; font-weight:700; }
.code-field { display:grid; grid-template-columns:minmax(0,1fr) 102px; gap:8px; }
.code-field button { border:1px solid #245e9b; border-radius:8px; background:#10243a; color:#69acff; font-size:13px; font-weight:700; }
.code-field button:disabled { opacity:.55; }
.agreement-check { margin:4px 0 16px; display:grid; grid-template-columns:18px 1fr; gap:8px; color:#777; font-size:12px; line-height:1.55; }
.agreement-check input { width:16px; height:16px; margin-top:1px; accent-color:#0879e8; }
.agreement-check button { padding:0; border:0; background:none; color:#5ca9ff; font-size:inherit; }

/* ===== Home ===== */
.home-header {
  padding:16px 20px 8px; display:flex; justify-content:space-between; align-items:center; gap:8px;
}
.home-header h2 { font-size:22px; font-weight:700; }
.selected-game-label { margin-top:3px; color:#777; font-size:12px; }
.coop-join-bar { margin:10px 16px 0; display:grid; grid-template-columns:minmax(0,1fr) 96px; gap:8px; }
.coop-join-bar input { min-width:0; height:42px; padding:0 12px; border:1px solid #30343a; border-radius:6px; background:#111317; color:#fff; font-size:16px; letter-spacing:0; }
.coop-join-bar button { height:42px; border:0; border-radius:6px; background:#0879e8; color:#fff; font-weight:700; }
.btn-logout { background:none; border:none; color:#666; font-size:14px; padding:8px; cursor:pointer; }
.header-actions { display:flex; align-items:center; gap:4px; }
.btn-account { height:34px; padding:0 10px; border:1px solid #292929; border-radius:6px; background:#151515; color:#b8b8b8; font-size:13px; }
.btn-profile { width:36px; height:36px; flex:0 0 36px; border:1px solid #34383e; border-radius:50%; background:#1b2026; color:#eaf3ff; font-size:13px; font-weight:800; }
.btn-profile span { width:24px; height:24px; margin:auto; display:flex; align-items:center; justify-content:center; border-radius:50%; background:#0879e8; }
.btn-header-action { height:36px; padding:0 9px; border:0; background:transparent; color:#8fbdf0; font-size:12px; font-weight:700; }

/* ===== Account and legal ===== */
#account-page, #legal-page { background:#0a0a0a; }
.account-header, .legal-header { height:58px; padding:8px 14px; display:grid; grid-template-columns:48px 1fr 48px; align-items:center; border-bottom:1px solid #222; background:#0d0d0d; }
.account-header h2, .legal-header h2 { text-align:center; font-size:17px; letter-spacing:0; }
.account-header button, .legal-header button { height:36px; border:0; background:transparent; color:#65aaff; font-size:14px; }
.account-header #account-back, .legal-header #legal-back { font-size:32px; line-height:30px; text-align:left; }
.account-scroll { flex:1; min-height:0; overflow-y:auto; padding-bottom:max(28px,env(safe-area-inset-bottom)); }
.wallet-band { padding:26px 20px 24px; display:flex; flex-direction:column; align-items:center; border-bottom:1px solid #242424; background:#101419; }
.wallet-band span { color:#8e98a4; font-size:13px; }
.wallet-band strong { margin:5px 0; color:#fff; font-size:34px; letter-spacing:0; }
.wallet-band small { color:#5f9edc; font-size:12px; }
.account-section { padding:20px; border-bottom:1px solid #242424; }
.account-section h3 { margin-bottom:14px; font-size:15px; }
.account-section label { display:grid; grid-template-columns:82px minmax(0,1fr); align-items:center; min-height:46px; border-bottom:1px solid #202020; color:#888; font-size:13px; }
.account-section label:last-child { border-bottom:0; }
.account-section input { min-width:0; height:40px; border:0; outline:0; background:transparent; color:#e8e8e8; text-align:right; font-size:14px; }
.account-section input:disabled { color:#676767; opacity:1; }
.recharge-options { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
.recharge-options button { height:46px; border:1px solid #2c5e91; border-radius:6px; background:#10243a; color:#75b8ff; font-size:15px; font-weight:700; }
.account-hint { padding:10px 0 0; color:#666; font-size:12px; line-height:1.5; }
.transaction-list > div { min-height:54px; display:flex; align-items:center; justify-content:space-between; gap:12px; border-bottom:1px solid #202020; }
.transaction-list > div:last-child { border-bottom:0; }
.transaction-list span { min-width:0; display:flex; flex-direction:column; gap:4px; }
.transaction-list b { font-size:13px; }
.transaction-list small { color:#666; font-size:11px; }
.transaction-list strong { color:#4fc776; font-size:14px; }
.transaction-list strong.debit { color:#ddd; }
.legal-links { display:grid; }
.legal-links button { height:48px; display:flex; align-items:center; justify-content:space-between; border:0; border-bottom:1px solid #202020; background:transparent; color:#ddd; text-align:left; font-size:14px; }
.legal-links button:last-child { border-bottom:0; }
.legal-links span { color:#555; font-size:24px; }
.legal-content { flex:1; min-height:0; overflow-y:auto; padding:22px 20px max(40px,env(safe-area-inset-bottom)); color:#b8b8b8; font-size:14px; line-height:1.75; user-select:text; -webkit-user-select:text; }
.legal-content h3 { margin:24px 0 8px; color:#f0f0f0; font-size:16px; letter-spacing:0; }
.legal-content h3:first-of-type { margin-top:14px; }
.legal-effective { color:#666; font-size:12px; }

/* ===== Personal center ===== */
#account-page { touch-action:pan-y; background:#090b0e; }
#account-page button, #account-page input { font-family:inherit; }
.account-header {
  flex:none; height:calc(58px + env(safe-area-inset-top)); padding:max(8px,env(safe-area-inset-top)) 14px 8px;
  border-bottom:1px solid #24282e; background:rgba(13,16,20,.96); z-index:3;
}
.account-header h2 { font-size:16px; font-weight:750; }
.account-icon-button { width:40px; color:#b8c0ca!important; }
.account-save-button { color:#64adff!important; font-size:13px!important; font-weight:750; }
.account-save-button:disabled { color:#58626d!important; }
.account-scroll { padding-bottom:max(34px,env(safe-area-inset-bottom)); overscroll-behavior:contain; }
.profile-overview {
  min-height:126px; padding:22px 20px; display:flex; align-items:center; gap:16px;
  border-bottom:1px solid #24282e; background:#101419;
}
.profile-avatar {
  position:relative; width:68px; height:68px; flex:0 0 68px; overflow:hidden;
  display:flex; align-items:center; justify-content:center; border:1px solid #38516b; border-radius:50%;
  background:#173251; color:#8cc4ff; font-size:25px; font-weight:800;
}
.profile-avatar img { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; }
.profile-identity { min-width:0; display:flex; flex-direction:column; gap:5px; }
.profile-identity strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:21px; }
.profile-identity span { color:#939da8; font-size:13px; }
.profile-identity small { min-height:14px; color:#626c77; font-size:11px; }
.account-metrics {
  display:grid; grid-template-columns:1fr 1fr; border-bottom:1px solid #24282e; background:#0d1014;
}
.account-metrics > div { position:relative; min-width:0; min-height:86px; padding:16px 20px; display:flex; flex-direction:column; gap:6px; }
.account-metrics > div + div { border-left:1px solid #24282e; }
.account-metrics span { color:#747e89; font-size:11px; }
.account-metrics strong { overflow:hidden; color:#eef2f6; font-size:20px; letter-spacing:0; text-overflow:ellipsis; }
#account-recharge-entry {
  position:absolute; right:14px; bottom:16px; height:28px; padding:0 10px; border:1px solid #287ed4; border-radius:6px;
  background:#0879e8; color:#fff; font-size:11px; font-weight:750;
}
#account-page .account-section { padding:20px; border-bottom:1px solid #24282e; background:#0d1014; }
#account-page .account-section + .account-section { margin-top:10px; border-top:1px solid #24282e; }
.section-title { min-height:34px; margin-bottom:10px; display:flex; align-items:flex-start; justify-content:space-between; }
.section-title h3 { margin:0!important; color:#eff3f6; font-size:15px; }
.section-title p { margin-top:4px; color:#69737d; font-size:11px; line-height:1.35; }
.preference-row {
  min-height:82px; display:grid; grid-template-columns:minmax(0,1fr) minmax(150px,44%); align-items:center; gap:14px;
  border-top:1px solid #23272c;
}
.preference-row > div:first-child { min-width:0; display:flex; flex-direction:column; gap:5px; }
.preference-row strong { color:#dfe4e8; font-size:13px; }
.preference-row small { color:#68727d; font-size:10px; line-height:1.35; }
.account-segment { height:34px; padding:2px; display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); border:1px solid #30363d; border-radius:6px; background:#171b20; }
.account-segment.two { grid-template-columns:repeat(2,minmax(0,1fr)); }
.account-segment button { min-width:0; border:0; border-radius:4px; background:transparent; color:#737d87; font-size:10px; font-weight:700; }
.account-segment button.active { background:#2a323b; color:#ecf5ff; }
.switch-row { position:relative; grid-template-columns:minmax(0,1fr) 48px; }
.switch-input { position:absolute; width:1px; height:1px; opacity:0; }
.switch-control { position:relative; width:46px; height:27px; border:1px solid #343a42; border-radius:14px; background:#262b31; transition:.18s; }
.switch-control::after { content:''; position:absolute; width:21px; height:21px; left:2px; top:2px; border-radius:50%; background:#aeb5bc; transition:.18s; }
.switch-input:checked + .switch-control { border-color:#0879e8; background:#0879e8; }
.switch-input:checked + .switch-control::after { transform:translateX(19px); background:#fff; }
.profile-form-section .profile-field {
  min-height:54px; display:grid; grid-template-columns:72px minmax(0,1fr); align-items:center; border-top:1px solid #23272c; color:#7d8791; font-size:12px;
}
.profile-form-section .profile-field input { width:100%; height:42px; border:0; outline:0; background:transparent; color:#e5e9ed; text-align:right; font-size:13px; user-select:text; -webkit-user-select:text; }
.profile-form-section .profile-field input::placeholder { color:#505861; }
.readonly-fields { padding-top:12px; display:flex; flex-wrap:wrap; gap:6px 14px; border-top:1px solid #23272c; color:#59636e; font-size:10px; }
.wallet-section .account-hint { padding-top:0; }
.transaction-details { border-top:1px solid #23272c; }
.transaction-details summary { height:48px; display:flex; align-items:center; justify-content:space-between; color:#c7cdd3; font-size:12px; list-style:none; }
.transaction-details summary::-webkit-details-marker { display:none; }
.transaction-details summary span { color:#69727c; font-size:22px; transition:.18s; }
.transaction-details[open] summary span { transform:rotate(90deg); }
.transaction-list > div { min-height:58px; }
.account-links { display:grid; }
.account-links .section-title { margin-bottom:0; }
.account-links > button {
  height:50px; display:flex; align-items:center; justify-content:space-between; border:0; border-top:1px solid #23272c;
  background:transparent; color:#d3d8dd; text-align:left; font-size:13px;
}
.account-links > button b { color:#5b6570; font-size:21px; font-weight:400; }
.account-footer { padding:26px 20px 10px; display:grid; gap:18px; text-align:center; }
#account-logout { height:46px; border:1px solid #58302f; border-radius:6px; background:#211414; color:#ff7068; font-size:13px; font-weight:750; }
.account-footer p { color:#444c55; font-size:10px; }

.recharge-sheet { position:fixed; inset:0; z-index:100; display:flex; align-items:flex-end; justify-content:center; touch-action:manipulation; }
.recharge-sheet[hidden] { display:none; }
.recharge-backdrop { position:absolute; inset:0; background:rgba(0,0,0,.7); }
.recharge-panel {
  position:relative; width:100%; max-width:520px; padding:8px 20px max(20px,env(safe-area-inset-bottom));
  border-top:1px solid #3a414a; border-radius:8px 8px 0 0; background:#15191e;
}
.recharge-handle { width:38px; height:4px; margin:0 auto 12px; border-radius:2px; background:#424952; }
.recharge-panel header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:20px; }
.recharge-panel h3 { font-size:17px; }
.recharge-panel header p { margin-top:4px; color:#747e89; font-size:11px; }
.recharge-panel header button { width:34px; height:34px; border:0; border-radius:50%; background:#262c33; color:#9ca5ae; font-size:23px; line-height:1; }
.recharge-amount-field {
  height:64px; display:grid; grid-template-columns:30px 1fr; align-items:center; border-bottom:1px solid #3c444d; color:#fff; font-size:27px;
}
.recharge-amount-field input { min-width:0; height:58px; border:0; outline:0; background:transparent; color:#fff; font-size:34px; font-weight:700; user-select:text; -webkit-user-select:text; }
.recharge-amount-field input::-webkit-inner-spin-button,
.recharge-amount-field input::-webkit-outer-spin-button { margin:0; -webkit-appearance:none; }
.recharge-amount-field input[type=number] { appearance:textfield; -moz-appearance:textfield; }
.recharge-amount-field input::placeholder { color:#404851; }
.recharge-options { margin:16px 0; display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:8px; }
.recharge-options button { height:42px; border:1px solid #343b44; border-radius:6px; background:#20252b; color:#aeb7c0; font-size:13px; font-weight:700; }
.recharge-options button.active { border-color:#328fe9; background:#173454; color:#86c4ff; }
.recharge-submit { width:100%; height:48px; border:0; border-radius:6px; background:#0879e8; color:#fff; font-size:14px; font-weight:800; }
.recharge-submit:disabled { background:#2a3642; color:#75808a; }
.recharge-note { margin-top:10px; color:#565f69; text-align:center; font-size:10px; }

@media (max-width:374px) {
  .home-header { padding-left:14px; padding-right:10px; }
  .home-header h2 { font-size:20px; }
  .btn-header-action { padding:0 6px; }
  .preference-row { grid-template-columns:1fr; gap:10px; padding:15px 0; }
  .switch-row { grid-template-columns:minmax(0,1fr) 48px; }
  .account-segment { width:100%; }
  .account-metrics > div { padding-left:14px; padding-right:14px; }
  .account-metrics strong { font-size:17px; }
}
.game-list { flex:1; overflow-y:auto; padding:8px 16px 24px; display:flex; flex-direction:column; gap:10px; }
.game-card {
  width:100%; min-height:86px; border:1px solid #1f1f1f; border-radius:12px;
  background:#101010; color:#fff; display:flex; align-items:center; gap:14px;
  padding:14px; text-align:left; cursor:pointer;
}
.game-card:active { background:#171717; }
.game-cover {
  width:56px; height:56px; border-radius:10px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  background:#20242b; color:#69a7ff; font-size:24px; font-weight:700;
}
.game-info { min-width:0; display:flex; flex-direction:column; gap:5px; }
.game-info strong { font-size:17px; font-weight:700; }
.game-info small { color:#777; font-size:12px; line-height:1.35; }
.game-host-count { color:#666b73; font-size:11px; line-height:1.2; }
.game-host-count.available { color:#45c86b; font-weight:700; }
.game-actions { margin-left:auto; display:flex; flex-direction:column; gap:7px; flex-shrink:0; }
.game-actions button {
  min-width:54px; height:30px; border-radius:6px; border:1px solid #2b2b2b;
  background:#191919; color:#aaa; font-size:12px; font-weight:600;
}
.game-actions .game-play-btn { border-color:#247bd6; background:#0879e8; color:#fff; }
.game-control-badge { color:#6fb0ff; font-size:11px; text-align:center; white-space:nowrap; }
.host-list { flex:1; overflow-y:auto; padding:8px 16px 20px; }
.host-card {
  background:#111; border-radius:14px; padding:18px; margin-bottom:10px;
  display:flex; justify-content:space-between; align-items:center;
}
.host-card .info h3 { font-size:16px; font-weight:600; display:flex; align-items:center; gap:8px; }
.host-card .info p { font-size:12px; color:#666; }
.host-card .info { flex:1; min-width:0; }
.host-actions { display:flex; align-items:center; gap:8px; flex-shrink:0; }
.dot {
  display:inline-block; width:8px; height:8px; border-radius:50%; flex-shrink:0;
}
.dot.online { background:#34c759; box-shadow:0 0 6px #34c759; }
.dot.offline { background:#333; }
.btn-connect {
  padding:10px 24px; border:none; border-radius:10px;
  background:#007aff; color:#fff; font-size:14px; font-weight:600; cursor:pointer;
}
.btn-connect:disabled { opacity:.4; }
.empty-state { text-align:center; padding:80px 20px; color:#666; }
.empty-state .icon { font-size:48px; margin-bottom:12px; }
.empty-state p { font-size:14px; }
.empty-state .empty-hint { max-width:340px; margin:8px auto 0; color:#777; font-size:12px; line-height:1.5; }
.empty-action { margin-top:16px; }

/* ===== Player (Remote Desktop - Fullscreen) ===== */
#player-page {
  background:#000;
  -webkit-touch-callout:none;
  -webkit-user-select:none;
  user-select:none;
}
#player-page *, #player-page button {
  -webkit-touch-callout:none!important;
  -webkit-user-select:none!important;
  user-select:none!important;
  -webkit-user-drag:none;
}

/* Keep the source aspect ratio by default; the player menu can switch to cover. */
#stream-video, #screen-view {
  position:absolute; inset:0;
  width:100%; height:100%;
  object-fit:contain;
  object-position:center;
  z-index:1;
}

/* Connecting overlay */
#connecting-overlay {
  position:absolute; inset:0; z-index:10;
  display:flex; flex-direction:column;
  align-items:center; justify-content:center;
  background:#111;
  transition:opacity .4s;
}
#connecting-overlay.hidden { opacity:0; pointer-events:none; }
.spinner {
  width:28px; height:28px;
  border:3px solid #222; border-top-color:#007aff;
  border-radius:50%;
  animation:spin .7s linear infinite;
  margin-bottom:14px;
}
@keyframes spin { to { transform:rotate(360deg); } }
#connecting-overlay .text { font-size:14px; color:#666; }

/* Top HUD - shows in both portrait & landscape */
#conn-hud {
  position:absolute; top:12px; left:50%; transform:translateX(-50%);
  z-index:1001;
  background:rgba(0,0,0,.5);
  -webkit-backdrop-filter:blur(8px); backdrop-filter:blur(8px);
  padding:5px 14px; border-radius:20px;
  font-size:12px; color:rgba(255,255,255,.6);
  display:flex; align-items:center; gap:6px;
  pointer-events:none;
}
#conn-hud .live-dot { width:6px; height:6px; border-radius:50%; background:#34c759; }

/* Mode toggle - floating at bottom center */
#mode-btn {
  position:absolute; bottom:max(20px,env(safe-area-inset-bottom,20px));
  left:50%; transform:translateX(-50%);
  z-index:1001;
  background:rgba(255,255,255,.12);
  -webkit-backdrop-filter:blur(12px); backdrop-filter:blur(12px);
  border:1px solid rgba(255,255,255,.1);
  color:#fff;
  padding:10px 22px;
  border-radius:24px;
  font-size:13px;
  cursor:pointer;
  display:none;
  white-space:nowrap;
  transition:background .2s;
}
#mode-btn:active { background:rgba(255,255,255,.2); }

/* Mouse control panel */
#mouse-overlay {
  position:fixed; left:50%; bottom:max(12px,env(safe-area-inset-bottom)); z-index:999;
  width:min(92vw,560px); height:min(42vh,320px); transform:translateX(-50%);
  display:grid; grid-template-rows:minmax(0,1fr) 52px; gap:8px;
  padding:8px; border:1px solid rgba(255,255,255,.14); border-radius:8px;
  background:transparent;
  touch-action:none;
}
#mouse-touchpad {
  min-width:0; min-height:0; display:flex; align-items:center; justify-content:center;
  border:1px solid rgba(255,255,255,.2); border-radius:6px;
  background:rgba(255,255,255,.07); color:rgba(255,255,255,.48);
  font-size:13px; font-weight:700; touch-action:none;
}
#mouse-touchpad.active { background:rgba(255,255,255,.13); border-color:rgba(100,174,255,.65); }
.mouse-button-row { display:grid; grid-template-columns:1fr 1fr; gap:8px; min-width:0; }
.mouse-button-row button {
  min-width:0; height:52px; border:1px solid rgba(255,255,255,.2); border-radius:6px;
  background:rgba(255,255,255,.1); color:#fff; font-size:14px; font-weight:700;
  touch-action:none;
}
.mouse-button-row button.active { background:rgba(0,122,255,.48); border-color:rgba(92,174,255,.9); }

@media (orientation:landscape) {
  #mouse-overlay {
    width:min(58vw,620px); height:min(58vh,340px);
    bottom:max(8px,env(safe-area-inset-bottom));
  }
}

#audio-btn {
  position:absolute; top:12px; right:12px;
  z-index:1001;
  width:38px; height:38px;
  display:none;
  align-items:center; justify-content:center;
  background:rgba(0,0,0,.5);
  -webkit-backdrop-filter:blur(8px); backdrop-filter:blur(8px);
  border:1px solid rgba(255,255,255,.12);
  border-radius:50%;
  color:#fff;
  font-size:17px;
  cursor:pointer;
}
#audio-btn.blocked { border-color:rgba(255,204,0,.55); }
#audio-btn:active { background:rgba(255,255,255,.16); }

/* ===== Per-game layout editor ===== */
#layoutEditor-page { background:#0b0c0e; touch-action:none; }
.layout-header {
  height:64px; padding:8px 12px; display:grid; grid-template-columns:42px 1fr 62px;
  align-items:center; gap:8px; border-bottom:1px solid #23262b; background:#111317; z-index:2;
}
.layout-header h2 { font-size:16px; line-height:1.2; letter-spacing:0; }
.layout-header p { margin-top:3px; color:#777; font-size:11px; }
.layout-icon-btn, .layout-save-btn {
  height:36px; border-radius:6px; border:1px solid #30343a; background:#191c21; color:#fff;
}
.layout-icon-btn { width:36px; font-size:28px; line-height:28px; }
.layout-save-btn { background:#0879e8; border-color:#0879e8; font-size:13px; font-weight:700; }
.layout-workspace {
  flex:1; min-height:0; padding:12px; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px;
  background:#08090a;
}
.layout-profile-tabs {
  display:flex; flex:0 0 34px; padding:3px; border:1px solid #30343a; border-radius:6px; background:#15181c;
}
.layout-profile-tabs[hidden] { display:none; }
.layout-profile-tabs button {
  min-width:78px; padding:0 16px; border:0; border-radius:4px; background:transparent; color:#8d929a; font-size:12px; font-weight:700;
}
.layout-profile-tabs button.active { background:#0879e8; color:#fff; }
.layout-stage {
  position:relative; width:min(100%,960px); aspect-ratio:16/9; max-height:calc(100% - 42px); overflow:hidden;
  border:1px solid #343840; border-radius:6px; background:#171a1f;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.02);
}
.layout-stage::before {
  content:''; position:absolute; inset:0; pointer-events:none; opacity:.16;
  background-image:linear-gradient(#59606b 1px,transparent 1px),linear-gradient(90deg,#59606b 1px,transparent 1px);
  background-size:10% 10%;
}
.gamepad-layout-editor {
  width:min(100%,560px); display:grid; gap:20px; align-content:center;
}
.gamepad-layout-editor[hidden] { display:none; }
.gamepad-layout-preview {
  height:150px; display:grid; grid-template-columns:1fr 1fr; align-items:center; gap:40px;
  padding:24px; border:1px solid #343840; border-radius:6px; background:#171a1f;
}
.gamepad-layout-preview div { display:grid; justify-items:center; gap:8px; }
.gamepad-layout-preview b {
  width:76px; height:36px; display:flex; align-items:center; justify-content:center;
  border:1px solid #4a505a; border-radius:6px; background:#242830; color:#fff; font-size:14px;
}
.gamepad-layout-preview span { min-height:20px; color:#c8ccd2; font-size:13px; font-weight:700; }
.gamepad-layout-fields { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.gamepad-layout-fields label { display:grid; gap:7px; color:#999; font-size:12px; }
.gamepad-layout-fields input {
  width:100%; height:42px; padding:0 12px; border:1px solid #343840; border-radius:6px;
  outline:none; background:#0d0f12; color:#fff; font-size:15px;
}
.gamepad-layout-fields input:focus { border-color:#0879e8; }
.gamepad-layout-reset {
  height:42px; border:1px solid #3a3e46; border-radius:6px; background:#202329; color:#ff7169; font-weight:700;
}
.layout-preview-button {
  position:absolute; z-index:3; min-width:36px; min-height:30px; padding:3px; overflow:hidden;
  border:1px solid rgba(255,255,255,.36); border-radius:50%; background:rgba(8,121,232,.72);
  color:#fff; font-size:11px; font-weight:700; letter-spacing:0; touch-action:none;
}
.layout-preview-stick {
  position:absolute; z-index:2; border:2px solid rgba(255,255,255,.26); border-radius:50%;
  background:rgba(0,0,0,.28); color:#aaa; font-size:10px; touch-action:none;
}
.layout-preview-stick i {
  position:absolute; width:42%; height:42%; left:29%; top:29%; border-radius:50%;
  background:rgba(255,255,255,.16); border:1px solid rgba(255,255,255,.24);
}
.layout-preview-stick span { position:absolute; left:0; right:0; bottom:-17px; text-align:center; }
.layout-preview-look {
  position:absolute; z-index:1; display:flex; align-items:center; justify-content:center;
  border:1px dashed rgba(255,255,255,.25); border-radius:6px; background:rgba(255,255,255,.035);
  color:#777; font-size:11px; touch-action:none;
}
.layout-toolbar {
  height:68px; padding:6px 12px max(6px,env(safe-area-inset-bottom)); display:grid;
  grid-template-columns:repeat(5,1fr); gap:6px; border-top:1px solid #23262b; background:#111317;
}
.layout-toolbar button {
  border:0; border-radius:6px; background:transparent; color:#aaa; display:flex;
  flex-direction:column; align-items:center; justify-content:center; gap:2px; font-size:10px;
}
.layout-toolbar b { color:#e7e9ed; font-size:20px; line-height:22px; font-weight:500; }
.layout-sheet {
  position:absolute; inset:0; z-index:30; background:rgba(0,0,0,.62); display:flex;
  align-items:flex-end; justify-content:center; touch-action:auto;
}
.layout-sheet[hidden] { display:none; }
.layout-sheet-panel {
  width:100%; max-width:560px; max-height:88%; overflow-y:auto; padding:16px 18px max(18px,env(safe-area-inset-bottom));
  border-top:1px solid #343840; border-radius:8px 8px 0 0; background:#17191d;
}
.layout-sheet-panel.compact { padding-bottom:max(22px,env(safe-area-inset-bottom)); }
.layout-sheet-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.layout-sheet-head h3 { font-size:17px; letter-spacing:0; }
.layout-sheet-head button { width:34px; height:34px; border:0; background:transparent; color:#888; font-size:26px; }
.layout-sheet-panel > label, .layout-size-row label {
  display:flex; flex-direction:column; gap:6px; margin:11px 0; color:#999; font-size:12px;
}
.layout-sheet-panel input:not([type=range]), .layout-sheet-panel select {
  width:100%; height:42px; padding:0 12px; border:1px solid #343840; border-radius:6px;
  outline:none; background:#0d0f12; color:#fff; font-size:15px;
}
.layout-sheet-panel input:focus, .layout-sheet-panel select:focus { border-color:#0879e8; }
.layout-size-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.layout-size-row input { width:100%; }
.layout-key-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:8px; }
.layout-key-grid label { display:flex; flex-direction:column; gap:5px; color:#888; font-size:11px; }
.layout-sheet-actions { display:grid; grid-template-columns:1fr 2fr; gap:10px; margin-top:18px; }
.layout-sheet-actions button, .layout-transfer-actions button {
  height:44px; border-radius:6px; border:1px solid #363a42; background:#22252b; color:#ddd; font-weight:700;
}
.layout-sheet-actions .primary { border-color:#0879e8; background:#0879e8; color:#fff; }
.layout-sheet-actions .danger { color:#ff6259; }
.layout-switch { flex-direction:row!important; align-items:center; justify-content:space-between; padding:8px 0; }
.layout-switch span { display:flex; flex-direction:column; gap:3px; }
.layout-switch b { color:#eee; font-size:14px; }
.layout-switch small { color:#6f737b; font-size:11px; }
.layout-switch input { width:22px; height:22px; accent-color:#0879e8; }
.layout-sheet-note { color:#858991; font-size:13px; line-height:1.5; }
.layout-transfer-actions { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:16px; }

@media (orientation:landscape) and (max-height:520px) {
  .layout-header { height:54px; }
  .layout-toolbar { position:absolute; right:8px; top:62px; width:58px; height:auto; grid-template-columns:1fr; z-index:4; border:1px solid #2d3138; border-radius:6px; padding:4px; }
  .layout-toolbar button { height:48px; }
  .layout-workspace { padding:6px 76px 6px 8px; gap:4px; }
  .layout-profile-tabs { position:absolute; top:60px; left:16px; z-index:5; height:30px; }
  .layout-profile-tabs button { min-width:64px; padding:0 10px; }
  .layout-stage { width:min(100%,calc((100vh - 66px) * 16 / 9),960px); max-height:100%; }
  .gamepad-layout-editor { grid-template-columns:220px 1fr; gap:12px; }
  .gamepad-layout-preview { height:120px; gap:18px; padding:14px; }
  .gamepad-layout-fields { align-content:center; }
  .gamepad-layout-reset { grid-column:2; }
}

/* ===== Virtual Keyboard Overlay ===== */
#vk-overlay {
  position:fixed; bottom:0; left:0; right:0;
  z-index:999;
  max-height:50vh;
  padding:4px 3px max(4px,env(safe-area-inset-bottom));
  background:rgba(10,12,15,.85);
  -webkit-backdrop-filter:blur(10px); backdrop-filter:blur(10px);
  border-top:1px solid rgba(255,255,255,.06);
  touch-action:none; -webkit-user-select:none; user-select:none;
  -webkit-touch-callout:none;
  display:flex; flex-direction:column;
  overflow:hidden;
}
#vk-overlay .vk-rows {
  display:flex; flex-direction:column; flex:1; min-height:0;
  gap:2px;
}
.vk-r { display:flex; gap:2px; justify-content:center; flex:1; min-height:0; }
.vk-k {
  display:flex; align-items:center; justify-content:center;
  min-height:0; height:auto;
  border-radius:4px;
  background:rgba(255,255,255,.11);
  border:1px solid rgba(255,255,255,.07);
  color:#ccc;
  font-size:10px; font-weight:600;
  -webkit-user-select:none; user-select:none;
  touch-action:none; cursor:default;
  will-change:transform,background;
  flex:1 0 auto;
  transition:background .08s, transform .08s;
}
.vk-k:active { background:rgba(0,122,255,.5); }
.vk-d { background:rgba(0,122,255,.55)!important; border-color:rgba(0,122,255,.7)!important; transform:scale(.94); color:#fff; }
.vk-a { background:rgba(0,122,255,.35)!important; border-color:rgba(0,122,255,.5)!important; color:#fff; }
.vk-sp { flex:5 1 auto; min-width:50px; }
.vk-arrow-row .vk-k { font-size:12px; }
#vk-hide-btn {
  position:absolute; right:4px; top:2px; z-index:2;
  width:20px; height:20px; border-radius:50%;
  border:0; background:rgba(255,255,255,.08);
  color:rgba(255,255,255,.4); font-size:10px;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
}
#vk-hide-btn:active { background:rgba(255,255,255,.18); }

/* ===== Menu Panel ===== */
#menu-panel {
  display:none;
  position:fixed; inset:0; z-index:2000;
  background:rgba(0,0,0,.45);
  -webkit-backdrop-filter:blur(6px); backdrop-filter:blur(6px);
  align-items:flex-end; justify-content:center;
  touch-action:none; -webkit-user-select:none; user-select:none;
  -webkit-touch-callout:none;
}
#menu-panel * { -webkit-touch-callout:none; -webkit-user-select:none; user-select:none; }
#menu-panel-inner {
  width:100%; max-width:400px;
  background:rgba(20,22,26,.95);
  border-radius:16px 16px 0 0;
  padding:16px 20px max(24px,env(safe-area-inset-bottom));
  max-height:70vh; overflow-y:auto; overscroll-behavior:contain; touch-action:pan-y;
  -webkit-overflow-scrolling:touch;
}
#menu-panel-inner button { touch-action:pan-y!important; }
#menu-hud { text-align:center; margin-bottom:16px; }
#menu-player { font-size:17px; font-weight:700; color:#fff; }
#menu-room { font-size:12px; color:#888; margin-top:2px; }
#menu-stats { font-size:11px; color:#666; margin-top:4px; }
.menu-section {
  font-size:11px; color:#555; text-transform:uppercase; letter-spacing:.5px;
  margin:16px 0 8px; padding-bottom:4px; border-bottom:1px solid rgba(255,255,255,.06);
}
.menu-guide-inline { display:grid; gap:8px; }
#menu-guide-block[hidden] { display:none; }
#menu-panel-inner.menu-guide-open > :not(#menu-guide-block) { display:none!important; }
#menu-guide-block { min-height:100%; }
.menu-guide-heading {
  position:sticky; top:0; z-index:3; display:flex; align-items:center; justify-content:space-between; gap:12px;
  min-height:52px; margin-bottom:12px; padding:6px 0 10px; border-bottom:1px solid rgba(255,255,255,.1);
  background:#14161a;
}
.menu-guide-heading strong { color:#fff; font-size:15px; }
#menu-guide-close {
  flex:none; width:96px; height:40px; border:1px solid rgba(255,69,58,.55); border-radius:8px;
  background:rgba(255,69,58,.22); color:#ff8a82; font-size:13px; font-weight:700; touch-action:none;
}
#menu-guide-close:active { background:rgba(255,69,58,.38); }
.menu-guide-inline select {
  width:100%; height:40px; padding:0 10px; border:1px solid rgba(255,255,255,.14); border-radius:6px;
  outline:none; background:#15181d; color:#fff; font-size:12px;
}
.menu-guide-meta { min-width:0; display:flex; align-items:center; justify-content:space-between; gap:8px; }
.menu-guide-meta strong { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#e3e6ea; font-size:12px; }
.menu-guide-meta span { flex-shrink:0; color:#777d86; font-size:10px; }
.menu-guide-actions { display:grid; grid-template-columns:1fr; gap:6px; }
.menu-guide-actions button {
  height:36px; border:1px solid rgba(255,255,255,.12); border-radius:6px;
  display:flex; align-items:center; justify-content:center; background:rgba(255,255,255,.06);
  color:#bfc5cd; font-size:11px; font-weight:700; text-decoration:none;
}
.menu-guide-actions button { width:100%; border-color:#247bd6; background:rgba(0,122,255,.22); color:#fff; touch-action:none; }
.menu-guide-actions button:active { background:rgba(0,122,255,.38); }
.menu-guide-loading { padding:12px; color:#747982; text-align:center; font-size:11px; }
.guide-content-modal {
  position:fixed; inset:0; z-index:4000; display:flex; flex-direction:column;
  background:#0d0f12; color:#fff; touch-action:manipulation;
}
.guide-content-header {
  flex:none; min-height:60px; padding:max(8px,env(safe-area-inset-top)) 12px 8px;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  border-bottom:1px solid rgba(255,255,255,.1); background:#15181d;
}
.guide-content-header div { min-width:0; display:grid; gap:3px; }
.guide-content-header strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:14px; }
.guide-content-header span { color:#858b94; font-size:10px; }
#guide-content-close {
  flex:none; width:76px; height:40px; border:1px solid rgba(255,69,58,.55); border-radius:8px;
  background:rgba(255,69,58,.22); color:#ff8a82; font-size:13px; font-weight:700; touch-action:none;
}
#guide-content-close:active { background:rgba(255,69,58,.38); }
.guide-content-frame-wrap { position:relative; flex:1; min-height:0; background:#fff; }
.guide-content-loading {
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  background:#fff; color:#666; font-size:13px;
}
.guide-content-frame { position:absolute; inset:0; z-index:1; width:100%; height:100%; border:0; background:#fff; }
.controls-guide-modal {
  position:fixed; inset:0; z-index:4200; display:flex; flex-direction:column;
  background:#0e1115; color:#fff; touch-action:manipulation; overflow:hidden;
}
.controls-guide-header {
  flex:none; min-height:62px; padding:max(8px,env(safe-area-inset-top)) 14px 8px;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  border-bottom:1px solid #2a3038; background:#171b20;
}
.controls-guide-header div { min-width:0; display:grid; gap:3px; }
.controls-guide-header strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:15px; }
.controls-guide-header span { color:#8e97a2; font-size:11px; }
#controls-guide-close {
  flex:none; width:40px; height:40px; border:1px solid #3a424c; border-radius:6px;
  background:#242a31; color:#d8dde3; font-size:25px; line-height:1; touch-action:none;
}
#controls-guide-close:active { background:#343c45; }
.controls-guide-loading { flex:1; display:flex; align-items:center; justify-content:center; color:#818a94; font-size:13px; }
.controls-guide-content {
  flex:1; min-height:0; overflow:auto; padding:16px max(14px,env(safe-area-inset-right)) max(20px,env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left));
}
.controls-markdown-wrap {
  width:min(100%,760px); margin:0 auto; overflow:hidden; border:1px solid #343b44; background:#11151a;
}
.controls-markdown-table {
  width:100%; border-collapse:collapse; table-layout:fixed; color:#dfe4e9; font-size:13px;
}
.controls-markdown-table th,
.controls-markdown-table td {
  padding:11px 12px; text-align:left; vertical-align:middle; border-right:1px solid #343b44; border-bottom:1px solid #343b44;
  line-height:1.45; overflow-wrap:anywhere;
}
.controls-markdown-table th:last-child,
.controls-markdown-table td:last-child { border-right:0; }
.controls-markdown-table tbody tr:last-child td { border-bottom:0; }
.controls-markdown-table th { background:#20262d; color:#fff; font-size:12px; font-weight:700; }
.controls-markdown-table th:first-child,
.controls-markdown-table td:first-child { width:36%; }
.controls-markdown-table code {
  color:#f3f5f7; font-family:inherit; font-size:12px; font-weight:700; white-space:normal;
}
.cast-pair-modal {
  position:fixed; inset:0; z-index:4500; display:flex; align-items:center; justify-content:center;
  padding:18px; background:rgba(0,0,0,.72); touch-action:manipulation;
}
.cast-pair-dialog {
  width:min(100%,380px); padding:18px; border:1px solid #343941; border-radius:8px;
  background:#15181c; color:#fff; display:grid; gap:12px;
}
.cast-pair-header { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.cast-pair-header strong { font-size:16px; }
#cast-pair-close {
  width:36px; height:36px; border:1px solid #3a4048; border-radius:6px;
  background:#22262c; color:#c8cdd3; font-size:24px; line-height:1;
}
.cast-pair-url { color:#8e969f; font-size:12px; line-height:1.5; overflow-wrap:anywhere; }
.cast-pair-url strong { color:#cfd4da; font-weight:600; }
.cast-pair-dialog label { color:#a6adb5; font-size:13px; }
#cast-pair-code {
  width:100%; height:54px; border:1px solid #414852; border-radius:6px; outline:none;
  background:#0b0d10; color:#fff; text-align:center; font-family:ui-monospace,monospace;
  font-size:28px; font-weight:700; letter-spacing:0;
}
#cast-pair-code:focus { border-color:#5aa9ff; }
#cast-pair-status { min-height:18px; color:#63d880; font-size:12px; text-align:center; }
#cast-pair-status.error { color:#ff7169; }
#cast-pair-connect {
  width:100%; height:46px; border:0; border-radius:6px; background:#0879e8;
  color:#fff; font-size:14px; font-weight:700;
}
#cast-pair-connect:disabled { background:#292e35; color:#69717a; }
.menu-mode-list { display:flex; gap:8px; }
.menu-mode-btn {
  flex:1; height:48px; border:1px solid rgba(255,255,255,.12); border-radius:10px;
  background:rgba(255,255,255,.06); color:#ccc; font-size:13px; font-weight:600;
  display:flex; align-items:center; justify-content:center; gap:4px;
  cursor:pointer; touch-action:none;
}
.menu-mode-btn:active { background:rgba(255,255,255,.12); }
.menu-mode-active { background:rgba(0,122,255,.25)!important; border-color:rgba(0,122,255,.5)!important; color:#fff!important; }
.menu-display-list {
  display:grid; grid-template-columns:repeat(2,minmax(0,1fr));
  height:38px; border:1px solid rgba(255,255,255,.12); border-radius:8px;
  overflow:hidden;
}
.menu-display-btn {
  min-width:0; border:0; border-right:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.04); color:#888; font-size:11px; font-weight:700;
  cursor:pointer; touch-action:none;
}
.menu-display-btn:last-child { border-right:0; }
.menu-display-btn:active { background:rgba(255,255,255,.12); }
.menu-quality-list {
  display:grid; grid-template-columns:repeat(4,minmax(0,1fr));
  height:38px; border:1px solid rgba(255,255,255,.12); border-radius:8px;
  overflow:hidden;
}
.menu-quality-btn {
  min-width:0; border:0; border-right:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.04); color:#888; font-size:11px; font-weight:700;
  cursor:pointer; touch-action:none;
}
.menu-quality-btn:last-child { border-right:0; }
.menu-quality-btn:active { background:rgba(255,255,255,.12); }
.menu-quality-active { background:rgba(48,209,88,.2)!important; color:#fff!important; }
.menu-fps-list {
  display:grid; grid-template-columns:repeat(3,minmax(0,1fr));
  height:38px; border:1px solid rgba(255,255,255,.12); border-radius:8px;
  overflow:hidden;
}
.menu-fps-btn {
  min-width:0; border:0; border-right:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.04); color:#888; font-size:11px; font-weight:700;
  cursor:pointer; touch-action:none;
}
.menu-fps-btn:last-child { border-right:0; }
.menu-fps-btn:active { background:rgba(255,255,255,.12); }
.menu-setting-confirm {
  position:fixed; inset:0; z-index:4600; display:flex; align-items:center; justify-content:center;
  padding:20px; background:rgba(0,0,0,.72); touch-action:none;
}
.menu-setting-dialog {
  width:min(100%,340px); padding:20px; border:1px solid #3a414a; border-radius:8px;
  background:#171b20; color:#fff; box-shadow:0 18px 50px rgba(0,0,0,.5);
}
.menu-setting-dialog h3 { font-size:16px; }
.menu-setting-dialog p { min-height:48px; margin:10px 0 18px; color:#9ba4ae; font-size:13px; line-height:1.6; }
.menu-setting-dialog div { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.menu-setting-dialog button { height:44px; border:1px solid #363d46; border-radius:6px; background:#23282f; color:#b8c0c8; font-size:13px; font-weight:700; touch-action:manipulation; }
.menu-setting-dialog button[data-confirm="apply"] { border-color:#0879e8; background:#0879e8; color:#fff; }
.menu-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-bottom:8px; }
.menu-act-btn {
  height:42px; border:1px solid rgba(255,255,255,.1); border-radius:8px;
  background:rgba(255,255,255,.06); color:#bbb; font-size:12px; font-weight:600;
  display:flex; align-items:center; justify-content:center; gap:4px;
  cursor:pointer; touch-action:none;
}
.menu-act-btn:active { background:rgba(255,255,255,.14); }
.menu-disconn-btn {
  width:100%; height:44px; border:0; border-radius:10px;
  background:rgba(255,69,58,.2); color:#ff453a; font-size:14px; font-weight:700;
  margin-top:12px; cursor:pointer; touch-action:none;
}
.menu-disconn-btn:active { background:rgba(255,69,58,.35); }

/* Landscape: menu as right sidebar */
@media (orientation:landscape) and (min-width:568px) {
  #menu-panel {
    align-items:stretch; justify-content:flex-end;
    background:rgba(0,0,0,.3);
  }
  #menu-panel-inner {
    width:300px; max-width:40vw; max-height:100vh; height:100%;
    border-radius:12px 0 0 12px;
    padding:16px 18px max(20px,env(safe-area-inset-bottom));
    overflow-y:auto;
  }
  #menu-panel-inner .menu-mode-list { flex-direction:column; gap:4px; }
  #menu-panel-inner .menu-mode-btn { height:42px; font-size:12px; }
  #menu-panel-inner .menu-actions { grid-template-columns:1fr 1fr; gap:6px; }
  #menu-panel-inner .menu-act-btn { height:38px; font-size:11px; }
}

/* Landscape: even more compact (keyboard) */
@media (orientation:landscape) {
  #vk-overlay { max-height:45vh; padding:2px 6px max(2px,env(safe-area-inset-bottom)); }
  #vk-overlay .vk-rows { gap:1px; }
  .vk-r { gap:1px; }
  .vk-k { font-size:9px; border-radius:3px; }
  .vk-arrow-row .vk-k { font-size:11px; }
}
