:root {
  --bg: #0c0a09;
  --glass: rgba(22, 19, 17, 0.62);
  --glass-strong: rgba(19, 16, 14, 0.96); /* dialogs: near-opaque so nothing behind shows through the text */
  --line: rgba(255, 236, 200, 0.12);
  --line-strong: rgba(255, 236, 200, 0.22);
  --text: #f3ece0;
  --muted: #b5a891;
  --dim: #7f7464;
  --gold: #f0c66b;
  --gold-2: #d9a441;
  --teal: #5fe1c9;
  --red: #ff6b5b;
  --green: #7ee08a;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
body { -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
input, textarea { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; outline: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55) 100%); }

/* ---------------------------------------------------------------- generic controls */
.glass { background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); border: 1px solid var(--line); box-shadow: var(--shadow); }
.btn { appearance: none; border: 1px solid var(--line-strong); background: rgba(255, 245, 225, 0.06); color: var(--text); padding: 12px 18px; border-radius: 12px; cursor: pointer; font-weight: 600; letter-spacing: 0.2px; transition: transform 0.12s ease, background 0.2s, border-color 0.2s, box-shadow 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; }
.btn:hover { background: rgba(255, 245, 225, 0.12); border-color: rgba(255, 236, 200, 0.35); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .icon-btn:focus-visible, .seg button:focus-visible, input:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn-primary { background: linear-gradient(180deg, #f6d27e, #d9a441); color: #2a1b06; border-color: rgba(255, 220, 150, 0.7); box-shadow: 0 6px 20px rgba(217, 164, 65, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
.btn-primary:hover { background: linear-gradient(180deg, #ffdc8c, #e2ad4b); }
.btn-danger { border-color: rgba(255, 107, 91, 0.5); color: #ffb3aa; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn.big { width: 100%; padding: 15px 20px; font-size: 1.05rem; justify-content: flex-start; white-space: nowrap; }
.btn.big .ico { width: 26px; height: 26px; flex: none; }
.btn .sub { font-weight: 400; color: var(--muted); font-size: 0.82rem; margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 8px; }
.btn-primary .sub { color: rgba(42, 27, 6, 0.7); }
.icon-btn { appearance: none; border: 1px solid transparent; background: transparent; width: 44px; height: 44px; border-radius: 12px; display: inline-grid; place-items: center; cursor: pointer; color: var(--text); transition: background 0.15s, transform 0.12s; }
.icon-btn:hover { background: rgba(255, 245, 225, 0.1); }
.icon-btn:active { transform: scale(0.94); }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.seg { display: flex; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; appearance: none; border: 0; background: transparent; color: var(--muted); padding: 10px 8px; border-radius: 9px; cursor: pointer; font-weight: 600; min-height: 40px; transition: background 0.15s, color 0.15s; }
.seg button.on { background: rgba(240, 198, 107, 0.18); color: var(--gold); box-shadow: inset 0 0 0 1px rgba(240, 198, 107, 0.45); }
.seg button small { display: block; font-weight: 400; font-size: 0.72rem; opacity: 0.8; margin-top: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.82rem; color: var(--muted); font-weight: 600; letter-spacing: 0.3px; }
.field input { appearance: none; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line-strong); color: var(--text); border-radius: 11px; padding: 13px 14px; font-size: 1rem; min-height: 46px; transition: border-color 0.15s, box-shadow 0.15s; }
.field input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(95, 225, 201, 0.18); }
.field .hint { font-size: 0.78rem; color: var(--dim); }
.form-error { color: #ffb3aa; background: rgba(255, 107, 91, 0.1); border: 1px solid rgba(255, 107, 91, 0.3); border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; margin-bottom: 12px; }
.form-ok { color: #b9f3c2; background: rgba(126, 224, 138, 0.1); border: 1px solid rgba(126, 224, 138, 0.3); border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; margin-bottom: 12px; }
.link { appearance: none; background: none; border: 0; color: var(--gold); cursor: pointer; padding: 4px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.sep { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: rgba(255, 255, 255, 0.15); position: relative; cursor: pointer; transition: background 0.2s; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(18px); }
input[type=range] { width: 100%; accent-color: var(--gold); }

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

#loader { display: grid; place-items: center; background: radial-gradient(ellipse at center, #1b1511 0%, #070605 70%); z-index: 50; transition: opacity 0.6s ease; }
#loader.fade { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; width: min(320px, 80vw); }
.loader-logo { width: 84px; height: 84px; margin: 0 auto 18px; color: var(--gold); animation: float 2.4s ease-in-out infinite; filter: drop-shadow(0 6px 24px rgba(240, 198, 107, 0.35)); }
.loader-title { font-family: var(--serif); font-size: 2rem; letter-spacing: 1px; margin-bottom: 18px; }
.loader-title span { color: var(--gold); }
.loader-bar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-2), var(--gold)); transition: width 0.35s ease; }
.loader-text { margin-top: 12px; color: var(--muted); font-size: 0.9rem; min-height: 1.3em; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* Main menu */
#menu { pointer-events: none; z-index: 10; }
#menu.active { display: flex; align-items: center; padding: calc(24px + var(--sat)) calc(24px + var(--sar)) calc(24px + var(--sab)) calc(clamp(24px, 6vw, 90px) + var(--sal)); }
.menu-card { pointer-events: auto; width: min(420px, 100%); border-radius: 24px; padding: 30px 26px 22px; animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.brand { font-family: var(--serif); font-weight: 600; font-size: clamp(2.3rem, 5vw, 3rem); margin: 0; letter-spacing: 0.5px; line-height: 1; display: flex; align-items: center; gap: 12px; }
.brand svg { width: 46px; height: 46px; color: var(--gold); flex: none; }
.brand span { color: var(--gold); }
.tagline { color: var(--muted); margin: 10px 0 22px; line-height: 1.45; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; }
.menu-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); gap: 10px; }
.account-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account-chip .avatar { width: 34px; height: 34px; font-size: 0.9rem; }
.account-chip .who { min-width: 0; }
.account-chip .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-chip .who small { color: var(--muted); }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- modal */
.modal-layer { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal)); background: rgba(5, 4, 3, 0.62); animation: fade 0.2s ease both; }
.modal { width: min(460px, 100%); max-height: calc(100dvh - 32px - var(--sat) - var(--sab)); overflow: auto; border-radius: 22px; padding: 24px 22px 20px; background: var(--glass-strong); animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.25, 1.15) both; position: relative; }
.modal.wide { width: min(560px, 100%); }
.modal h2 { font-family: var(--serif); font-weight: 600; margin: 0 0 6px; font-size: 1.6rem; padding-right: 40px; }
.modal .lead { color: var(--muted); margin: 0 0 18px; line-height: 1.45; }
.modal .close { position: absolute; top: 12px; right: 12px; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions .btn { flex: 1; }
.modal .section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 1.2px; color: var(--dim); font-weight: 700; margin: 18px 0 8px; }
.modal .section-title:first-of-type { margin-top: 4px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }

.tabs { display: flex; gap: 6px; margin: 4px 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { appearance: none; background: none; border: 0; color: var(--muted); padding: 10px 12px; cursor: pointer; font-weight: 700; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }

.otp { display: flex; gap: 8px; justify-content: center; margin: 8px 0 16px; }
.otp input { width: 48px; height: 58px; text-align: center; font-size: 1.6rem; font-weight: 700; border-radius: 12px; border: 1px solid var(--line-strong); background: rgba(0, 0, 0, 0.35); color: var(--text); padding: 0; }
.otp input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(95, 225, 201, 0.18); }

.code-box { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 2.2rem; letter-spacing: 8px; text-align: center; padding: 16px; border-radius: 14px; background: rgba(0, 0, 0, 0.35); border: 1px dashed rgba(240, 198, 107, 0.5); color: var(--gold); margin: 6px 0 14px; user-select: all; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.12); border-top-color: var(--gold); animation: spin 0.9s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.pulse-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 0 rgba(95, 225, 201, 0.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(95, 225, 201, 0.6); } 70% { box-shadow: 0 0 0 10px rgba(95, 225, 201, 0); } 100% { box-shadow: 0 0 0 0 rgba(95, 225, 201, 0); } }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.list-item .grow { min-width: 0; }
.list-item b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item small { color: var(--muted); }
.badge { font-size: 0.72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: rgba(240, 198, 107, 0.15); color: var(--gold); white-space: nowrap; }
.badge.green { background: rgba(126, 224, 138, 0.15); color: var(--green); }
.badge.red { background: rgba(255, 107, 91, 0.15); color: var(--red); }

.promo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.promo-grid button { appearance: none; border: 1px solid var(--line-strong); background: rgba(255, 255, 255, 0.05); border-radius: 14px; padding: 8px; cursor: pointer; aspect-ratio: 1; display: grid; place-items: center; transition: transform 0.12s, background 0.15s, border-color 0.15s; }
.promo-grid button:hover { background: rgba(240, 198, 107, 0.14); border-color: var(--gold); transform: translateY(-2px); }
.promo-grid img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }

.result-icon { display: block; width: 72px; height: 72px; margin: 4px auto 10px; color: var(--gold); fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 4px 18px rgba(240, 198, 107, 0.35)); }
.result-title { text-align: center; font-family: var(--serif); font-size: 2rem; margin: 0; }
.result-sub { text-align: center; color: var(--muted); margin: 6px 0 4px; }
.rating-change { text-align: center; font-weight: 700; margin-top: 6px; }
.rating-change.up { color: var(--green); }
.rating-change.down { color: var(--red); }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud > * { pointer-events: auto; }
.player-card { position: absolute; left: calc(16px + var(--sal)); display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px; border-radius: 16px; min-width: 240px; max-width: min(360px, calc(100vw - 32px)); transition: box-shadow 0.3s, border-color 0.3s, transform 0.3s; }
.player-card.top { top: calc(16px + var(--sat)); }
.player-card.bottom { bottom: calc(16px + var(--sab)); }
.player-card.turn { border-color: rgba(95, 225, 201, 0.55); box-shadow: var(--shadow), 0 0 0 1px rgba(95, 225, 201, 0.25), 0 0 28px rgba(95, 225, 201, 0.18); }
.avatar { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; flex: none; background: linear-gradient(135deg, #3a2f26, #1b1612); border: 1px solid var(--line-strong); color: var(--gold); position: relative; overflow: hidden; }
.avatar img { width: 120%; height: 120%; object-fit: contain; margin-top: 8%; }
.avatar.w { background: linear-gradient(135deg, #f3e9d6, #c9b48f); color: #3a2a17; }
.avatar.b { background: linear-gradient(135deg, #2e2722, #120f0d); }
.avatar .online { position: absolute; right: 3px; bottom: 3px; width: 10px; height: 10px; border-radius: 50%; background: #666; border: 2px solid #111; }
.avatar .online.on { background: var(--green); }
.pc-info { min-width: 0; flex: 1; }
.pc-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: baseline; gap: 6px; }
.pc-rating { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.pc-sub { display: flex; align-items: center; gap: 6px; min-height: 22px; margin-top: 2px; }
.pc-captured { display: flex; align-items: center; flex-wrap: nowrap; overflow: hidden; }
.pc-captured img { width: 20px; height: 20px; margin-right: -6px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5)); }
.pc-adv { color: var(--muted); font-size: 0.82rem; font-weight: 700; margin-left: 8px; }
.pc-status { font-size: 0.8rem; color: var(--teal); white-space: nowrap; }
.thinking i { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--teal); margin: 0 1px; animation: dots 1.2s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dots { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.clock { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 1.35rem; font-weight: 700; padding: 6px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; }
.clock.running { background: rgba(95, 225, 201, 0.12); border-color: rgba(95, 225, 201, 0.4); color: #dffbf5; }
.clock.low { color: #ffd2cc; background: rgba(255, 107, 91, 0.18); border-color: rgba(255, 107, 91, 0.5); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.65; } }

.toolbar { position: absolute; bottom: calc(16px + var(--sab)); left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 6px; border-radius: 18px; }
.toolbar .icon-btn { width: 48px; height: 48px; position: relative; }
.toolbar .icon-btn[disabled] { opacity: 0.3; pointer-events: none; }
.toolbar .icon-btn[data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.85); padding: 5px 9px; border-radius: 8px; font-size: 0.78rem; white-space: nowrap; pointer-events: none; }
.toolbar .divider { width: 1px; background: var(--line); margin: 8px 2px; }

.moves-panel { position: absolute; right: calc(16px + var(--sar)); top: calc(16px + var(--sat)); bottom: calc(16px + var(--sab)); width: 260px; border-radius: 18px; display: flex; flex-direction: column; overflow: hidden; transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s; }
.moves-panel.closed { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }
.moves-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.moves-head h3 { margin: 0; font-size: 0.95rem; letter-spacing: 0.4px; }
.moves-opening { padding: 8px 16px; font-size: 0.8rem; color: var(--gold); border-bottom: 1px solid var(--line); min-height: 34px; }
.moves-list { flex: 1; overflow: auto; padding: 8px 8px 12px; font-variant-numeric: tabular-nums; user-select: text; }
.mrow { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; align-items: center; border-radius: 8px; }
.mrow:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.mrow .n { color: var(--dim); font-size: 0.82rem; text-align: right; padding-right: 4px; }
.mrow .m { padding: 6px 8px; border-radius: 7px; font-weight: 600; font-size: 0.92rem; display: flex; align-items: center; gap: 4px; }
.mrow .m img { width: 16px; height: 16px; }
.mrow .m.last { background: rgba(95, 225, 201, 0.16); color: #dffbf5; }
.moves-foot { padding: 10px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.moves-foot .btn { flex: 1; padding: 8px 10px; min-height: 38px; font-size: 0.85rem; }

.status-banner { position: absolute; top: calc(18px + var(--sat)); left: 50%; transform: translate(-50%, -10px); padding: 9px 18px; border-radius: 999px; font-weight: 700; letter-spacing: 0.3px; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; white-space: nowrap; }
.status-banner.show { opacity: 1; transform: translate(-50%, 0); }
.status-banner.check { color: #ffd2cc; border-color: rgba(255, 107, 91, 0.6); box-shadow: var(--shadow), 0 0 30px rgba(255, 107, 91, 0.3); }

#toasts { position: fixed; left: 50%; bottom: calc(96px + var(--sab)); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { padding: 11px 16px; border-radius: 12px; font-size: 0.92rem; animation: toast-in 0.25s ease both; text-align: center; }
.toast.error { border-color: rgba(255, 107, 91, 0.5); color: #ffd2cc; }
.toast.ok { border-color: rgba(126, 224, 138, 0.5); color: #c8f5cf; }
.toast.out { animation: toast-out 0.3s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- friends & social */
.badge-dot { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 0.72rem; font-weight: 800; display: inline-grid; place-items: center; margin-left: 8px; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); }
.btn.big .badge-dot { margin-left: 2px; }
.tabs .badge-dot { min-width: 18px; height: 18px; font-size: 0.68rem; margin-left: 6px; vertical-align: 1px; }
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { white-space: nowrap; display: inline-flex; align-items: center; }
.pid-card { display: flex; align-items: center; gap: 6px; padding: 12px 10px 12px 14px; border-radius: 14px; background: linear-gradient(135deg, rgba(240, 198, 107, 0.12), rgba(240, 198, 107, 0.03)); border: 1px solid rgba(240, 198, 107, 0.28); }
.pid-card small { color: var(--muted); font-size: 0.75rem; display: block; }
.pid { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 1.45rem; font-weight: 800; letter-spacing: 2px; color: var(--gold); user-select: all; -webkit-user-select: all; }
.add-friend { display: flex; gap: 8px; margin: 12px 0 8px; }
.add-friend input { flex: 1; min-width: 0; appearance: none; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line-strong); color: var(--text); border-radius: 11px; padding: 0 14px; min-height: 46px; font-size: 1rem; letter-spacing: 0.5px; }
.add-friend input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(95, 225, 201, 0.18); }
.form-msg { margin: 4px 0 8px; }
.list-item.friend { padding: 10px 10px 10px 12px; }
.list-item .pc-rating { margin-left: 4px; font-size: 0.8rem; }
.avatar .presence { position: absolute; right: 2px; bottom: 2px; width: 11px; height: 11px; border-radius: 50%; background: #5d5650; border: 2px solid #15110e; }
.avatar .presence.online { background: var(--green); }
.avatar .presence.playing { background: var(--gold); }
.list-item.friend.offline .avatar { opacity: 0.7; }
.avatar.xl { width: 72px; height: 72px; font-size: 1.8rem; border-radius: 20px; margin: 4px auto 0; }
.avatar.xl .presence { width: 16px; height: 16px; }
.row.tight { gap: 6px; flex: none; }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: 0.86rem; border-radius: 10px; gap: 6px; }
.btn.sm .ico { width: 17px; height: 17px; }
.icon-btn.sm { width: 36px; height: 36px; border-radius: 10px; }
.icon-btn.sm .ico { width: 18px; height: 18px; }
.empty { padding: 6px 2px; line-height: 1.5; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 28%; }
.challenge-head { width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 20px; display: grid; place-items: center; color: var(--gold); background: rgba(240, 198, 107, 0.12); border: 1px solid rgba(240, 198, 107, 0.35); animation: pop 0.4s ease both; }
.challenge-head .ico { width: 34px; height: 34px; }
.modal h2.center { padding-right: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; }
.stats b { display: block; font-size: 1.55rem; font-weight: 800; }
.stats b.win { color: var(--green); }
.stats b.loss { color: var(--red); }
.stats small { color: var(--muted); }
.row.wrap { flex-wrap: wrap; justify-content: center; }
.chat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chat-grid .btn { justify-content: center; min-height: 48px; }
.chat-bubble { position: absolute; left: 62px; max-width: min(260px, 70vw); padding: 8px 12px; border-radius: 14px; background: #fff7e8; color: #2a1d10; font-weight: 700; font-size: 0.92rem; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); animation: pop 0.25s ease both; transition: opacity 0.4s, transform 0.4s; z-index: 2; pointer-events: none; }
.player-card.top .chat-bubble { top: calc(100% + 8px); border-top-left-radius: 4px; }
.player-card.bottom .chat-bubble { bottom: calc(100% + 8px); border-bottom-left-radius: 4px; }
.chat-bubble.out { opacity: 0; transform: translateY(-4px); }
.tb-more { display: none !important; }
.modal.sheet h2 { font-size: 1.3rem; }
.sheet-list { display: flex; flex-direction: column; gap: 8px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 899px) {
  .moves-panel { left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); top: auto; bottom: calc(84px + var(--sab)); width: auto; max-height: 46vh; }
  .moves-panel.closed { transform: translateY(calc(100% + 120px)); }
}

@media (max-width: 899px) and (orientation: portrait), (max-width: 560px) {
  .player-card { left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); min-width: 0; max-width: none; padding: 8px 10px 8px 8px; border-radius: 14px; }
  .player-card.top { top: calc(10px + var(--sat)); }
  .player-card.bottom { bottom: calc(74px + var(--sab)); }
  .avatar { width: 38px; height: 38px; }
  .clock { font-size: 1.15rem; min-width: 72px; padding: 5px 8px; }
  .toolbar { left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); transform: none; bottom: calc(10px + var(--sab)); justify-content: space-around; padding: 4px; border-radius: 16px; }
  .toolbar .icon-btn { width: 46px; height: 46px; }
  .toolbar .divider { display: none; }
  .status-banner { top: calc(76px + var(--sat)); }
  #menu.active { align-items: flex-end; justify-content: center; padding: calc(16px + var(--sat)) calc(12px + var(--sar)) calc(16px + var(--sab)) calc(12px + var(--sal)); }
  .menu-card { padding: 22px 18px 16px; border-radius: 22px; }
  .tagline { margin: 8px 0 16px; font-size: 0.92rem; }
  .moves-panel { bottom: calc(132px + var(--sab)); }
  #toasts { bottom: calc(140px + var(--sab)); }
  .menu-buttons { gap: 8px; }
  .btn.big { padding: 13px 16px; font-size: 1rem; }
  .pc-name { font-size: 0.95rem; }
  .pc-sub { min-height: 18px; }
  .pc-captured img { width: 17px; height: 17px; }
}

/* Phones: big touch targets, overflow actions in a bottom sheet, sheets slide up from the bottom */
@media (max-width: 600px) {
  .toolbar .tb-extra { display: none !important; }
  .toolbar .tb-more { display: inline-grid !important; }
  .modal-layer:has(.modal.sheet) { align-items: end; padding-bottom: calc(10px + var(--sab)); }
  .modal { padding: 20px 16px 16px; border-radius: 20px; }
  .modal h2 { font-size: 1.4rem; }
  .seg button { padding: 10px 4px; font-size: 0.9rem; }
  .pid { font-size: 1.25rem; letter-spacing: 1.5px; }
  .list-item { gap: 10px; }
  .list-item small { font-size: 0.78rem; }
  .stats b { font-size: 1.3rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .player-card { min-width: 200px; padding: 6px 10px 6px 6px; }
  .player-card.top { top: calc(8px + var(--sat)); }
  .player-card.bottom { bottom: calc(8px + var(--sab)); }
  .avatar { width: 34px; height: 34px; }
  .toolbar { left: auto; right: calc(8px + var(--sar)); top: 50%; bottom: auto; transform: translateY(-50%); flex-direction: column; }
  .toolbar .icon-btn { width: 44px; height: 44px; }
  .toolbar .divider { display: none; }
  /* A phone on its side has no room for a full column of buttons: extras go to the "more" sheet */
  .toolbar .tb-extra { display: none !important; }
  .toolbar .tb-more { display: inline-grid !important; }
  .modal-layer:has(.modal.sheet) { align-items: center; }
  .moves-panel { right: calc(74px + var(--sar)); left: auto; width: 240px; top: calc(8px + var(--sat)); bottom: calc(8px + var(--sab)); max-height: none; }
  .moves-panel.closed { transform: translateX(calc(100% + 100px)); }
  #menu.active { align-items: center; }
  .menu-card { max-height: calc(100dvh - 24px); overflow: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
