@font-face {
    font-family: 'Stack Sans Notch';
    src: url('/fonts/StackSansNotch.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --font-brand: 'Stack Sans Notch', 'Nunito', sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --accent: #1E9E5E;
    --accent-light: #6FDDA0;
    --accent-dark: #17804B;
    --bg: #0C110E;
    --bg-card: #17201B;
    --bg-card-hover: #1F2B24;
    --bg-surface: #121915;
    --avatar-bg: #2E2E50;
    --text: #E8F0EA;
    --text-muted: #9BB0A3;
    --text-dim: #5A6D61;
    --green: #00B894;
    --red: #FF6B6B;
    --yellow: #FFEAA7;
    --border: rgba(255, 255, 255, 0.07);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body { height: 100%; }

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; touch-action: manipulation; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* Screens */
.screen { display: none; width: 100%; min-height: 100dvh; }
.screen.active { display: flex; animation: fadeIn 0.35s var(--ease); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 13px 22px; border: none; border-radius: var(--radius-sm);
    font-size: 15px; font-weight: 800; cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, transform 0.12s, opacity 0.2s, filter 0.2s;
    position: relative;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); box-shadow: 0 6px 22px rgba(30, 158, 94, 0.4); }
.btn-secondary { background: var(--bg-card-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #27352D; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-accent { background: var(--yellow); color: #1a1a1a; }
.btn-accent:hover { filter: brightness(0.95); }
.btn-sm { padding: 9px 14px; font-size: 13px; }
.btn-yes { background: var(--green); color: #fff; min-width: 110px; }
.btn-no { background: var(--red); color: #fff; min-width: 110px; }
.btn-yes:hover, .btn-no:hover { filter: brightness(1.08); }
.btn.loading { color: transparent !important; }
.btn.loading::after {
    content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
    animation: spin 0.7s linear infinite;
}
.btn-secondary.loading::after { border-color: rgba(255, 255, 255, 0.2); border-top-color: var(--text); }
.btn-icon {
    width: 40px; height: 40px; border: none; background: var(--bg-card);
    color: var(--text-muted); border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.btn-icon:hover { background: var(--bg-card-hover); color: var(--text); }
.link-btn {
    background: none; border: none; color: var(--accent-light); font-size: 13px; font-weight: 700;
    cursor: pointer; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px;
}

/* Inputs */
input[type="text"] {
    width: 100%; padding: 14px 16px; background: var(--bg-surface); border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-family: inherit; font-size: 16px;
    outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]::placeholder { color: var(--text-dim); }
input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(30, 158, 94, 0.18); }
.code-input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-size: 22px !important; font-weight: 800; }
.code-input::placeholder { letter-spacing: 6px; }

/* Lobby */
#screen-lobby { flex-direction: column; align-items: center; padding: calc(72px + var(--safe-top)) 16px 0; position: relative; }
.lobby-container { width: 100%; max-width: 640px; margin: auto 0; }
.lang-selector { position: absolute; top: calc(16px + var(--safe-top)); right: 16px; display: flex; gap: 6px; }

.site-footer {
    width: 100%; max-width: 640px; margin-top: 40px; padding: 18px 0 calc(22px + var(--safe-bottom));
    border-top: 1px solid var(--border); font-size: 13.5px;
    display: flex; align-items: center; justify-content: center; gap: 10px 16px; flex-wrap: wrap;
}
.version-btn {
    display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px;
    border: 1px solid var(--border); background: transparent; color: var(--text-muted);
    font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.version-btn:hover { color: var(--text); border-color: var(--accent-light); background: rgba(30, 158, 94, 0.12); }

/* How to play */
.hero-links { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 4px 20px; margin-top: 10px; }
.howto-link { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-size: 14px; }
.howto-inline { display: none; }
.howto h2 { font-size: 15px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 14px; }
.howto-list { list-style: none; display: flex; flex-direction: column; gap: 14px; text-align: left; }
.howto-list li { display: flex; gap: 14px; align-items: flex-start; }
.howto-num {
    flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
    background: rgba(30, 158, 94, 0.18); color: var(--accent-light); font-weight: 800; font-size: 15px;
}
.howto-list strong { display: block; font-size: 15.5px; margin-bottom: 2px; }
.howto-list p { color: var(--text-muted); font-size: 14px; line-height: 1.45; }
.modal-content.howto h3 { margin-bottom: 18px; }
.modal-content.howto .howto-list { margin-bottom: 22px; }

.rules-more { display: inline-flex; align-items: center; gap: 6px; margin-top: 16px; text-decoration: none; font-size: 14px; }
.rules-sheet-btn { width: 100%; margin-top: 4px; }

/* Game rules */
.modal-content.rules-content { position: relative; max-width: 680px; text-align: left; padding: 28px 28px 30px; }
.rules-content h3 { text-align: center; font-size: 21px; margin-bottom: 18px; }
.rules-body { display: flex; flex-direction: column; gap: 22px; }
.rules-body h4 { font-size: 13px; font-weight: 800; color: var(--accent-light); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px; }
.rules-body p, .rule-list li, .rule-cases li { color: var(--text-muted); font-size: 14.5px; line-height: 1.55; }
.rules-body p + p, .rule-list + p { margin-top: 8px; }
.rule-list { padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }

/* Piece style */
.modal-content.style-content { position: relative; max-width: 460px; }
.style-content h3 { margin-bottom: 16px; }
.style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.style-option {
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 10px 9px; border-radius: 14px; cursor: pointer;
    background: var(--bg); border: 2px solid var(--border); color: var(--text-muted); font: inherit; font-weight: 800; font-size: 14px;
    transition: border-color 0.15s, color 0.15s, transform 0.15s var(--ease);
}
.style-option:hover { border-color: var(--accent-dark); color: var(--text); }
.style-option.active { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 3px rgba(30, 158, 94, 0.22); }
.style-option:active { transform: scale(0.97); }
 /* Options (attributes on <html>); the rule diagrams use .mini-board, so they keep their markers */
[data-coords="off"] .board .coord { display: none; }
[data-last-move="off"] .board .sq.last::before { background: none; }
[data-dots="off"] .board:not(.tips-on) .sq .mark { display: none; }
[data-anim="off"] .sq .pc.capture-ghost, [data-anim="off"] .capture-burst { display: none; }

.option-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; text-align: left; }
.option-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 14px; min-height: 50px;
    font-size: 14.5px; font-weight: 700; color: var(--text); cursor: pointer; background: var(--bg);
}
.option-row + .option-row { border-top: 1px solid var(--border); }
.option-row small { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-top: 2px; }
.switch {
    -webkit-appearance: none; appearance: none; flex-shrink: 0; position: relative; width: 44px; height: 26px; margin: 0; border-radius: 13px;
    background: var(--bg-card-hover); border: 1px solid var(--border); cursor: pointer; transition: background 0.18s, border-color 0.18s;
}
.switch::before {
    content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
    background: var(--text-muted); transition: transform 0.18s var(--ease), background 0.18s;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::before { transform: translateX(18px); background: #fff; }
.switch:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.seg { display: inline-flex; flex-shrink: 0; padding: 3px; border-radius: 10px; background: var(--bg-card-hover); }
.seg button {
    border: none; background: transparent; color: var(--text-muted); font: inherit; font-size: 13px; font-weight: 800;
    padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.seg button.active { background: var(--accent); color: #fff; }

.style-section { margin: 20px 0 10px; font-size: 12px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; text-align: left; }
.style-content h3 + .style-section { margin-top: 0; }
.custom-layout { display: flex; flex-direction: column; }
.custom-preview { display: none; }
.board-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.board-preview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; max-width: 92px; border-radius: 8px; overflow: hidden; }
.board-preview .sq { aspect-ratio: 1; min-width: 0; }
.board-preview .pc { width: 86%; height: 86%; filter: var(--pc-shadow); stroke-width: var(--pc-stroke); }
.style-preview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; border-radius: 8px; overflow: hidden; }
.style-preview .sq { aspect-ratio: 1; min-width: 0; }
.style-preview .pc { width: 88%; height: 88%; filter: var(--pc-shadow); stroke-width: var(--pc-stroke); }

/* Release notes */
.modal-content.release-content { position: relative; max-width: 460px; text-align: left; }
.release-content h3 { text-align: center; }
.release-list { display: flex; flex-direction: column; gap: 18px; margin-top: 6px; }
.release { border-left: 2px solid var(--border); padding-left: 14px; }
.release.current { border-left-color: var(--accent); }
.release-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.release-head strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.release-tag { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 20px; background: rgba(30, 158, 94, 0.2); color: var(--accent-light); text-transform: uppercase; letter-spacing: 0.04em; }
.release ul { padding-left: 18px; color: var(--text-muted); font-size: 14px; line-height: 1.5; display: flex; flex-direction: column; gap: 3px; }

/* Desktop start page: presentation on the left, choices on the right */
@media (min-width: 980px) {
    .lobby-container { max-width: 1120px; display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); gap: 56px; align-items: center; }
    .hero { text-align: left; }
    .hero .logo-area { text-align: left; margin-bottom: 28px; }
    .hero .logo-faces { justify-content: flex-start; }
    .hero .logo-title { font-size: 52px; justify-content: flex-start; }
    .hero .logo-subtitle { font-size: 17px; }
    .hero-links { display: none; }
    .howto-inline { display: block; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
    .site-footer { max-width: 1120px; justify-content: space-between; }
    .credit-block { align-items: flex-start; }
}
.credit-block { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.credit-ai { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); opacity: 0.8; }
.credit-ai svg { color: var(--accent-light); }
.credit { color: var(--text-muted); text-decoration: none; display: inline-flex; align-items: baseline; gap: 7px; flex-wrap: wrap; justify-content: center; }
.credit-name { font-family: var(--font-brand); font-size: 1.08rem; color: var(--text); letter-spacing: 0.01em; transition: color 0.15s; }
.credit:hover .credit-name, .credit:focus-visible .credit-name { color: var(--accent-light); }
.lang-btn {
    width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
    background: transparent; color: var(--text-muted); font-size: 11px; font-weight: 800;
    cursor: pointer; transition: all 0.2s;
}
.lang-btn:hover { color: var(--text); border-color: var(--accent-light); }
@media (pointer: coarse) { .lang-btn { width: 40px; height: 40px; font-size: 12px; } }

/* Phones: a single language button that opens a sheet with full language names */
.lang-toggle {
    display: none; position: absolute; top: calc(14px + var(--safe-top)); right: 14px;
    align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
    border-radius: 20px; border: 1px solid var(--border); background: var(--bg-card);
    color: var(--text); font-size: 13px; font-weight: 800; cursor: pointer;
}
.lang-toggle:hover { border-color: var(--accent-light); }
.lang-toggle svg:first-child { color: var(--accent-light); }
.lang-options { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.lang-option {
    display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 0 16px;
    border-radius: 14px; border: 1.5px solid var(--border); background: var(--bg-surface);
    color: var(--text); font-size: 16px; font-weight: 700; text-align: left; cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.lang-option:hover { border-color: rgba(111, 221, 160, 0.45); }
.lang-code {
    width: 34px; height: 26px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg-card-hover); color: var(--text-muted); font-size: 11.5px; font-weight: 800; letter-spacing: 0.04em;
}
.lang-check { margin-left: auto; color: var(--accent-light); opacity: 0; }
.lang-option.active { border-color: var(--accent); background: rgba(30, 158, 94, 0.14); }
.lang-option.active .lang-code { background: var(--accent); color: #fff; }
.lang-option.active .lang-check { opacity: 1; }

.brand-mark { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 26px; font-size: 17px; font-weight: 800; color: var(--text); }
.brand-mark img { border-radius: 8px; }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.logo-area { text-align: center; margin-bottom: 24px; }
.logo-faces { display: flex; justify-content: center; margin-bottom: 14px; }
.logo-face {
    width: 64px; height: 64px; border-radius: 18px; overflow: hidden;
    border: 3px solid var(--bg); box-shadow: var(--shadow);
    animation: bob 3.2s ease-in-out infinite;
}
.logo-face svg { width: 100%; height: 100%; }
.logo-face.f1 { transform: rotate(-8deg); margin-right: -10px; animation-delay: 0s; }
.logo-face.f2 { position: relative; z-index: 1; width: 74px; height: 74px; animation-delay: 0.4s; }
.logo-face.f3 { transform: rotate(8deg); margin-left: -10px; animation-delay: 0.8s; }
.logo-title { display: flex; justify-content: center; align-items: center; gap: 12px; font-size: 40px; font-weight: 800; letter-spacing: -0.5px; }
.logo-title span {
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.logo-mark { width: 1.1em; height: 1.1em; border-radius: 0.26em; flex-shrink: 0; box-shadow: 0 6px 18px rgba(30, 158, 94, 0.35); }
.logo-subtitle { color: var(--text-muted); font-size: 15px; margin-top: 2px; }

.steps-indicator { list-style: none; display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; }
.step-btn {
    display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 20px;
    background: none; border: none; color: var(--text-dim); font-size: 13px; font-weight: 800;
}
.step-num {
    width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    border: 2px solid var(--text-dim); font-size: 12.5px; transition: all 0.3s var(--ease);
}
.step-check { display: none; }
.step.active .step-btn { color: var(--text); }
.step.active .step-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.done .step-btn { color: var(--text-muted); cursor: pointer; }
.step.done .step-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.step.done .step-num { background: var(--green); border-color: var(--green); color: #fff; }
.step.done .step-n { display: none; }
.step.done .step-check { display: block; }
.step-line { width: 32px; height: 2px; background: var(--border); border-radius: 2px; }
.step.done + .step-line { background: var(--green); }


.lobby-step { display: none; }
.lobby-step.active { display: block; animation: stepIn 0.4s var(--ease); }
#step-name { max-width: 380px; margin: 0 auto; display: none; flex-direction: column; gap: 12px; }
#step-name.active { display: flex; }
.step-title { display: block; font-size: 22px; font-weight: 800; text-align: center; }
.step-hint { color: var(--text-muted); font-size: 14px; text-align: center; margin-bottom: 6px; }
.greeting { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.greeting .link-btn { font-size: 13px; padding: 2px 4px; }
#step-mode .step-hint { margin: 4px 0 18px; }

.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode-card {
    background: var(--bg-card); border: 1.5px solid var(--border); border-radius: var(--radius);
    padding: 20px; display: flex; flex-direction: column; gap: 14px;
    transition: border-color 0.25s, transform 0.25s var(--ease), box-shadow 0.25s;
}
.mode-card:hover, .mode-card:focus-within { border-color: rgba(111, 221, 160, 0.45); transform: translateY(-2px); box-shadow: var(--shadow); }
.mode-card.highlight { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(30, 158, 94, 0.15); }
.mode-icon {
    width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    background: rgba(30, 158, 94, 0.18); color: var(--accent-light);
}
.mode-icon.alt { background: rgba(255, 234, 167, 0.14); color: var(--yellow); }
.mode-body h3 { font-size: 17px; font-weight: 800; margin-bottom: 4px; }
.mode-body p { color: var(--text-muted); font-size: 13.5px; line-height: 1.45; }
.mode-card .btn { margin-top: auto; }
.mode-card-wide { grid-column: 1 / -1; flex-direction: row; align-items: center; }
.mode-card-wide .mode-body { flex: 1; }
.mode-card-wide .btn { margin-top: 0; flex-shrink: 0; }
.mode-icon.random { background: rgba(116, 185, 255, 0.16); color: var(--blue); flex-shrink: 0; }

.play-mode { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.play-mode-option { cursor: pointer; position: relative; }
.play-mode-option input { position: absolute; opacity: 0; pointer-events: none; }
.play-mode-box {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px; height: 100%;
    padding: 10px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
    background: var(--bg-surface); color: var(--text-muted); transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.play-mode-box svg { margin-bottom: 2px; }
.play-mode-box strong { font-size: 14px; color: var(--text); }
.play-mode-box small { font-size: 12px; line-height: 1.3; }
.play-mode-option input:checked + .play-mode-box { border-color: var(--accent); background: rgba(30, 158, 94, 0.14); color: var(--accent-light); }
.play-mode-option input:focus-visible + .play-mode-box { box-shadow: 0 0 0 3px rgba(30, 158, 94, 0.35); }

/* Waiting */
#screen-waiting { justify-content: center; align-items: center; text-align: center; padding: 24px 16px; }
.waiting-container { max-width: 420px; }
.waiting-container h2 { font-size: 22px; margin-bottom: 6px; }
.waiting-animation { position: relative; width: 120px; height: 120px; margin: 0 auto 24px; display: flex; align-items: center; justify-content: center; }
.pulse-ring {
    position: absolute; inset: 0; border-radius: 50%;
    border: 2px solid var(--accent); opacity: 0;
    animation: pulse-ring 2.4s ease-out infinite;
}
.delay-1 { animation-delay: 0.8s; }
.delay-2 { animation-delay: 1.6s; }
.waiting-dots { display: flex; gap: 6px; }
.waiting-dots span { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-light); animation: dot 1.2s ease-in-out infinite; }
.waiting-dots span:nth-child(2) { animation-delay: 0.15s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.3s; }
.room-code-display {
    display: inline-flex; align-items: center; gap: 14px;
    padding: 16px 26px; background: var(--bg-card); border-radius: var(--radius);
    cursor: pointer; transition: all 0.2s; margin: 16px 0 18px;
    border: 1.5px dashed rgba(111, 221, 160, 0.45); color: var(--text-muted);
}
.room-code-display:hover { background: var(--bg-card-hover); color: var(--text); }
.room-code-display span { font-size: 30px; font-weight: 800; letter-spacing: 7px; color: var(--accent-light); }
.waiting-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#waiting-public-desc { max-width: 340px; margin: 4px auto 24px; line-height: 1.5; }
.mode-note { color: var(--yellow); font-size: 13px; font-weight: 700; margin: -8px 0 16px; }
.mode-note:empty { display: none; }
.mode-badge {
    padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 800; white-space: nowrap;
    background: rgba(255, 234, 167, 0.14); color: var(--yellow);
}

/* Game header */
#screen-game { flex-direction: column; height: 100dvh; }
.game-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-head, .side-log-title, .side-log-empty { display: none; }
.game-header {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: calc(10px + var(--safe-top)) 16px 10px; background: var(--bg-surface); border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.game-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.game-title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 800; flex-shrink: 0; }
.game-title img { display: block; border-radius: 7px; }
.game-title span {
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.turn-indicator {
    padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 800;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw;
    transition: background 0.3s, color 0.3s;
}
.turn-indicator.my-turn { background: rgba(30, 158, 94, 0.22); color: var(--accent-light); animation: glow-pulse 2s ease-in-out infinite; }
.turn-indicator.their-turn { background: rgba(154, 154, 180, 0.12); color: var(--text-muted); }
.game-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.players-status { display: flex; gap: 5px; }
.player-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); transition: background 0.3s; }
.player-dot.online { background: var(--green); box-shadow: 0 0 6px rgba(0, 184, 148, 0.6); }
.my-card-btn {
    display: flex; align-items: center; gap: 8px; padding: 3px 12px 3px 3px;
    background: var(--bg-card); border: 1.5px solid var(--accent); border-radius: 24px;
    color: var(--text); font-size: 13px; font-weight: 800; cursor: pointer; transition: background 0.2s;
}
.my-card-btn:hover { background: var(--bg-card-hover); }
.my-card-thumb { width: 32px; height: 32px; border-radius: 50%; overflow: hidden; background: var(--avatar-bg); }
.my-card-thumb svg { width: 100%; height: 100%; }

/* Modals */
.modal {
    position: fixed; inset: 0; z-index: 200; padding: 16px;
    background: rgba(4, 8, 6, 0.78); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: flex; justify-content: center; align-items: center;
    animation: fadeIn 0.2s ease;
}
.modal-content {
    background: var(--bg-card); border-radius: 20px; border: 1px solid var(--border);
    padding: 28px 24px; text-align: center; max-width: 380px; width: 100%;
    max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain;
    box-shadow: var(--shadow); animation: popIn 0.35s var(--ease);
}
.modal-content h3 { font-size: 19px; margin-bottom: 14px; }
.modal-content .muted { font-size: 14px; line-height: 1.5; margin: 12px 0 18px; }
.modal-avatar { width: 170px; height: 170px; margin: 0 auto; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); animation: flipIn 0.6s var(--ease); }
.modal-avatar.small { width: 120px; height: 120px; }
.modal-avatar svg { width: 100%; height: 100%; }
.modal-name { font-size: 20px; font-weight: 800; margin-top: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.warning-text { color: var(--yellow); font-weight: 700; font-size: 14px; margin: 14px 0 18px; }
.gameover-content #gameover-icon svg { margin: 0 auto; animation: popIn 0.5s var(--ease); }
.gameover-content h2 { font-size: 26px; margin: 12px 0 4px; }
.reveal-row { display: flex; justify-content: center; gap: 16px; margin-bottom: 14px; }
.score-line { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 14px; color: var(--text-muted); font-weight: 700; margin-bottom: 10px; }
.score-line span { max-width: 35%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-line strong { font-size: 22px; color: var(--text); background: var(--bg-surface); padding: 4px 14px; border-radius: 10px; }
.rematch-status { min-height: 20px; font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.rematch-status.invite { color: var(--yellow); animation: popIn 0.35s var(--ease); }
.rematch-status.warn { color: var(--red); }
.gameover-actions { display: flex; flex-direction: column; gap: 6px; }
.reveal-row figcaption { margin-top: 8px; font-size: 13px; color: var(--text-muted); font-weight: 700; }

/* Zoom */
.zoom-content { position: relative; max-width: 440px; padding-top: 36px; }
.zoom-close {
    position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
    border: none; background: var(--bg-card-hover); color: var(--text-muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: color 0.2s, background 0.2s;
}
.zoom-close:hover { color: var(--text); background: #27352D; }

@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

/* Toast */
.toast {
    position: fixed; top: calc(16px + var(--safe-top)); left: 50%; transform: translate(-50%, -120%);
    background: var(--bg-card-hover); color: var(--text); padding: 12px 20px; max-width: calc(100% - 32px);
    border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; text-align: center;
    box-shadow: var(--shadow); border: 1px solid var(--border);
    transition: transform 0.35s var(--ease), opacity 0.35s; opacity: 0; z-index: 1000; pointer-events: none;
}
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes stepIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.88); } to { opacity: 1; transform: scale(1); } }
@keyframes flipIn { from { transform: perspective(600px) rotateY(90deg); } to { transform: perspective(600px) rotateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.6); } 100% { box-shadow: 0 0 0 8px rgba(0, 184, 148, 0); } }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }
@keyframes dot { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
@keyframes pulse-ring { 0% { transform: scale(0.45); opacity: 0.8; } 100% { transform: scale(1.3); opacity: 0; } }
@keyframes glow-pulse { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 14px rgba(30, 158, 94, 0.4); } }
@keyframes wiggle { 0%, 90%, 100% { rotate: 0deg; } 93% { rotate: -1.5deg; } 97% { rotate: 1.5deg; } }
@keyframes cardAppear {
    from { opacity: 0; transform: perspective(600px) rotateY(-90deg) scale(0.9); }
    to { opacity: 1; transform: perspective(600px) rotateY(0) scale(1); }
}
.card-enter { animation: cardAppear 0.5s var(--ease) both; }
@keyframes confetti-fall { 0% { transform: translateY(-10px) rotate(0); opacity: 1; } 100% { transform: translateY(100vh) rotate(720deg); opacity: 0; } }
.confetti { position: fixed; top: 0; z-index: 300; pointer-events: none; animation: confetti-fall 3s ease-in forwards; }

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


/* ---------- Chess ---------- */
:root {
    --sq-light: #F2F2F0;
    --sq-dark: #58585D;
    --orange: #FDA65D;
    --blue: #74B9FF;
}
/* Board colours: the nearest [data-board] wins, so the picker previews can show every theme */
[data-board="green"] { --sq-light: #EEF2E4; --sq-dark: #74A065; }
[data-board="brown"] { --sq-light: #F0D9B5; --sq-dark: #B58863; }
[data-board="blue"] { --sq-light: #E3EAF0; --sq-dark: #7C9CB5; }
[data-board="grey"] { --sq-light: #E6E6E3; --sq-dark: #9A9C99; }
[data-board="purple"] { --sq-light: #ECE6F3; --sq-dark: #8E7AB5; }
[data-board="coral"] { --sq-light: #F6E3DA; --sq-dark: #CF8572; }
[data-board="classic"] { --sq-light: #F2F2F0; --sq-dark: #58585D; }
.logo-face { background: var(--sq-light); display: flex; align-items: center; justify-content: center; }
.logo-face.f2 { background: var(--sq-dark); }
.logo-face .pc { width: 82%; height: 82%; }

/* Option chips (time, level, colour) */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { cursor: pointer; position: relative; flex: 1 1 auto; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip > span {
    display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 12px;
    border-radius: var(--radius-sm); border: 1.5px solid var(--border); background: var(--bg-surface);
    color: var(--text-muted); font-size: 13.5px; font-weight: 800; white-space: nowrap;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.chip:hover > span { border-color: rgba(111, 221, 160, 0.45); color: var(--text); }
.chip input:checked + span { border-color: var(--accent); background: rgba(30, 158, 94, 0.16); color: var(--accent-light); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(30, 158, 94, 0.35); }
.chip-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--text-dim); flex-shrink: 0; }
.chip-dot.w { background: #FBFAFF; }
.chip-dot.b { background: #2B2A35; }
.chip-dot.r { background: linear-gradient(90deg, #FBFAFF 50%, #2B2A35 50%); }

/* Mode tabs on the start page */
.mode-tabs {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin-bottom: 16px;
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px;
}
.mode-tab {
    display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 8px;
    border: none; border-radius: 10px; background: transparent; color: var(--text-muted);
    font-size: 14px; font-weight: 800; cursor: pointer; transition: background 0.2s, color 0.2s;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.active { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(30, 158, 94, 0.35); }
.mode-panel { display: none; }
.mode-panel.active { display: block; animation: stepIn 0.35s var(--ease); }
.solo-card { max-width: 460px; margin: 0 auto; }
.solo-card input[type="text"] { padding: 12px 14px; }

/* Game layout */
#screen-game { flex-direction: column; height: 100dvh; }
.game-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.board-area { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px 12px; position: relative; }
.board-column { width: var(--board-size, 480px); display: flex; flex-direction: column; gap: 6px; }
.mode-badge { padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 800; white-space: nowrap; background: rgba(255, 234, 167, 0.14); color: var(--yellow); }
.mode-badge:empty { display: none; }
.turn-indicator.done { background: rgba(0, 184, 148, 0.16); color: var(--green); }

/* Player bars */
.player-bar { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.pb-avatar {
    width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    background: var(--bg-card); border: 1.5px solid var(--border);
}
.pb-avatar .pc { width: 86%; height: 86%; }
.pb-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.pb-name { display: flex; align-items: center; gap: 6px; font-size: 14.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-name .online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.pb-name .online-dot.on { background: var(--green); box-shadow: 0 0 6px rgba(0, 184, 148, 0.6); }
.pb-score { font-size: 11.5px; font-weight: 800; color: var(--text-muted); padding: 1px 7px; border-radius: 10px; background: var(--bg-card); }
.pb-captured { display: flex; align-items: center; min-height: 16px; }
/* Nothing captured yet: no empty row, so the name sits centred next to the avatar */
.pb-captured:empty { display: none; }
.pb-captured .pc { width: 17px; height: 17px; margin-right: -5px; }
.pb-captured .pc-w { --ps: #6b6888; }
.pb-adv { margin-left: 8px; font-size: 12px; font-weight: 800; color: var(--text-muted); }
.player-bar.to-move .pb-avatar { border-color: var(--accent-light); box-shadow: 0 0 0 3px rgba(30, 158, 94, 0.25); }
.clock {
    min-width: 76px; padding: 6px 10px; border-radius: 9px; text-align: right;
    font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
    background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); transition: background 0.2s, color 0.2s;
}
.clock.running { background: #FBFAFF; color: #16162A; }
.clock.low { color: var(--red); }
.clock.running.low { background: var(--red); color: #fff; animation: glow-pulse 1s ease-in-out infinite; }
.thinking { display: inline-flex; gap: 3px; margin-left: 4px; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-light); animation: dot 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }

/* Board */
.board-wrap { position: relative; width: var(--board-size, 480px); height: var(--board-size, 480px); border-radius: 10px; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45); }
.board {
    display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
    width: 100%; height: 100%; border-radius: 10px; overflow: hidden; touch-action: none;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq::before { content: ''; position: absolute; inset: 0; pointer-events: none; }
.sq.last::before { background: rgba(255, 228, 120, 0.45); }
.sq.sel::before { background: rgba(255, 214, 102, 0.75); }
.sq.check::before { background: radial-gradient(circle, rgba(255, 70, 70, 0.95) 0%, rgba(255, 70, 70, 0.55) 40%, transparent 72%); }
.sq.hover::before { box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.75); }
.sq.hint-from::before, .sq.hint-to::before { background: rgba(255, 196, 61, 0.45); }
.coord { position: absolute; font-size: calc(var(--board-size, 480px) / 46); font-weight: 800; pointer-events: none; line-height: 1; }
.coord.rank { top: 4%; left: 5%; }
.coord.file { bottom: 4%; right: 6%; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.sq .pc {
    position: relative; z-index: 1; width: 90%; height: 90%; cursor: default;
    stroke-width: var(--pc-stroke); stroke-linejoin: round; stroke-linecap: round; transition: transform 0.18s var(--ease);
    filter: var(--pc-shadow);
}
.sq.mine .pc { cursor: grab; }
.pc { fill: var(--pf); stroke: var(--ps); stroke-width: 3.2; stroke-linejoin: round; stroke-linecap: round; }
/* Piece styles: each sets a palette for both sides; the nearest [data-pieces] wins, so previews can differ from the board */
:root, [data-pieces="classic"] {
    --pc-stroke: 3.2;
    --w-f: url(#pg-w); --w-s: #2F2A1F; --w-d: #5E5541; --w-h: rgba(255, 255, 255, 0.95);
    --b-f: url(#pg-b); --b-s: #050507; --b-d: #B9B6C8; --b-h: rgba(255, 255, 255, 0.4);
    --pc-shadow: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)) drop-shadow(1.5px 1px 0 rgba(0, 0, 0, 0.12));
}
[data-pieces="wood"] {
    --pc-stroke: 3.2;
    --w-f: url(#wd-w); --w-s: #4E3214; --w-d: #85582A; --w-h: rgba(255, 248, 230, 0.9);
    --b-f: url(#wd-b); --b-s: #1A0E05; --b-d: #E4BC8C; --b-h: rgba(255, 220, 180, 0.35);
    --pc-shadow: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)) drop-shadow(1.5px 1px 0 rgba(0, 0, 0, 0.12));
}
[data-pieces="flat"] {
    --pc-stroke: 3.4;
    --w-f: #FFFFFF; --w-s: #17171A; --w-d: #17171A; --w-h: transparent;
    --b-f: #2B2B31; --b-s: #0B0B0D; --b-d: #F4F4F4; --b-h: transparent;
    --pc-shadow: drop-shadow(0 1.5px 0 rgba(0, 0, 0, 0.22));
}
[data-pieces="marble"] {
    --pc-stroke: 3.2;
    --w-f: url(#mb-w); --w-s: #3B372F; --w-d: #7E776A; --w-h: rgba(255, 255, 255, 0.95);
    --b-f: url(#mb-b); --b-s: #050506; --b-d: #D8B86E; --b-h: rgba(255, 255, 255, 0.35);
    --pc-shadow: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)) drop-shadow(1.5px 1px 0 rgba(0, 0, 0, 0.12));
}
[data-pieces="glass"] {
    --pc-stroke: 3;
    --w-f: url(#gl-w); --w-s: #47677D; --w-d: #5F8399; --w-h: #FFFFFF;
    --b-f: url(#gl-b); --b-s: #04070B; --b-d: #9FC0D8; --b-h: rgba(220, 240, 255, 0.75);
    --pc-shadow: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.28));
}
[data-pieces="pixel"] {
    --pc-stroke: 0;
    --w-f: #E2DED3; --w-s: #15151A; --w-d: #A79F8F; --w-h: #FFFFFF;
    --b-f: #3D3D4B; --b-s: #07070A; --b-d: #24242D; --b-h: #6A6A82;
    --pc-shadow: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.25));
}
.pc-w { --pf: var(--w-f); --ps: var(--w-s); --pd: var(--w-d); --ph: var(--w-h); }
.pc-b { --pf: var(--b-f); --ps: var(--b-s); --pd: var(--b-d); --ph: var(--b-h); }



.pc.dragging { position: fixed; z-index: 50; pointer-events: none; transition: none; filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.4)); }
.sq.drag-origin .pc { opacity: 0.3; }
.pc.anim { z-index: 3; }

/* Move markers: a dot for an empty square, a ring for a capture */
.sq .mark { position: absolute; inset: 0; z-index: 2; pointer-events: none; display: flex; align-items: center; justify-content: center; }
/* Dark centre for light squares, light rim for dark ones */
.sq .mark::after { content: ''; width: 30%; height: 30%; border-radius: 50%; background: rgba(10, 14, 12, 0.32); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.4); }
.sq.capture .mark::after { width: 92%; height: 92%; background: transparent; box-shadow: inset 0 0 0 calc(var(--board-size, 480px) / 96) rgba(10, 14, 12, 0.34), inset 0 0 0 calc(var(--board-size, 480px) / 96 + 1.5px) rgba(255, 255, 255, 0.35); }
/* Tips: colour-coded markers */
.tips-on .sq.safe .mark::after { background: rgba(0, 184, 148, 0.85); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); }
.tips-on .sq.unsafe .mark::after { background: rgba(253, 166, 93, 0.95); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); }
.tips-on .sq.capture .mark::after { background: transparent; box-shadow: inset 0 0 0 calc(var(--board-size, 480px) / 80) rgba(255, 90, 90, 0.9); }
.tips-on .sq.special .mark::after { background: rgba(116, 185, 255, 0.95); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); }
.tips-on .sq.capture.special .mark::after { background: transparent; box-shadow: inset 0 0 0 calc(var(--board-size, 480px) / 80) rgba(116, 185, 255, 0.95); }
.mark-check {
    position: absolute; top: 4%; right: 4%; z-index: 3; min-width: 32%; height: 32%; padding: 0 3px; border-radius: 20px;
    display: none; align-items: center; justify-content: center; background: var(--yellow); color: #1a1a1a;
    font-size: calc(var(--board-size, 480px) / 40); font-weight: 900; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.tips-on .sq.gives-check .mark-check { display: flex; }
/* Not your move (opponent's piece, or waiting for your turn): same markers, in grey */
.board.tips-on.inspect .sq.target .mark::after { background: rgba(92, 98, 95, 0.9); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7); }
.board.tips-on.inspect .sq.target.capture .mark::after { background: transparent; box-shadow: inset 0 0 0 calc(var(--board-size, 480px) / 80) rgba(84, 90, 87, 0.92), inset 0 0 0 calc(var(--board-size, 480px) / 80 + 2px) rgba(255, 255, 255, 0.6); }
.board.tips-on.inspect .sq.gives-check .mark-check { background: #C4C9C5; }
.board.inspect .sq.sel::before { background: rgba(190, 196, 192, 0.6); }

/* Capture: the taken piece pops, spins and fades under the arriving one */
.sq .pc.capture-ghost { position: absolute; left: 5%; top: 5%; z-index: 2; pointer-events: none; transform-origin: 50% 70%; animation: captured calc(0.46s * var(--anim-k, 1)) cubic-bezier(0.4, 0, 0.2, 1) calc(0.1s * var(--anim-k, 1)) both; }
.capture-burst { position: absolute; inset: 8%; z-index: 1; border-radius: 50%; pointer-events: none; border: calc(var(--board-size, 480px) / 110) solid rgba(255, 214, 102, 0.95); animation: captureBurst calc(0.5s * var(--anim-k, 1)) ease-out calc(0.16s * var(--anim-k, 1)) both; }
@keyframes captured {
    0% { transform: scale(1) rotate(0); opacity: 1; }
    30% { transform: scale(1.1) rotate(-8deg); opacity: 1; }
    100% { transform: scale(0.15) rotate(25deg) translateY(12%); opacity: 0; }
}
@keyframes captureBurst {
    0% { transform: scale(0.3); opacity: 0; }
    25% { opacity: 1; }
    100% { transform: scale(1.35); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .sq .pc.capture-ghost, .capture-burst { display: none; }
}
.tips-on .sq.attacked-piece .pc { animation: wiggle 2s ease-in-out infinite; }

.board-arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.board-arrows line { stroke: rgba(255, 196, 61, 0.9); stroke-linecap: round; }
.board-arrows polygon { fill: rgba(255, 196, 61, 0.9); }

.promo-picker {
    position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
    background: rgba(12, 17, 14, 0.6); border-radius: 10px; animation: fadeIn 0.2s ease;
}
.promo-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 14px; text-align: center; box-shadow: var(--shadow); animation: popIn 0.25s var(--ease); }
.promo-box p { font-size: 13px; font-weight: 800; color: var(--text-muted); margin-bottom: 10px; }
.promo-options { display: flex; gap: 8px; }
.promo-options button {
    width: calc(var(--board-size, 480px) / 6); height: calc(var(--board-size, 480px) / 6); max-width: 80px; max-height: 80px; min-width: 52px; min-height: 52px;
    border-radius: 12px; border: 1.5px solid var(--border); background: var(--sq-light); cursor: pointer; padding: 4px;
    transition: transform 0.15s, border-color 0.2s;
}
.promo-options button:hover { transform: translateY(-2px); border-color: var(--accent); }
.promo-options .pc { width: 100%; height: 100%; }

.banner {
    width: 100%; max-width: var(--board-size, 480px); margin: 0 auto 8px; padding: 9px 12px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; text-align: center;
    font-size: 14px; font-weight: 700; animation: slideDown 0.3s var(--ease);
    background: rgba(255, 234, 167, 0.1); border: 1px solid rgba(255, 234, 167, 0.35); color: var(--yellow);
}
.banner.warn { background: rgba(255, 107, 107, 0.12); border-color: rgba(255, 107, 107, 0.35); color: #FFB3B3; }
.banner .btn { padding: 7px 12px; font-size: 13px; }

/* Side panel / bottom bar */
.side-panel { flex-shrink: 0; background: var(--bg-surface); border-top: 1px solid var(--border); padding: 8px 12px calc(8px + var(--safe-bottom)); }
.side-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.side-title { display: none; }
.moves-wrap { min-width: 0; }
.move-list {
    list-style: none; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; font-size: 13.5px;
    font-variant-numeric: tabular-nums; min-height: 30px; align-items: center;
}
.move-list::-webkit-scrollbar { display: none; }
.move-list:empty::before { content: attr(data-empty); color: var(--text-dim); font-size: 13px; font-weight: 700; }
.move-row { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.move-num { color: var(--text-dim); font-weight: 700; padding: 0 2px 0 6px; }
.move-san { padding: 4px 7px; border-radius: 7px; font-weight: 700; color: var(--text-muted); white-space: nowrap; }
.san-pc { display: inline-block; width: 1.3em; height: 1.3em; vertical-align: -0.3em; margin-right: 1px; }
.san-pc .pc { width: 100%; height: 100%; stroke-width: 6; }
.move-san.current { background: rgba(30, 158, 94, 0.25); color: var(--text); }

.game-actions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.game-actions::-webkit-scrollbar { display: none; }
.action-btn {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 7px 3px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-card);
    color: var(--text-muted); font-size: 11.5px; font-weight: 800; cursor: pointer; transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.action-btn > span { white-space: nowrap; }
.action-btn:hover:not(:disabled) { color: var(--text); background: var(--bg-card-hover); }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.action-btn.danger:hover:not(:disabled) { color: var(--red); }
.action-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tip-toggle[aria-pressed="true"] { background: rgba(255, 234, 167, 0.14); border-color: rgba(255, 234, 167, 0.5); color: var(--yellow); }
.tip-toggle[aria-pressed="true"] svg { filter: drop-shadow(0 0 6px rgba(255, 234, 167, 0.6)); }

/* Tip card */
.tip-card { display: none; }
.tip-card.visible { display: block; animation: slideUp 0.25s var(--ease); }
.tip-inner { background: var(--bg-card); border: 1px solid rgba(255, 234, 167, 0.25); border-radius: 14px; padding: 12px 14px; }
.tip-head { display: flex; align-items: center; gap: 10px; }
.tip-piece { width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px; background: var(--sq-light); display: flex; align-items: center; justify-content: center; }
.tip-piece .pc { width: 88%; height: 88%; }
.tip-head strong { display: block; font-size: 15px; }
.tip-head small { display: block; font-size: 12.5px; color: var(--text-muted); font-weight: 700; }
.tip-how { font-size: 13.5px; color: var(--text-muted); line-height: 1.45; margin-top: 8px; }
.tip-facts { list-style: none; display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.tip-facts li { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.4; color: var(--text); }
.tip-facts .ti { flex-shrink: 0; width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; }
.ti.safe { background: var(--green); }
.ti.unsafe { background: var(--orange); }
.ti.capture { background: transparent; box-shadow: inset 0 0 0 2.5px var(--red); }
.ti.check { background: var(--yellow); border-radius: 4px; }
.ti.special { background: var(--blue); }
.ti.warn { background: var(--red); border-radius: 3px; transform: rotate(45deg) scale(0.85); }
.tip-facts .warn-text { color: #FFB3B3; font-weight: 700; }
.tip-empty { font-size: 13.5px; color: var(--text-muted); line-height: 1.45; display: flex; gap: 10px; align-items: center; }
.tip-empty svg { flex-shrink: 0; color: var(--yellow); }
.tip-suggest { margin-top: 8px; font-size: 13.5px; font-weight: 800; color: var(--green); }

/* Game over */
.gameover-content #gameover-icon svg { margin: 0 auto; animation: popIn 0.5s var(--ease); }
.gameover-content h2 { font-size: 26px; margin: 12px 0 4px; }

/* Rules diagrams */
.rule-diagrams { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 10px; }
.rule-diagram { margin: 0; padding: 10px; border-radius: 14px; background: var(--bg); border: 1px solid var(--border); }
.rule-diagram figcaption { font-size: 12.5px; color: var(--text-muted); margin-top: 8px; line-height: 1.4; text-align: center; }
.mini-board {
    --board-size: 180px; display: grid; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
    grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
}
.mini-board .sq { aspect-ratio: 1; min-width: 0; min-height: 0; }
.mini-board .sq .pc { width: 94%; height: 94%; filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.35)); stroke-width: 5; }
.mini-board .sq .mark::after { width: 34%; height: 34%; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }

/* Chat: a sheet from the bottom on phones and tablets, part of the side panel on wide screens */
.action-btn { position: relative; }
.chat-badge {
    position: absolute; top: 3px; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 900; line-height: 18px; text-align: center;
    box-shadow: 0 0 0 2px var(--bg-surface);
}
.chat-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.chat {
    position: fixed; left: 0; right: 0; bottom: var(--kb-offset, 0px); z-index: 71;
    height: min(72dvh, 560px, calc(var(--vv-height, 100dvh) - 12px));
    display: flex; flex-direction: column; gap: 10px; padding: 14px 14px calc(14px + var(--safe-bottom));
    background: var(--bg-card); border: 1px solid var(--border); border-bottom: none; border-radius: 22px 22px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4); transform: translateY(105%); visibility: hidden;
    transition: transform 0.28s var(--ease), visibility 0s linear 0.28s;
}
body.chat-open .chat { transform: none; visibility: visible; transition: transform 0.28s var(--ease); }
body.chat-open .chat-backdrop { opacity: 1; pointer-events: auto; }
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat .chat-title { display: block; margin: 0; font-size: 16px; font-weight: 800; color: var(--text); text-transform: none; letter-spacing: 0; }
.chat-list { list-style: none; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 2px; overscroll-behavior: contain; }
.chat-empty { margin: auto; color: var(--text-dim); font-size: 13.5px; font-weight: 700; text-align: center; padding: 12px; }
.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-msg.theirs { align-self: flex-start; align-items: flex-start; }
.chat-author { font-size: 11.5px; font-weight: 800; color: var(--text-dim); margin: 6px 6px 2px; }
.chat-text {
    padding: 7px 12px; border-radius: 16px; font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-wrap;
    background: var(--bg-card-hover); color: var(--text);
}
.chat-msg.mine .chat-text { background: var(--accent-dark); color: #fff; border-bottom-right-radius: 6px; }
.chat-msg.theirs .chat-text { border-bottom-left-radius: 6px; }
.chat-form { display: flex; gap: 8px; }
.chat-form input {
    flex: 1; min-width: 0; padding: 11px 14px; border-radius: 22px; border: 1px solid var(--border);
    /* 16px or more, or iOS Safari zooms the page when the field gets focus */
    background: var(--bg); color: var(--text); font: inherit; font-size: 16px; outline: none;
}
.chat-form input:focus { border-color: var(--accent); }
.chat-form input:disabled { opacity: 0.5; }
.chat-send {
    flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff;
}
.chat-send:hover { background: var(--accent-dark); }
.chat-form input:disabled + .chat-send { opacity: 0.5; pointer-events: none; }

/* Customise on large screens: choices on the left, live preview and options on the right */
@media (min-width: 900px) and (min-height: 600px) {
    .modal-content.style-content { max-width: 980px; padding: 28px 30px 30px; }
    .style-content h3 { font-size: 21px; margin-bottom: 20px; }
    .custom-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 30px; align-items: start; }
    .custom-main .style-section:first-child, .custom-side .style-section { margin-top: 0; }
    .custom-side { position: sticky; top: 0; display: flex; flex-direction: column; gap: 0; }
    .custom-side .style-section { margin-top: 20px; }
    .custom-preview {
        display: block; --board-size: 320px; width: 320px; height: 320px; border-radius: 12px; overflow: hidden;
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    }
    .custom-preview .board { border-radius: 12px; pointer-events: none; }
    .style-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .board-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .option-row { min-height: 46px; padding: 9px 14px; font-size: 14px; }
}

/* Wide landscape screens: moves and actions in a side panel */
@media (min-width: 900px) and (orientation: landscape) {
    .game-body { flex-direction: row; }
    .side-panel { width: clamp(300px, 27vw, 380px); border-top: none; border-left: 1px solid var(--border); padding: 16px 16px calc(16px + var(--safe-bottom)); display: flex; }
    .side-inner { max-width: none; width: 100%; min-height: 0; gap: 14px; }
    .side-title { display: block; font-size: 12px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
    .moves-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
    .move-list { flex-direction: column; align-items: stretch; overflow-x: hidden; overflow-y: auto; gap: 2px; flex: 1; min-height: 0; }
    .move-list:empty::before { padding: 4px 0; }
    .move-row { display: grid; grid-template-columns: 36px 1fr 1fr; padding: 1px 0; border-radius: 8px; }
    .move-row:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
    .move-num { padding: 0 0 0 8px; }
    .chat, body.chat-open .chat {
        position: static; height: auto; flex: 1.1; min-height: 190px; transform: none; visibility: visible; transition: none;
        padding: 12px; border-radius: 14px; border-bottom: 1px solid var(--border); background: var(--bg); box-shadow: none; gap: 8px;
    }
    .chat .chat-title { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
    .chat-close, #btn-chat, .chat-backdrop { display: none; }
    .chat-text { font-size: 14px; }
    .chat-send { width: 40px; height: 40px; }
    .chat-form input { padding: 9px 13px; }
    .game-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; overflow: visible; }
    .action-btn { min-height: 58px; font-size: 12.5px; }
    .action-btn.primary { grid-column: 1 / -1; flex-direction: row; min-height: 48px; font-size: 14px; }
    .board-area { padding: 16px 20px; }
}

/* Phones */
@media (max-width: 640px) {
    #screen-lobby { padding-top: calc(64px + var(--safe-top)); }
    .lang-selector { display: none; }
    .lang-toggle { display: inline-flex; }
    .logo-title { font-size: 32px; }
    .logo-face { width: 54px; height: 54px; }
    .logo-face.f2 { width: 62px; height: 62px; }
    #screen-lobby.compact .logo-faces { display: none; }
    #screen-lobby.compact .logo-title { font-size: 26px; }
    #screen-lobby.compact .logo-subtitle { display: none; }
    #screen-lobby.compact .logo-area { margin-bottom: 14px; }
    .mode-tab { flex-direction: column; gap: 2px; font-size: 12px; min-height: 52px; }

    .modal { align-items: flex-end; padding: 0; }
    .modal-content {
        max-width: none; border-radius: 22px 22px 0 0; border-bottom: none;
        padding: 26px 20px calc(22px + var(--safe-bottom)); max-height: calc(100dvh - 24px - var(--safe-top));
        animation: sheetUp 0.32s var(--ease);
    }
    .modal-content::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--text-dim); margin: -14px auto 16px; }
    .modal-actions .btn, .gameover-actions .btn, .modal-content > .btn { min-height: 50px; }
    .modal-content > .btn { width: 100%; }
    .modal-actions { gap: 8px; }
    .modal-actions .btn { flex: 1; }
    .zoom-close { top: 16px; }
    .mode-options { grid-template-columns: 1fr; }
    .mode-card-wide { flex-direction: column; align-items: stretch; }
    .mode-card-wide .btn { width: 100%; }
    .mode-card, .mode-card-wide { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; row-gap: 12px; padding: 16px; }
    .mode-card > :not(.mode-icon):not(.mode-body) { grid-column: 1 / -1; }
    .mode-icon { width: 40px; height: 40px; }
    .mode-body h3 { font-size: 16px; margin-bottom: 2px; }
    .mode-body p { font-size: 13px; }
    .game-header { padding: calc(8px + var(--safe-top)) 10px 8px; }
    .game-title span { display: none; }
    .game-title img { width: 26px; height: 26px; }
    .board-area { padding: 6px 8px; }
    .clock { min-width: 66px; font-size: 17px; padding: 5px 8px; }
    .pb-name { font-size: 14px; }
    .site-footer { margin-top: 28px; }
    .tip-inner { padding: 10px 12px; }
    .tip-how { display: none; }
    .tip-card.expanded .tip-how { display: block; }
    .game-actions { gap: 4px; }
    .action-btn { padding: 7px 2px; font-size: 10.5px; letter-spacing: -0.01em; }
    .action-btn.danger { flex-grow: 1.3; }
}
@media (max-width: 380px) {
    .turn-indicator { max-width: 38vw; }
    .mode-badge { display: none; }
    .action-btn { font-size: 10.5px; padding: 7px 4px; }
}
@media (max-height: 560px) and (orientation: landscape) {
    .game-header { padding-top: calc(4px + var(--safe-top)); padding-bottom: 4px; }
    .board-area { padding-top: 4px; padding-bottom: 4px; }
}
