/* Toguz Pro Phase 1 identity. These pages consume the shared dark surface
 * hierarchy so Lobby and Analysis never split from the AppShell. */
:root {
    --tp1-white: var(--tp-product-surface, var(--tp-color-surface));
    --tp1-canvas: var(--tp-product-canvas, var(--tp-color-page));
    --tp1-navy: var(--tp-product-text, var(--tp-color-text));
    --tp1-navy-soft: var(--tp-product-muted, var(--tp-color-text-muted));
    --tp1-turquoise: var(--tp-product-gold, var(--tp-color-primary));
    --tp1-turquoise-dark: var(--tp-product-gold-hover, var(--tp-color-primary-hover));
    --tp1-turquoise-soft: color-mix(in srgb, var(--tp-product-gold, var(--tp-color-primary)) 12%, var(--tp-product-surface, var(--tp-color-surface)));
    --tp1-gold: var(--tp-product-gold, var(--tp-color-primary));
    --tp1-gold-soft: color-mix(in srgb, var(--tp-product-gold, var(--tp-color-primary)) 12%, var(--tp-product-surface, var(--tp-color-surface)));
    --tp1-muted: var(--tp-product-muted, var(--tp-color-text-muted));
    --tp1-border: var(--tp-product-border, var(--tp-color-border));
    --tp1-surface-raised: var(--tp-product-surface-raised, var(--tp-color-surface-raised));
    --tp1-surface-soft: var(--tp-product-surface-soft, var(--tp-color-surface-soft));
    --tp1-shadow: var(--tp-product-shadow, var(--tp-shadow-sm));
}

.tp-phase-page {
    min-height: 100%;
    overflow-x: hidden;
    background: var(--tp1-canvas);
    color: var(--tp1-navy);
    padding: clamp(12px, 2.5vw, 30px) clamp(12px, 3vw, 36px) calc(96px + env(safe-area-inset-bottom));
}

.tp-phase-header {
    width: min(1280px, 100%);
    margin: 0 auto 18px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    background: var(--tp1-white);
    border: 1px solid var(--tp1-border);
    border-radius: 22px;
    padding: clamp(14px, 2vw, 22px);
    box-shadow: var(--tp1-shadow);
}

.tp-phase-header h1 {
    margin: 2px 0 1px;
    color: var(--tp1-navy);
    font-size: clamp(1.25rem, 3vw, 2rem);
    line-height: 1.15;
}

.tp-phase-header p { margin: 0; color: var(--tp1-muted); }
.tp-phase-kicker { color: var(--tp1-turquoise-dark); font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.tp-phase-header__actions, .tp-phase-button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.tp-phase-icon-button,
.tp-phase-button,
.tp-phase-button-row button {
    min-height: 44px;
    border: 1px solid var(--tp1-border);
    border-radius: 13px;
    background: var(--tp1-white);
    color: var(--tp1-navy);
    font: 700 .9rem/1 system-ui, sans-serif;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.tp-phase-icon-button { width: 44px; padding: 0; }
.tp-phase-button, .tp-phase-button-row button { padding: 0 15px; }
.tp-phase-button--accent { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise); color: var(--tp-color-primary-ink); }
.tp-phase-button:hover:not(:disabled), .tp-phase-button-row button:hover:not(:disabled), .tp-phase-icon-button:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--tp1-turquoise); box-shadow: var(--tp-shadow-sm); }
.tp-phase-button:focus-visible, .tp-phase-button-row button:focus-visible, .tp-phase-icon-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 30%, transparent); outline-offset: 2px; }
.tp-phase-button:disabled, .tp-phase-button-row button:disabled { opacity: .45; cursor: not-allowed; }

.tp-phase-content { width: min(1280px, 100%); margin: 0 auto; }
.tp-phase-status { margin-bottom: 12px; border-radius: 14px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--tp1-turquoise) 44%, var(--tp1-border)); background: var(--tp1-turquoise-soft); color: var(--tp1-navy); }
.tp-phase-status[data-state="error"] { border-color: color-mix(in srgb, var(--tp-color-danger) 54%, var(--tp1-border)); background: color-mix(in srgb, var(--tp-color-danger) 12%, var(--tp1-white)); color: var(--tp-color-danger); }
.tp-phase-popover { margin: 0 0 14px auto; width: min(460px, 100%); padding: 14px; border: 1px solid var(--tp1-border); border-radius: 16px; background: var(--tp1-white); box-shadow: var(--tp1-shadow); }
.tp-phase-popover p { margin: 0 0 10px; }

.tp-replay-facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin: 0 0 14px;
}

.tp-replay-facts > div { min-width: 0; border: 1px solid var(--tp1-border); border-radius: 14px; background: var(--tp1-white); padding: 10px 12px; }
.tp-replay-facts dt { color: var(--tp1-muted); font-size: .72rem; font-weight: 700; letter-spacing: .045em; text-transform: uppercase; }
.tp-replay-facts dd { margin: 3px 0 0; overflow: hidden; color: var(--tp1-navy); font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

.tp-analysis-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(330px, .55fr); gap: 16px; align-items: start; }
.tp-analysis-viewer-card, .tp-analysis-control-card, .tp-analysis-results {
    min-width: 0;
    border: 1px solid var(--tp1-border);
    border-radius: 22px;
    background: var(--tp1-white);
    box-shadow: var(--tp1-shadow);
    padding: clamp(13px, 2vw, 20px);
}
.tp-analysis-viewer-card { grid-column: 1; }
.tp-analysis-control-card { grid-column: 2; grid-row: 1; }
/* The replay viewer resolves its own palette from the html[data-theme] token
 * layer inside its shadow root, so Analysis must not install a page-local map.
 * A per-page override here would give Analysis a different palette from
 * Replay, Watch Live and Opening Explorer — the exact theme mixing this
 * component is required to avoid. */
.tp-analysis-results { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; scroll-margin-top: 14px; }
.tp-analysis-results[hidden] { display: none; }
.tp-analysis-results > .tp-analysis-section-heading, .tp-analysis-results > .tp-analysis-best { grid-column: 1 / -1; }
.tp-analysis-results > article { border: 1px solid var(--tp1-border); border-radius: 16px; background: var(--tp1-surface-raised); padding: 14px; }
.tp-analysis-results h3 { margin: 0 0 9px; color: var(--tp1-navy); font-size: 1rem; }
.tp-analysis-best { background: linear-gradient(135deg, var(--tp1-turquoise-soft), var(--tp1-white)) !important; border-color: color-mix(in srgb, var(--tp1-turquoise) 44%, var(--tp1-border)) !important; }
.tp-analysis-best > span { color: var(--tp1-turquoise-dark); font-size: .72rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.tp-analysis-best h3 { margin: 5px 0; color: var(--tp1-navy); font-size: clamp(1.25rem, 3vw, 1.8rem); }
.tp-analysis-best p { margin: 0; color: var(--tp1-muted); }
.tp-analysis-section-heading { display: flex; justify-content: space-between; gap: 12px; align-items: end; margin-bottom: 12px; }
.tp-analysis-section-heading span { color: var(--tp1-turquoise-dark); font-size: .72rem; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.tp-analysis-section-heading h2 { margin: 2px 0 0; color: var(--tp1-navy); font-size: 1.16rem; }
.tp-analysis-section-heading > strong { max-width: 52%; color: var(--tp1-muted); font-size: .8rem; text-align: right; }
.tp-analysis-source-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 15px; padding: 4px; border-radius: 13px; background: var(--tp1-surface-soft); }
.tp-analysis-source-tabs button { min-height: 42px; border: 0; border-radius: 10px; background: transparent; color: var(--tp1-muted); font-weight: 800; cursor: pointer; }
.tp-analysis-source-tabs button.is-active { background: var(--tp1-white); color: var(--tp1-navy); box-shadow: var(--tp-shadow-xs); }
.tp-analysis-control-card h2 { margin: 0 0 10px; font-size: 1rem; }
.tp-analysis-control-card label:not(.tp-phase-button) { color: var(--tp1-navy); font-size: .78rem; font-weight: 800; }
.tp-analysis-control-card textarea, .tp-analysis-control-card input[type="number"], .tp-analysis-control-card select {
    width: 100%; min-height: 44px; border: 1px solid var(--tp1-border); border-radius: 11px; background: var(--tp1-surface-raised); color: var(--tp1-navy); padding: 9px 10px; font: inherit;
}
.tp-analysis-control-card textarea { margin-top: 5px; resize: vertical; }
.tp-analysis-control-card textarea:focus, .tp-analysis-control-card input:focus, .tp-analysis-control-card select:focus { border-color: var(--tp1-turquoise); outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 24%, transparent); }
.tp-analysis-import-row, .tp-analysis-inline-actions, .tp-analysis-run-row { display: flex; flex-wrap: wrap; gap: 7px; margin: 9px 0; }
.tp-analysis-import-row .tp-phase-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 130px; }
.tp-analysis-dropzone { margin: 9px 0; border: 1px dashed var(--tp1-border); border-radius: 12px; padding: 12px; color: var(--tp1-muted); text-align: center; }
.tp-analysis-dropzone.is-dragging { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise-soft); color: var(--tp1-navy); }
#analysis-input-help { margin: 6px 0 8px; color: var(--tp1-muted); font-size: .75rem; }
.tp-analysis-inline-actions button, .tp-analysis-editor-heading button { min-height: 38px; border: 0; background: transparent; color: var(--tp1-turquoise-dark); font-weight: 800; cursor: pointer; }
.tp-analysis-control-card pre { overflow: auto; border-radius: 10px; background: var(--tp1-surface-soft); color: var(--tp1-navy); padding: 10px; }
.tp-analysis-error { margin: 8px 0; border-radius: 10px; background: color-mix(in srgb, var(--tp-color-danger) 12%, var(--tp1-white)); color: var(--tp-color-danger); padding: 9px 10px; font-size: .78rem; }
.tp-analysis-editor-heading { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.tp-analysis-editor-heading p { margin: -5px 0 8px; color: var(--tp1-muted); font-size: .75rem; }
.tp-analysis-position-grid { display: grid; gap: 7px; }
.tp-analysis-pit-group { min-width: 0; margin: 0; border: 1px solid var(--tp1-border); border-radius: 12px; padding: 7px; display: grid; grid-template-columns: repeat(9, minmax(0,1fr)); gap: 3px; }
.tp-analysis-pit-group legend { grid-column: 1 / -1; padding: 0 4px; color: var(--tp1-muted); font-size: .7rem; font-weight: 800; }
.tp-analysis-pit-group label { min-width: 0; text-align: center; font-size: .67rem !important; }
.tp-analysis-pit-group input[type="number"] { min-width: 0; min-height: 38px; padding: 4px 1px; text-align: center; -moz-appearance: textfield; }
.tp-analysis-pit-group input::-webkit-inner-spin-button { margin: 0; appearance: none; }
.tp-analysis-position-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.tp-analysis-position-meta label:last-child { grid-column: 1 / -1; }
.tp-analysis-position-meta input, .tp-analysis-position-meta select { margin-top: 3px; }
.tp-analysis-stone-check { display: flex; justify-content: space-between; margin-top: 8px; border-radius: 11px; background: var(--tp1-turquoise-soft); padding: 9px 10px; }
.tp-analysis-stone-check strong.is-invalid { color: var(--tp-color-danger); }
.tp-analysis-presets { margin: 15px 0 0; border: 0; padding: 0; }
.tp-analysis-presets legend { margin-bottom: 7px; color: var(--tp1-navy); font-size: .78rem; font-weight: 900; }
.tp-analysis-presets label { display: block; position: relative; margin: 5px 0; cursor: pointer; }
.tp-analysis-presets input { position: absolute; opacity: 0; pointer-events: none; }
.tp-analysis-presets label span { display: block; border: 1px solid var(--tp1-border); border-radius: 12px; padding: 10px 12px; transition: border-color .15s ease, background .15s ease; }
.tp-analysis-presets label strong, .tp-analysis-presets label small { display: block; }
.tp-analysis-presets label small { margin-top: 2px; color: var(--tp1-muted); font-weight: 500; }
.tp-analysis-presets input:checked + span { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise-soft); box-shadow: inset 4px 0 var(--tp1-turquoise); }
.tp-analysis-presets input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 28%, transparent); outline-offset: 2px; }
.tp-analysis-run-row .tp-phase-button { flex: 1; }
.tp-analysis-progress { margin-top: 8px; border-radius: 10px; background: var(--tp1-gold-soft); color: var(--tp1-navy); padding: 10px; }
.tp-analysis-progress > span { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: tp1-spin .8s linear infinite; }
.tp-analysis-finding + .tp-analysis-finding { margin-top: 8px; border-top: 1px solid var(--tp1-border); padding-top: 8px; }
.tp-analysis-finding button { margin: 0 0 4px; border: 0; background: transparent; color: var(--tp1-turquoise-dark); padding: 0; font-size: .74rem; font-weight: 850; cursor: pointer; }
.tp-analysis-finding strong { display: block; color: var(--tp1-navy); }
.tp-analysis-finding p, .tp-analysis-empty { margin: 3px 0 0; color: var(--tp1-muted); font-size: .8rem; }
@keyframes tp1-spin { to { transform: rotate(360deg); } }

.tp-play-lobby,
.tp-play-lobby * { box-sizing: border-box; }
.tp-play-lobby :where(.tp-phase-content, .tp-play-lobby-grid, .tp-play-room-browser, .tp-play-tabpanel, .tp-play-table-card, .tp-play-table-card > *, .tp-play-online-summary) { min-width: 0; }
.tp-play-primary-actions { display: grid; grid-template-columns: minmax(0, 1.2fr) repeat(2, minmax(0, 1fr)); gap: 9px; }
.tp-play-primary-action { display: flex; min-width: 0; min-height: 72px; gap: 11px; align-items: center; border: 1px solid var(--tp1-border); border-radius: 15px; background: var(--tp1-white); color: var(--tp1-navy); padding: 11px 14px; text-align: left; box-shadow: var(--tp-shadow-xs); cursor: pointer; }
.tp-play-primary-action > i { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px; background: var(--tp1-turquoise-soft); color: var(--tp1-turquoise-dark); }
.tp-play-primary-action span, .tp-play-primary-action strong, .tp-play-primary-action small { display: block; min-width: 0; }
.tp-play-primary-action strong { font-size: .9rem; }
.tp-play-primary-action small { margin-top: 3px; color: var(--tp1-muted); font-size: .7rem; line-height: 1.35; }
.tp-play-primary-action--quick { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise); color: var(--tp-color-primary-ink); }
.tp-play-primary-action--quick > i { background: color-mix(in srgb, var(--tp1-white) 42%, transparent); color: inherit; }
.tp-play-primary-action--quick small { color: color-mix(in srgb, var(--tp-color-primary-ink) 76%, transparent); }
.tp-play-primary-action:hover { border-color: var(--tp1-turquoise); }
.tp-play-primary-action:focus-visible,
.tp-play-tabs button:focus-visible,
.tp-play-inline-action:focus-visible { outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 28%, transparent); outline-offset: 2px; }
.tp-play-quick-note { display: flex; flex-wrap: wrap; gap: 7px 9px; align-items: center; margin: 8px 2px 13px; color: var(--tp1-muted); font-size: .75rem; line-height: 1.45; }
.tp-play-mode-badge { flex: 0 0 auto; border: 1px solid color-mix(in srgb, var(--tp1-gold) 46%, var(--tp1-border)); border-radius: 999px; background: var(--tp1-gold-soft); color: var(--tp1-navy); padding: 3px 8px; font-size: .64rem; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.tp-play-lobby-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(250px, 3fr); gap: 13px; align-items: start; }
.tp-play-room-browser,
.tp-play-online-summary { border: 1px solid var(--tp1-border); border-radius: 18px; background: var(--tp1-white); box-shadow: var(--tp1-shadow); }
.tp-play-room-browser { overflow: hidden; }
.tp-play-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; border-bottom: 1px solid var(--tp1-border); background: var(--tp1-surface-soft); padding: 7px; }
.tp-play-tabs button { min-width: 0; min-height: 44px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--tp1-muted); padding: 7px 9px; font: inherit; font-size: .78rem; font-weight: 800; line-height: 1.25; cursor: pointer; }
.tp-play-tabs button.is-active { border-color: var(--tp1-border); background: var(--tp1-white); color: var(--tp1-navy); box-shadow: var(--tp-shadow-xs); }
.tp-play-tabpanel { padding: 12px; }
.tp-play-tabpanel[hidden],
.tp-play-active-table[hidden] { display: none; }
.tp-play-list-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.tp-play-list-heading > div > span,
.tp-play-active-table > div > span { color: var(--tp1-turquoise-dark); font-size: .68rem; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.tp-play-list-heading h3,
.tp-play-active-table h3 { margin: 2px 0 0; color: var(--tp1-navy); font-size: 1rem; }
.tp-play-list-heading label { width: min(220px, 42%); color: var(--tp1-muted); font-size: .7rem; font-weight: 750; }
.tp-play-list-heading input,
.tp-play-create-form input,
.tp-play-create-form select,
.tp-play-friend-grid input,
.tp-play-friend-grid select,
.tp-play-copy-row input { width: 100%; min-width: 0; min-height: 44px; margin-top: 4px; border: 1px solid var(--tp1-border); border-radius: 10px; background: var(--tp1-surface-raised); color: var(--tp1-navy); padding: 8px 10px; font: inherit; }
.tp-play-list-heading input:focus,
.tp-play-create-form input:focus,
.tp-play-create-form select:focus,
.tp-play-friend-grid input:focus,
.tp-play-friend-grid select:focus { border-color: var(--tp1-turquoise); outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 24%, transparent); }
.tp-play-inline-action { display: inline-flex; min-height: 44px; gap: 7px; align-items: center; border: 0; border-radius: 10px; background: var(--tp1-surface-soft); color: var(--tp1-navy); padding: 0 12px; font-weight: 800; cursor: pointer; }
.tp-play-table-list { display: grid; gap: 7px; }
.tp-play-table-card { display: grid; grid-template-columns: minmax(150px, 1.35fr) repeat(3, minmax(78px, .55fr)) auto; min-height: 72px; gap: 9px; align-items: center; border: 1px solid var(--tp1-border); border-radius: 12px; background: var(--tp1-white); padding: 9px 10px; }
.tp-play-table-card--live { grid-template-columns: minmax(180px, 1.5fr) repeat(2, minmax(90px, .6fr)) auto; }
.tp-play-table-card--mine { grid-template-columns: minmax(160px, 1.4fr) repeat(2, minmax(90px, .6fr)); }
.tp-play-table-card__host { display: flex; gap: 9px; align-items: center; min-width: 0; }
.tp-play-table-card__players { min-width: 0; }
.tp-play-table-card__avatar { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; border-radius: 50%; background: var(--tp1-turquoise-soft); color: var(--tp1-turquoise-dark); font-weight: 900; }
.tp-play-table-card strong,
.tp-play-table-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-play-table-card small { margin-top: 2px; color: var(--tp1-muted); font-size: .72rem; }
.tp-play-table-card__fact span { display: block; color: var(--tp1-muted); font-size: .62rem; letter-spacing: .03em; text-transform: uppercase; }
.tp-play-table-card__fact strong { margin-top: 2px; font-size: .77rem; }
.tp-play-table-card button { min-height: 44px; border: 0; border-radius: 10px; background: var(--tp1-turquoise); color: var(--tp-color-primary-ink); padding: 0 13px; font-weight: 850; cursor: pointer; }
.tp-play-table-card button:disabled { background: var(--tp1-surface-soft); color: var(--tp1-muted); cursor: not-allowed; }
.tp-play-list-state { border: 1px dashed var(--tp1-border); border-radius: 12px; padding: 18px; color: var(--tp1-muted); text-align: center; }
.tp-play-list-state h4 { margin: 0; color: var(--tp1-navy); font-size: .92rem; }
.tp-play-list-state p { margin: 6px auto 0; max-width: 520px; font-size: .76rem; line-height: 1.5; }
.tp-play-list-state--loading { background: var(--tp1-surface-raised); }
.tp-play-list-state--loading h4::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 7px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: tp1-spin .8s linear infinite; }
.tp-play-list-state--error { border-style: solid; border-color: color-mix(in srgb, var(--tp-color-danger, var(--tp1-gold)) 36%, var(--tp1-border)); background: color-mix(in srgb, var(--tp-color-danger, var(--tp1-gold)) 6%, var(--tp1-white)); }
.tp-play-empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.tp-play-empty__actions .tp-phase-button { min-width: 138px; }
.tp-play-online-summary { position: sticky; top: 12px; padding: 15px; }
.tp-play-online-summary h2 { margin: 3px 0 5px; color: var(--tp1-navy); font-size: 1rem; }
.tp-play-online-summary dl { display: grid; gap: 7px; margin: 13px 0; }
.tp-play-online-summary dl div { display: flex; min-height: 52px; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--tp1-border); border-radius: 11px; background: var(--tp1-surface-raised); padding: 9px 11px; }
.tp-play-online-summary dt { color: var(--tp1-muted); font-size: .74rem; }
.tp-play-online-summary dd { margin: 0; color: var(--tp1-turquoise-dark); font-size: 1.2rem; font-weight: 900; }
.tp-play-online-summary dd[data-state="loading"],
.tp-play-online-summary dd[data-state="unavailable"] { max-width: 50%; overflow-wrap: anywhere; font-size: .72rem; line-height: 1.2; text-align: right; }
.tp-play-online-summary p { margin: 0; color: var(--tp1-muted); font-size: .7rem; line-height: 1.5; overflow-wrap: anywhere; }
.tp-play-panel__copy h3 { margin: 0 0 4px; color: var(--tp1-navy); }
.tp-play-panel__copy p,
.tp-play-active-table p { margin: 0; color: var(--tp1-muted); font-size: .78rem; line-height: 1.45; }
.tp-play-drawer { inset: 0 0 0 auto; width: min(440px, 100vw); max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; border: 0; border-left: 1px solid var(--tp1-border); background: var(--tp1-white); color: var(--tp1-navy); padding: 0; overflow: hidden; box-shadow: -18px 0 48px color-mix(in srgb, var(--tp1-navy) 18%, transparent); }
.tp-play-drawer[open] { display: flex; flex-direction: column; }
.tp-play-drawer::backdrop { background: color-mix(in srgb, var(--tp1-navy) 40%, transparent); backdrop-filter: blur(2px); }
.tp-play-drawer__header { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--tp1-border); padding: 14px 16px; }
.tp-play-drawer__header h2 { margin: 3px 0 0; font-size: 1.15rem; }
.tp-play-drawer > section { min-width: 0; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)); scroll-padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.tp-play-create-form { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
.tp-play-create-form fieldset { display: grid; grid-template-columns: 1fr 1fr; min-width: 0; gap: 8px; margin: 0; border: 1px solid var(--tp1-border); border-radius: 13px; padding: 11px; }
.tp-play-create-form legend { padding: 0 5px; color: var(--tp1-navy); font-size: .78rem; font-weight: 900; }
.tp-play-create-form label,
.tp-play-friend-grid label { min-width: 0; color: var(--tp1-muted); font-size: .7rem; font-weight: 750; }
.tp-play-create-form > button { width: 100%; min-height: 48px; justify-self: stretch; }
.tp-play-toggle { display: flex !important; min-height: 44px; gap: 8px; align-items: center; }
.tp-play-toggle input { width: 20px !important; min-height: 20px !important; margin: 0 !important; accent-color: var(--tp1-turquoise); }
.tp-play-friend-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
.tp-play-friend-grid form { display: grid; min-width: 0; gap: 8px; align-content: start; border: 1px solid var(--tp1-border); border-radius: 13px; background: var(--tp1-surface-raised); padding: 12px; }
.tp-play-friend-grid h4 { margin: 0; color: var(--tp1-navy); }
.tp-play-active-table { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: start; margin-top: 10px; border: 1px solid color-mix(in srgb, var(--tp1-turquoise) 44%, var(--tp1-border)); border-radius: 13px; background: linear-gradient(135deg,var(--tp1-turquoise-soft),var(--tp1-white)); padding: 12px; }
.tp-play-copy-row { display: flex; min-width: 0; gap: 6px; }
.tp-play-copy-row input { margin: 0; }
.tp-play-copy-row button { flex: 0 0 auto; min-height: 44px; border: 0; border-radius: 10px; background: var(--tp1-surface-soft); color: var(--tp1-navy); font-weight: 800; cursor: pointer; }

.tp-opening-layout { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(300px,.55fr); gap: 14px; align-items: start; }
.tp-opening-viewer, .tp-opening-directory { min-width: 0; border: 1px solid var(--tp1-border); border-radius: 22px; background: var(--tp1-white); box-shadow: var(--tp1-shadow); padding: clamp(12px,2vw,18px); }
.tp-opening-directory { max-height: 760px; overflow: hidden; display: flex; flex-direction: column; }
.tp-opening-directory__heading { margin-bottom: 10px; }
.tp-opening-directory__heading span { color: var(--tp1-turquoise-dark); font-size: .7rem; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.tp-opening-directory__heading h2 { margin: 2px 0 9px; color: var(--tp1-navy); }
.tp-opening-directory__heading input { width: 100%; min-height: 44px; border: 1px solid var(--tp1-border); border-radius: 11px; background: var(--tp1-surface-raised); color: var(--tp1-navy); padding: 8px 10px; font: inherit; }
.tp-opening-directory #games-db-list { min-height: 0; overflow: auto; display: grid; gap: 7px; padding-right: 3px; }
.tp-opening-directory .db-game-card { border: 1px solid var(--tp1-border); border-radius: 13px; background: var(--tp1-surface-raised); padding: 11px; }
.tp-opening-directory .db-game-card > strong { display: block; color: var(--tp1-navy); }
.tp-opening-directory .db-game-card > p { margin: 3px 0 8px; color: var(--tp1-muted); font-size: .75rem; }
.tp-opening-directory .db-replay-btn { min-height: 40px; border: 0; border-radius: 10px; background: var(--tp1-turquoise); color: var(--tp-color-primary-ink); padding: 0 12px; font-weight: 800; cursor: pointer; }

.tp-watch-layout { display: grid; grid-template-columns: minmax(260px,.42fr) minmax(0,1.58fr); gap: 14px; align-items: start; }
.tp-watch-directory, .tp-watch-stage { min-width: 0; border: 1px solid var(--tp1-border); border-radius: 22px; background: var(--tp1-white); box-shadow: var(--tp1-shadow); padding: clamp(12px,2vw,18px); }
.tp-watch-heading span, .tp-watch-stage__heading > div > span { color: var(--tp1-turquoise-dark); font-size: .7rem; font-weight: 900; letter-spacing: .07em; text-transform: uppercase; }
.tp-watch-heading h2, .tp-watch-stage__heading h2 { margin: 2px 0 4px; color: var(--tp1-navy); }
.tp-watch-stage__heading { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 10px; }
.tp-watch-stage__heading p { margin: 0; color: var(--tp1-muted); }
.tp-watch-list { display: grid; gap: 7px; max-height: 680px; overflow: auto; }
.tp-watch-game { width: 100%; border: 1px solid var(--tp1-border); border-radius: 13px; background: var(--tp1-surface-raised); color: var(--tp1-navy); padding: 11px; text-align: left; cursor: pointer; }
.tp-watch-game.is-active { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise-soft); }
.tp-watch-game strong, .tp-watch-game span { display: block; }
.tp-watch-game span { margin-top: 3px; color: var(--tp1-muted); font-size: .75rem; }
.tp-watch-game:focus-visible { outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 28%, transparent); outline-offset: 2px; }
#watch-finished-replay { margin-top: 10px; }

/* The application shell carries the Phase 1 identity without changing game-board themes. */
.tp-topbar {
    background: color-mix(in srgb, var(--tp-product-surface, var(--tp-color-header)) 96%, transparent);
    border-bottom-color: var(--tp1-border);
    box-shadow: var(--tp-shadow-xs);
    backdrop-filter: blur(14px);
}
.tp-brand { color: var(--tp1-navy); }
.tp-brand__logo {
    width: 142px;
    height: 44px;
    border: 0;
    border-radius: 6px;
}
.tp-desktop-nav__item { color: var(--tp1-muted); }
.tp-desktop-nav__item:hover,
.tp-desktop-nav__item[aria-expanded="true"] {
    background: var(--tp1-turquoise-soft);
    color: var(--tp1-turquoise-dark);
}
.tp-desktop-nav__item.is-active {
    color: var(--tp1-turquoise-dark);
    box-shadow: inset 0 -2px 0 var(--tp1-turquoise);
}
.tp-shell-icon-button,
.tp-online-status,
.tp-profile-trigger {
    border-color: var(--tp1-border);
    background: var(--tp1-surface-raised);
    color: var(--tp1-navy);
}
.tp-shell-icon-button:hover,
.tp-profile-trigger:hover,
.tp-profile-trigger[aria-expanded="true"] {
    border-color: color-mix(in srgb, var(--tp1-turquoise) 46%, var(--tp1-border));
    background: var(--tp1-turquoise-soft);
    color: var(--tp1-turquoise-dark);
}
.tp-profile-trigger__avatar { background: var(--tp1-turquoise-soft); }
.tp-profile-trigger__chevron { color: var(--tp1-muted); }
.tp-rating-badge { color: var(--tp1-turquoise); }
.tp-profile-menu,
.tp-tools-menu {
    border-color: var(--tp1-border);
    background: var(--tp1-surface-raised);
    color: var(--tp1-navy);
    box-shadow: var(--tp1-shadow);
}
.tp-profile-menu button,
.tp-tools-menu button { color: var(--tp1-navy); }
.tp-profile-menu button:hover,
.tp-tools-menu button:hover { background: var(--tp1-turquoise-soft); }
.tp-tools-menu__label { color: var(--tp1-muted); }

/* Home remains the platform hub and adopts the same Phase 1 identity. */
#screen-home.tp-home {
    min-height: 100%;
    overflow-x: hidden;
    background: var(--tp1-canvas);
    color: var(--tp1-navy);
    padding: clamp(12px, 2.5vw, 30px) clamp(12px, 3vw, 36px) calc(96px + env(safe-area-inset-bottom));
}

.tp-home .tp-home__content { width: min(1280px, 100%); margin: 0 auto; }
.tp-home .tp-home-hero {
    position: relative;
    min-height: 330px;
    overflow: hidden;
    border: 1px solid var(--tp1-border);
    border-radius: 26px;
    background: var(--tp1-white);
    color: var(--tp1-navy);
    box-shadow: var(--tp1-shadow);
}
.tp-home .tp-home-hero::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 7px;
    background: linear-gradient(var(--tp1-turquoise), var(--tp1-gold));
}
.tp-home .tp-home__eyebrow, .tp-home .tp-section-heading__kicker { color: var(--tp1-turquoise-dark); }
.tp-home .tp-home-hero h1, .tp-home .tp-section-heading h2 { color: var(--tp1-navy); }
.tp-home .tp-home-hero__subtitle, .tp-home .tp-home-opening-shortcuts > p { color: var(--tp1-muted); }
.tp-home .tp-home__rating { border-color: color-mix(in srgb, var(--tp1-gold) 44%, var(--tp1-border)); background: var(--tp1-gold-soft); color: var(--tp1-navy); }
.tp-home .tp-home__rating i { color: var(--tp1-gold); }
.tp-home .tp-home__status { border-color: color-mix(in srgb, var(--tp1-turquoise) 42%, var(--tp1-border)); background: var(--tp1-turquoise-soft); color: var(--tp1-turquoise-dark); }
.tp-home .tp-home-hero__board-art { border: 1px solid var(--tp1-border); box-shadow: var(--tp1-shadow); }

.tp-home .tp-button { min-height: 44px; border-radius: 12px; }
.tp-home .tp-button--primary { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise); color: var(--tp-color-primary-ink); }
.tp-home .tp-button--secondary { border-color: var(--tp1-border); background: var(--tp1-surface-raised); color: var(--tp1-navy); }
.tp-home .tp-button--ghost { border-color: var(--tp1-border); background: transparent; color: var(--tp1-turquoise-dark); }
.tp-home .tp-button:focus-visible, .tp-home button:focus-visible { outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 30%, transparent); outline-offset: 2px; }

.tp-home .tp-home__play-grid { grid-template-columns: minmax(0,1.45fr) minmax(300px,.55fr); gap: 16px; }
.tp-home .tp-home-section {
    min-width: 0;
    border: 1px solid var(--tp1-border);
    border-radius: 21px;
    background: var(--tp1-white);
    color: var(--tp1-navy);
    box-shadow: var(--tp-shadow-xs);
}
.tp-home .tp-home__information-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
.tp-home .tp-home-recent { grid-column: span 2; }
.tp-home .tp-home-discovery-grid { display: grid; grid-template-columns: 1.35fr .65fr; gap: 16px; margin-top: 16px; }

.tp-home-action-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin-bottom: 12px; }
.tp-home-action {
    display: flex;
    min-width: 0;
    min-height: 72px;
    gap: 11px;
    align-items: center;
    border: 1px solid var(--tp1-border);
    border-radius: 14px;
    background: linear-gradient(145deg,var(--tp1-surface-raised),var(--tp1-white));
    color: var(--tp1-navy);
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
}
.tp-home-action > i { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px; background: var(--tp1-turquoise-soft); color: var(--tp1-turquoise-dark); }
.tp-home-action span, .tp-home-action strong, .tp-home-action small { display: block; min-width: 0; }
.tp-home-action small { margin-top: 2px; overflow: hidden; color: var(--tp1-muted); text-overflow: ellipsis; white-space: nowrap; }
.tp-home-action:hover { border-color: var(--tp1-turquoise); transform: translateY(-1px); }

.tp-home .tp-quick-play__controls { border-top: 1px solid var(--tp1-border); padding-top: 12px; }
.tp-home .tp-time-control { background: var(--tp1-surface-raised); color: var(--tp1-navy); }
.tp-home .tp-time-control--featured { border-color: color-mix(in srgb, var(--tp1-turquoise) 42%, var(--tp1-border)); background: var(--tp1-turquoise-soft); }
.tp-home .tp-time-control small { color: var(--tp1-muted); }

.tp-hub-list { display: grid; gap: 7px; }
.tp-hub-row {
    display: flex;
    width: 100%;
    min-width: 0;
    min-height: 58px;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--tp1-border);
    border-radius: 13px;
    background: var(--tp1-surface-raised);
    color: var(--tp1-navy);
    padding: 9px 11px;
    text-align: left;
}
button.tp-hub-row { cursor: pointer; }
button.tp-hub-row:hover { border-color: var(--tp1-turquoise); background: var(--tp1-turquoise-soft); }
.tp-hub-row__copy { display: block; min-width: 0; }
.tp-hub-row__copy strong, .tp-hub-row__copy span { display: block; }
.tp-hub-row__copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-hub-row__copy span { margin-top: 2px; color: var(--tp1-muted); font-size: .75rem; line-height: 1.35; }
.tp-hub-row__meta { flex: 0 0 auto; color: var(--tp1-turquoise-dark); font-size: .7rem; font-weight: 850; }
.tp-hub-row--static { align-items: start; }

.tp-home .tp-home-empty { border-color: var(--tp1-border); background: var(--tp1-surface-raised); color: var(--tp1-muted); }
.tp-home .tp-home-empty strong, .tp-home .tp-continue-card__title, .tp-home .tp-event-card__name { color: var(--tp1-navy); }
.tp-home .tp-news-item, .tp-home .tp-history-row, .tp-home .tp-event-card, .tp-home .tp-continue-card { border-color: var(--tp1-border); background: var(--tp1-surface-raised); color: var(--tp1-navy); }
.tp-home .tp-history-row__meta, .tp-home .tp-news-item__summary, .tp-home .tp-continue-card__detail, .tp-home .tp-event-card__meta { color: var(--tp1-muted); }
.tp-home-inline-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.tp-exercise-card > strong { display: block; color: var(--tp1-navy); font-size: 1rem; }
.tp-exercise-card > p { margin: 7px 0 14px; color: var(--tp1-muted); line-height: 1.5; }

@media (max-width: 900px) {
    .tp-play-lobby-grid { grid-template-columns: 1fr; }
    .tp-play-online-summary { position: static; }
    .tp-play-primary-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    .tp-phase-page { padding: 8px 8px calc(84px + env(safe-area-inset-bottom)); }
    .sm-app-main > #screen-play.tp-phase-page.screen.active {
        padding-bottom: calc(var(--tp-mobile-nav-height, 68px) + env(safe-area-inset-bottom, 0px) + 16px) !important;
        scroll-padding-bottom: calc(var(--tp-mobile-nav-height, 68px) + env(safe-area-inset-bottom, 0px) + 16px);
    }
    .tp-phase-header { grid-template-columns: auto minmax(0, 1fr); gap: 10px; margin-bottom: 10px; border-radius: 17px; padding: 12px; }
    .tp-phase-header__actions { grid-column: 1 / -1; }
    .tp-phase-header__actions .tp-phase-button { flex: 1 1 140px; }
    .tp-replay-facts { display: flex; overflow-x: auto; padding: 0 0 4px; scroll-snap-type: x proximity; }
    .tp-replay-facts > div { flex: 0 0 155px; scroll-snap-align: start; }
    .tp-analysis-layout { grid-template-columns: 1fr; gap: 10px; }
    .tp-analysis-viewer-card, .tp-analysis-control-card, .tp-analysis-results { grid-column: 1; grid-row: auto; border-radius: 17px; padding: 10px; }
    .tp-analysis-results { grid-template-columns: 1fr; }
    .tp-analysis-results > article { grid-column: 1 / -1; }
    .tp-analysis-control-card { order: -1; }
    .tp-analysis-section-heading { align-items: start; }
    .tp-analysis-section-heading > strong { max-width: 48%; }
    .tp-play-primary-actions { grid-template-columns: 1fr; gap: 7px; }
    .tp-play-primary-action { min-height: 62px; }
    .tp-play-room-browser, .tp-play-online-summary { border-radius: 15px; }
    .tp-play-tabs { gap: 3px; padding: 5px; }
    .tp-play-tabs button { padding: 6px 4px; font-size: .7rem; }
    .tp-play-tabpanel { padding: 9px; }
    .tp-play-list-heading { display: block; }
    .tp-play-list-heading label { display: block; width: 100%; margin-top: 8px; }
    .tp-play-table-card,
    .tp-play-table-card--live,
    .tp-play-table-card--mine { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
    .tp-play-table-card__host,
    .tp-play-table-card__players { grid-column: 1 / -1; }
    .tp-play-table-card__fact { border-radius: 8px; background: var(--tp1-surface-raised); padding: 7px; }
    .tp-play-table-card button { grid-column: 1 / -1; width: 100%; }
    .tp-play-create-form, .tp-play-friend-grid { grid-template-columns: 1fr; }
    .tp-play-create-form fieldset { grid-template-columns: 1fr 1fr; }
    .tp-play-active-table { grid-template-columns: 1fr; }
    .tp-play-drawer { width: 100vw; border-left: 0; }
    .tp-play-drawer__header,
    .tp-play-drawer > section { padding-inline: 12px; }
    .tp-play-copy-row { display: grid; grid-template-columns: minmax(0, 1fr); }
    .tp-play-copy-row button { width: 100%; }
    .tp-play-list-state { padding: 16px 12px; }
    .tp-opening-layout { grid-template-columns: 1fr; }
    .tp-opening-viewer, .tp-opening-directory { border-radius: 17px; padding: 10px; }
    .tp-opening-directory { max-height: 470px; }
    .tp-watch-layout { grid-template-columns: 1fr; }
    .tp-watch-directory, .tp-watch-stage { border-radius: 17px; padding: 10px; }
    .tp-watch-list { display: flex; max-height: none; overflow-x: auto; }
    .tp-watch-game { flex: 0 0 230px; }
    #screen-home.tp-home { padding: 8px 8px calc(84px + env(safe-area-inset-bottom)); }
    .tp-home .tp-home-hero { min-height: auto; border-radius: 18px; }
    .tp-home .tp-home__play-grid, .tp-home .tp-home__information-grid, .tp-home .tp-home-discovery-grid { grid-template-columns: 1fr; gap: 10px; }
    .tp-home .tp-home-recent { grid-column: auto; }
    .tp-home .tp-home-section { border-radius: 17px; }
    .tp-home-action-grid { grid-template-columns: 1fr 1fr; }
    .tp-home-action { min-height: 66px; padding: 8px; }
    .tp-home-action > i { flex-basis: 34px; width: 34px; height: 34px; }
    .tp-home .tp-section-heading { align-items: start; }
    .tp-home .tp-section-heading .tp-button--inline { max-width: 45%; }
}

@media (min-width: 701px) and (max-width: 1120px) {
    .tp-home .tp-home__play-grid { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
    .tp-play-empty__actions { display: grid; grid-template-columns: 1fr; }
    .tp-play-empty__actions .tp-phase-button { width: 100%; min-width: 0; }
}

@media (max-width: 1023px) {
    .tp-mobile-nav {
        border-top-color: var(--tp1-border);
        background: var(--tp1-surface-raised);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, .18);
        backdrop-filter: blur(14px);
    }
    .tp-mobile-nav__item { color: var(--tp1-muted); }
    .tp-mobile-nav__item.is-active {
        background: var(--tp1-turquoise-soft);
        color: var(--tp1-turquoise-dark);
    }
}

@media (prefers-reduced-motion: reduce) {
    .tp-phase-button, .tp-phase-button-row button, .tp-phase-icon-button { transition: none; }
}

/* Online lobby V2: two decisions, then the factual open-table list. */
.tp-play-lobby .tp-phase-content { display: grid; gap: 12px; }
.tp-play-lobby .tp-play-primary-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.tp-play-lobby .tp-play-primary-action { min-height: 76px; }
.tp-play-lobby .tp-play-primary-action:disabled { cursor: wait; opacity: .62; transform: none; }
.tp-play-current-table { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid color-mix(in srgb, var(--tp1-turquoise) 42%, var(--tp1-border)); border-radius: 13px; background: var(--tp1-turquoise-soft); padding: 9px 11px; }
.tp-play-current-table[hidden] { display: none !important; }
.tp-play-current-table > div:first-child { min-width: 0; }
.tp-play-current-table span,
.tp-play-current-table strong,
.tp-play-current-table small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-play-current-table span { color: var(--tp1-muted); font-size: .62rem; text-transform: uppercase; }
.tp-play-current-table strong { margin-top: 2px; color: var(--tp1-navy); font-size: .84rem; }
.tp-play-current-table small { margin-top: 2px; color: var(--tp1-muted); font-size: .7rem; }
.tp-play-current-table__actions { display: flex; flex: 0 0 auto; gap: 6px; }
.tp-play-current-table__actions button { min-height: 44px; border: 1px solid var(--tp1-border); border-radius: 9px; background: var(--tp1-white); color: var(--tp1-navy); padding: 0 10px; cursor: pointer; font-weight: 800; }
.tp-play-lobby .tp-play-room-browser { width: 100%; overflow: hidden; }
.tp-play-lobby .tp-play-list-heading--compact { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(180px, 220px); align-items: end; padding: 12px 13px 10px; }
.tp-play-list-heading--compact h2 { margin: 2px 0 0; color: var(--tp1-navy); font-size: 1rem; }
.tp-play-list-heading__note { margin: 4px 0 0; color: var(--tp1-muted); font-size: .7rem; line-height: 1.4; }
.tp-play-lobby-mode { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; border: 1px solid var(--tp1-border); border-radius: 10px; background: var(--tp1-surface-raised); padding: 3px; }
.tp-play-lobby-mode button { min-height: 44px; border: 0; border-radius: 7px; background: transparent; color: var(--tp1-muted); padding: 0 10px; cursor: pointer; font-size: .7rem; font-weight: 800; white-space: nowrap; }
.tp-play-lobby-mode button[aria-selected="true"] { background: var(--tp1-white); color: var(--tp1-navy); box-shadow: 0 1px 5px rgba(18, 38, 48, .1); }
.tp-play-lobby .tp-play-table-list { display: grid; max-height: min(56dvh, 600px); gap: 6px; overflow-y: auto; overscroll-behavior: contain; padding: 0 10px 10px; scrollbar-gutter: stable; }
.tp-play-lobby .tp-play-table-list[hidden] { display: none !important; }
.tp-play-lobby .tp-play-table-row {
    grid-template-columns: minmax(180px, 1.2fr) minmax(260px, 1.6fr) auto;
    min-height: 64px;
    gap: 12px;
    padding: 9px 10px;
}
.tp-play-table-row__facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; min-width: 0; }
.tp-play-table-row__facts > span { min-width: 0; padding: 5px 7px; border-radius: 8px; background: var(--tp1-surface-raised); }
.tp-play-table-row__facts small,
.tp-play-table-row__facts strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-play-table-row__facts small { color: var(--tp1-muted); font-size: .58rem; letter-spacing: .04em; text-transform: uppercase; }
.tp-play-table-row__facts strong { margin-top: 2px; color: var(--tp1-navy); font-size: .73rem; }
.tp-play-lobby .tp-play-table-row > button { min-width: 88px; min-height: 44px; }
.tp-play-lobby :is(button, input):focus-visible,
.tp-matchmaking-wait :is(button, input):focus-visible { outline: 3px solid color-mix(in srgb, var(--tp1-turquoise) 34%, transparent); outline-offset: 2px; }

.tp-matchmaking-wait {
    width: min(420px, calc(100vw - 24px));
    min-height: 0;
    margin: clamp(28px, 9vh, 90px) auto 0;
    border: 1px solid var(--tp1-border);
    border-radius: 20px;
    background: var(--tp1-white);
    color: var(--tp1-navy);
    padding: clamp(24px, 5vw, 40px);
    box-shadow: var(--tp1-shadow);
}
.tp-matchmaking-wait .searching-title { margin-top: 16px; color: var(--tp1-navy) !important; }
.tp-matchmaking-wait .searching-subtitle { margin-top: 8px; color: var(--tp1-muted); text-align: center; }
.tp-matchmaking-wait__connection { margin: 12px 0 20px; color: var(--tp1-muted); font-size: .78rem; line-height: 1.45; text-align: center; }
.tp-matchmaking-wait .cancel-search-btn { min-width: 160px; min-height: 46px; }
.tp-matchmaking-wait .cancel-search-btn:disabled { cursor: wait; opacity: .62; }

@media (max-width: 700px) {
    .tp-play-lobby .tp-phase-header { grid-template-columns: auto minmax(0, 1fr) auto; padding: 9px 10px; }
    .tp-play-lobby .tp-phase-header h1 { font-size: 1.05rem; }
    .tp-play-lobby .tp-phase-header p,
    .tp-play-lobby .tp-phase-kicker,
    .tp-play-lobby .tp-phase-header__actions span { display: none; }
    .tp-play-lobby .tp-phase-header__actions { grid-column: auto; }
    .tp-play-lobby .tp-phase-header__actions .tp-phase-button { min-width: 44px; width: 44px; padding: 0; }
    .tp-play-lobby .tp-play-primary-actions { grid-template-columns: 1fr; gap: 7px; }
    .tp-play-lobby .tp-play-primary-action { min-height: 58px; padding: 8px 10px; }
    .tp-play-current-table { align-items: stretch; }
    .tp-play-current-table__actions { display: grid; grid-template-columns: 1fr; }
    .tp-play-current-table__actions button { min-width: 92px; }
    .tp-play-lobby .tp-play-list-heading--compact { display: grid; grid-template-columns: 1fr; gap: 8px; padding: 10px; }
    .tp-play-lobby .tp-play-list-heading--compact label { margin: 0; }
    .tp-play-lobby-mode { width: 100%; }
    .tp-play-lobby-mode button { min-width: 0; padding-inline: 5px; white-space: normal; }
    .tp-play-lobby .tp-play-table-list { padding: 0 7px 8px; }
    .tp-play-lobby .tp-play-table-row,
    .tp-play-lobby .tp-play-table-card {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px 8px;
        padding: 8px;
    }
    .tp-play-lobby .tp-play-table-row .tp-play-table-card__host { grid-column: 1; grid-row: 1; }
    .tp-play-lobby .tp-play-table-row__facts { grid-column: 1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 4px 8px; }
    .tp-play-lobby .tp-play-table-row__facts > span { flex: 0 1 auto; padding: 2px 0; background: transparent; }
    .tp-play-lobby .tp-play-table-row__facts small { display: none; }
    .tp-play-lobby .tp-play-table-row__facts strong { margin: 0; font-size: .67rem; }
    .tp-play-lobby .tp-play-table-row__facts > span:not(:last-child) strong::after { content: ' ·'; color: var(--tp1-muted); }
    .tp-play-lobby .tp-play-table-row > button,
    .tp-play-lobby .tp-play-table-card button { grid-column: 2; grid-row: 1 / span 2; width: auto; min-width: 78px; align-self: stretch; }
}

@media (max-width: 350px) {
    .tp-play-lobby .tp-play-table-row > button { min-width: 70px; padding-inline: 8px; }
    .tp-play-list-heading__note { font-size: .66rem; }
}

@media (prefers-reduced-motion: reduce) {
    .tp-matchmaking-wait .searching-spinner { animation-duration: 1.8s; }
}

/* ==========================================================================
   Online lobby - dedicated /online page.

   Local compact scale: primary 42px, secondary 38px, icon 36px, tab 30px,
   input 38px, row 60px, radius 8-12px. Global design tokens are untouched;
   every size lives in these .tp-online__* classes.
   ========================================================================== */

#screen-online.tp-online {
    --on-line: var(--border-subtle, rgba(255, 255, 255, 0.09));
    --on-surface: var(--surface-1, #1E1810);
    --on-surface-2: var(--surface-2, #2A2218);
    --on-text: var(--text-primary, #F5EBD8);
    --on-muted: var(--text-secondary, #8A7860);
    --on-accent: var(--accent-gold, #D4A24C);
}

#screen-online .tp-online__page {
    width: min(1220px, 100%);
    margin-inline: auto;
    padding: 20px 22px 40px;
    display: grid;
    gap: 14px;
    align-content: start;
}

#screen-online .tp-online__sr {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    clip-path: inset(50%);
    overflow: hidden; white-space: nowrap;
}

/* Header */

#screen-online .tp-online__header {
    display: flex;
    align-items: center;
    gap: 12px;
}
#screen-online .tp-online__heading { flex: 1 1 auto; min-width: 0; }
#screen-online .tp-online__heading h1 {
    margin: 0;
    font: 700 20px/1.2 var(--font-display, inherit);
    color: var(--on-text);
}
#screen-online .tp-online__heading p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--on-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#screen-online .tp-online__count {
    font: 600 12px/1 var(--font-mono, inherit);
    color: var(--on-muted);
    white-space: nowrap;
}
#screen-online .tp-online__icon-button {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border: 1px solid var(--on-line);
    border-radius: 10px;
    background: transparent;
    color: var(--on-text);
    cursor: pointer;
}
#screen-online .tp-online__icon-button:hover { border-color: var(--on-accent); color: var(--on-accent); }
#screen-online .tp-online__icon-button[aria-busy="true"] { opacity: 0.6; cursor: progress; }

/* Quick match: one row, exactly one primary */

#screen-online .tp-online__quick {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 60px;
    padding: 10px 14px;
    border: 1px solid var(--on-line);
    border-radius: 12px;
    background: var(--on-surface);
}
#screen-online .tp-online__quick-label {
    font: 600 13px/1 var(--font-body, inherit);
    color: var(--on-text);
}
#screen-online .tp-online__presets { display: flex; gap: 6px; }
#screen-online .tp-online__preset {
    min-width: 56px; height: 38px;
    padding: 0 12px;
    border: 1px solid var(--on-line);
    border-radius: 9px;
    background: transparent;
    color: var(--on-muted);
    font: 600 13px/1 var(--font-mono, inherit);
    cursor: pointer;
}
#screen-online .tp-online__preset:hover { color: var(--on-text); }
#screen-online .tp-online__preset.is-active {
    background: var(--on-surface-2);
    border-color: var(--on-accent);
    color: var(--on-accent);
}
#screen-online .tp-online__quick-note {
    flex: 1 1 auto;
    font-size: 12px;
    color: var(--on-muted);
}
#screen-online .tp-online__primary {
    height: 42px;
    padding: 0 20px;
    border: 0;
    border-radius: 10px;
    background: var(--on-accent);
    color: #15100A;
    font: 700 14px/1 var(--font-body, inherit);
    cursor: pointer;
}
#screen-online .tp-online__primary:hover { filter: brightness(1.06); }
#screen-online .tp-online__primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

#screen-online .tp-online__secondary {
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--on-line);
    border-radius: 9px;
    background: var(--on-surface-2);
    color: var(--on-text);
    font: 600 13px/1 var(--font-body, inherit);
    cursor: pointer;
}
#screen-online .tp-online__secondary:hover { border-color: var(--on-accent); color: var(--on-accent); }
#screen-online .tp-online__tertiary {
    height: 34px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--on-muted);
    font: 600 13px/1 var(--font-body, inherit);
    cursor: pointer;
}
#screen-online .tp-online__tertiary:hover { color: var(--on-accent); }

/* Status and current table */

#screen-online .tp-online__status {
    padding: 8px 12px;
    border: 1px solid var(--on-line);
    border-radius: 9px;
    font-size: 13px;
    color: var(--on-muted);
}
#screen-online .tp-online__status[hidden] { display: none; }

#screen-online .tp-online__current {
    display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--on-line);
    border-radius: 10px;
    background: var(--on-surface);
}
#screen-online .tp-online__current[hidden] { display: none; }
#screen-online .tp-online__current-copy { flex: 1 1 auto; display: grid; }
#screen-online .tp-online__current-copy strong { font: 600 14px/1.2 var(--font-body, inherit); }
#screen-online .tp-online__current-copy small { font-size: 12px; color: var(--on-muted); }
#screen-online .tp-online__current-actions { display: flex; gap: 8px; }

/* Toolbar */

#screen-online .tp-online__toolbar {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
}
#screen-online .tp-online__tabs {
    display: flex; gap: 4px;
    padding: 3px;
    border: 1px solid var(--on-line);
    border-radius: 10px;
}
#screen-online .tp-online__tab {
    height: 30px;
    padding: 0 14px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--on-muted);
    font: 600 13px/1 var(--font-body, inherit);
    cursor: pointer;
}
#screen-online .tp-online__tab[aria-selected="true"] {
    background: var(--on-surface-2);
    color: var(--on-text);
}
#screen-online .tp-online__search {
    flex: 1 1 200px;
    min-width: 160px;
    display: flex; align-items: center; gap: 8px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--on-line);
    border-radius: 9px;
    color: var(--on-muted);
}
#screen-online .tp-online__search input {
    flex: 1 1 auto; min-width: 0;
    border: 0; background: transparent;
    color: var(--on-text);
    font: 400 13px/1 var(--font-body, inherit);
}
#screen-online .tp-online__search input:focus { outline: none; }
#screen-online .tp-online__note { margin: 0; font-size: 12px; color: var(--on-muted); }

/* List */

#screen-online .tp-online__list { display: grid; gap: 6px; }
#screen-online .tp-online__list[hidden] { display: none; }

#screen-online .tp-online__list-state {
    display: grid; place-items: center; align-content: center;
    gap: 4px;
    min-height: 96px; max-height: 120px;
    padding: 14px;
    border: 1px dashed var(--on-line);
    border-radius: 10px;
    text-align: center;
}
#screen-online .tp-online__list-state p { margin: 0; font-size: 13px; color: var(--on-muted); }
#screen-online .tp-online__list-state strong { font: 600 14px/1.2 var(--font-body, inherit); color: var(--on-text); }

/* Rows are produced by play-lobby.js; only their geometry is set here. */
#screen-online .tp-online__list > *:not(.tp-online__list-state) {
    display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
    min-height: 60px;
    padding: 10px 14px;
    border: 1px solid var(--on-line);
    border-radius: 10px;
    background: var(--on-surface);
    font-size: 13px;
}
#screen-online .tp-online__list button {
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--on-line);
    border-radius: 8px;
    background: transparent;
    color: var(--on-text);
    font: 600 13px/1 var(--font-body, inherit);
    cursor: pointer;
}
#screen-online .tp-online__list button:hover:not(:disabled) { border-color: var(--on-accent); color: var(--on-accent); }
#screen-online .tp-online__list button:disabled { opacity: 0.45; cursor: not-allowed; }

/* Drawer */

#screen-online .tp-online-drawer .tp-online-drawer__panel {
    width: min(400px, 100%);
    max-height: 88dvh;
    overflow-y: auto;
    border-radius: 12px;
}
#screen-online .tp-online-drawer__form { display: grid; gap: 8px; padding: 0 2px 4px; }
#screen-online .tp-online-drawer__form label { font: 500 12px/1.2 var(--font-body, inherit); color: var(--on-muted); }
#screen-online .tp-online-drawer__form select,
#screen-online .tp-online-drawer__form input[type="number"] {
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--on-line);
    border-radius: 9px;
    background: var(--product-bg, #15100A);
    color: var(--on-text);
    font: 400 13px/1 var(--font-body, inherit);
}
#screen-online .tp-online-drawer__check {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--on-text);
}
#screen-online .tp-online-drawer__actions { display: flex; gap: 8px; margin-top: 6px; }

#screen-online :focus-visible { outline: 2px solid var(--on-accent); outline-offset: 2px; }

/* Responsive */

@media (max-width: 900px) {
    #screen-online .tp-online__page { padding: 16px 16px 32px; }
    #screen-online .tp-online__quick-note { flex-basis: 100%; order: 5; }
}

@media (max-width: 640px) {
    #screen-online .tp-online__page { padding: 14px 12px 28px; gap: 12px; }
    #screen-online .tp-online__heading h1 { font-size: 18px; }
    #screen-online .tp-online__heading p { display: none; }
    /* Presets become 2x2 and the primary goes full width, capped at 46px. */
    #screen-online .tp-online__presets {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
    }
    #screen-online .tp-online__preset { min-width: 0; width: 100%; }
    #screen-online .tp-online__primary { width: 100%; height: 46px; }
    #screen-online .tp-online__quick { min-height: 0; }
    #screen-online .tp-online__toolbar { gap: 6px; }
    #screen-online .tp-online__tabs { width: 100%; }
    #screen-online .tp-online__tab { flex: 1 1 0; padding: 0 8px; }
    #screen-online .tp-online__search { flex-basis: 100%; }
    #screen-online .tp-online__secondary,
    #screen-online .tp-online__tertiary { flex: 1 1 0; }
    /* A row becomes a compact content-height card. */
    #screen-online .tp-online__list > *:not(.tp-online__list-state) {
        min-height: 0;
        padding: 10px 12px;
    }
}

/* Simple lobby: one create action plus two lists.
   Desktop shows the tab pair, mobile shows a single toggle button. */

#screen-online .tp-online__mobile-toggle { display: none; }

#screen-online .tp-online__toolbar { gap: 10px; }

@media (max-width: 640px) {
    /* Exactly two primary buttons in one row: create and the list toggle. */
    #screen-online .tp-online__tabs { display: none; }
    #screen-online .tp-online__mobile-toggle {
        display: block;
        flex: 1 1 0;
        min-width: 0;
        height: 44px;
        padding: 0 12px;
        border: 1px solid var(--on-line);
        border-radius: 10px;
        background: var(--on-surface-2);
        color: var(--on-text);
        font: 600 13px/1 var(--font-body, inherit);
        cursor: pointer;
    }
    #screen-online .tp-online__primary { flex: 1 1 0; width: auto; height: 44px; }
    #screen-online .tp-online__toolbar { flex-wrap: nowrap; }
}

@media (max-width: 340px) {
    /* At 320px the two buttons stack rather than shrink below a usable size. */
    #screen-online .tp-online__toolbar { flex-wrap: wrap; }
    #screen-online .tp-online__primary,
    #screen-online .tp-online__mobile-toggle { flex-basis: 100%; }
}

/* ── Local AI game recovery state ─────────────────────────────────────────────
   Shown when a stored AI-game snapshot fails validation. It replaces the board
   inside the game screen rather than redirecting to Home, so the URL and the
   visible screen stay in agreement and the snapshot is not discarded until the
   player chooses.
   ─────────────────────────────────────────────────────────────────────────── */
.tp-game-recovery {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--surface-canvas, #15100A);
}
.tp-game-recovery[hidden] { display: none; }

.tp-game-recovery__panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    max-width: 420px;
    padding: 28px 24px;
    border: 1px solid var(--on-line, rgba(255, 255, 255, 0.12));
    border-radius: 16px;
    background: var(--on-surface-1, rgba(255, 255, 255, 0.04));
    text-align: center;
}

.tp-game-recovery__panel > i {
    font-size: 26px;
    color: var(--accent-primary, #C9A227);
}

.tp-game-recovery__panel h2 { margin: 0; font-size: 19px; line-height: 1.3; }
.tp-game-recovery__panel p { margin: 0; color: var(--on-text-2, rgba(255, 255, 255, 0.68)); font-size: 14px; line-height: 1.5; }

.tp-game-recovery__reason:empty { display: none; }
.tp-game-recovery__reason {
    font: 500 12px/1.4 var(--font-mono, monospace);
    color: var(--on-text-3, rgba(255, 255, 255, 0.46));
}

.tp-game-recovery__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-top: 8px;
}
.tp-game-recovery__actions .tp-button { width: 100%; }

/* ── Not Found route ──────────────────────────────────────────────────────────
   A real screen for an unrecognised location. The router keeps the URL, so the
   panel can show exactly what was opened.
   ─────────────────────────────────────────────────────────────────────────── */
.tp-not-found__shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.tp-not-found__panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    max-width: 520px;
    padding: 28px 24px;
    border: 1px solid var(--on-line, rgba(255, 255, 255, 0.12));
    border-radius: 16px;
    background: var(--on-surface-1, rgba(255, 255, 255, 0.04));
}

.tp-not-found__panel h1 { margin: 0; font-size: 24px; line-height: 1.25; }
.tp-not-found__panel p { margin: 0; color: var(--on-text-2, rgba(255, 255, 255, 0.68)); line-height: 1.55; }

.tp-not-found__path code {
    display: inline-block;
    max-width: 100%;
    overflow-wrap: anywhere;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--on-surface-2, rgba(255, 255, 255, 0.06));
    font: 500 13px/1.4 var(--font-mono, monospace);
    color: var(--on-text-3, rgba(255, 255, 255, 0.56));
}

.tp-not-found__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Guest state inside the Online lobby. The page renders normally; the actions
   that genuinely need a server identity are disabled beside this notice. */
.tp-online__guest {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin: 12px 0;
    padding: 14px 16px;
    border: 1px solid var(--on-line, rgba(255, 255, 255, 0.12));
    border-radius: 14px;
    background: var(--on-surface-1, rgba(255, 255, 255, 0.04));
}
.tp-online__guest[hidden] { display: none; }
.tp-online__guest > i { font-size: 20px; color: var(--accent-primary, #C9A227); }
.tp-online__guest strong { display: block; margin-bottom: 2px; font-size: 15px; }
.tp-online__guest p { margin: 0; color: var(--on-text-2, rgba(255, 255, 255, 0.68)); font-size: 13px; line-height: 1.45; }
.tp-online__guest > div { flex: 1 1 200px; min-width: 0; }
.tp-online__refresh-row { display: flex; justify-content: flex-end; }

/* Explicit Back on screens that resolve to no bottom-navigation item.
   44x44 is the minimum comfortable touch target. */
.tp-page-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    margin-inline-end: 4px;
    border: 1px solid var(--on-line, rgba(255, 255, 255, 0.12));
    border-radius: 12px;
    background: var(--on-surface-1, rgba(255, 255, 255, 0.04));
    color: inherit;
    font-size: 16px;
    cursor: pointer;
}
.tp-page-back:focus-visible { outline: 2px solid var(--accent-primary, #C9A227); outline-offset: 2px; }
.tp-page-heading--action { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }

/* ── Page header with an explicit Back ────────────────────────────────────────
   `.tp-page-heading--action` is a grid, which placed the Back control in the
   first column and threw the title to the far right of the row — on a 1440px
   desktop the arrow sat at x=105 and "Турниры" at x=834, reading as two
   unrelated elements. A header that owns a Back is laid out as one row:
   Back and title together on the left, page actions on the right.
   ─────────────────────────────────────────────────────────────────────────── */
.tp-product-page .tp-page-heading--action:has(.tp-page-back) {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.tp-product-page .tp-page-heading--action:has(.tp-page-back) .tp-page-heading__copy {
    flex: 1 1 260px;
    min-width: 0;
}

/* 46px is a hero size; beside a 44px control it dwarfed everything. */
.tp-product-page .tp-page-heading--action:has(.tp-page-back) .tp-page-heading__copy h1 {
    margin: 0;
    font-size: clamp(20px, 2.2vw, 28px);
    line-height: 1.2;
}

.tp-product-page .tp-page-heading--action:has(.tp-page-back) .tp-page-heading__copy p {
    margin: 2px 0 0;
    font-size: 13px;
    line-height: 1.4;
}

.tp-product-page .tp-page-heading--action:has(.tp-page-back) .tp-page-heading__actions {
    flex: 0 0 auto;
    margin-inline-start: auto;
    display: flex;
    gap: 8px;
}

@media (max-width: 720px) {
    .tp-product-page .tp-page-heading--action:has(.tp-page-back) .tp-page-heading__actions {
        flex: 1 1 100%;
        margin-inline-start: 0;
    }
}
