/* game-core core.css — shared game-shell styles for the DOM the package
   drives (connect bar, below-game controls) and the scaffold both games use
   verbatim (score, status line, a11y primitives). Synced into lib/ and linked
   BEFORE the game stylesheet, so a game can override anything.

   Contract: the tokens used here — --ink --paper --line --wash --wash-hover
   --muted --focus — are defined below with defaults; a game MAY override any
   of them in its own :root (the game stylesheet is linked after this file).
   Board styles and board breakpoints stay game-owned. */

:root {
    --ink: #1a1a2e;
    --paper: #ffffff;
    /* WCAG 1.4.11: control borders must be >=3:1 vs the white background,
       so this is darker than a typical hairline. */
    --line: rgba(0, 0, 0, 0.45);
    --wash: rgba(0, 0, 0, 0.04);
    --wash-hover: rgba(0, 0, 0, 0.09);
    --muted: #5f5f6b;   /* >=4.5:1 on white for secondary text (Exit) */
    --focus: #0b57d0;   /* visible focus ring */
}

* {
    box-sizing: border-box;
}

/* Visually hidden but available to assistive tech. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* WCAG 2.4.7: a clear, consistent focus indicator on every control. */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
    border-radius: 6px;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--paper);
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
}

main {
    width: 100%;
    max-width: 860px;
    padding: 24px;
    position: relative;
}

.score {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-bottom: 24px;
}

.score-nums {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    font-size: 50px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

#score-player {
    text-align: right;
}

#score-opponent {
    text-align: left;
}

.score-colon {
    padding: 0 0.2em;
}

.play {
    margin: 28px 0 0;
    font-size: 20px;
    min-height: 30px;
}

/* Out of the layout flow so the centered game block sits in the same place
   whether or not the Play again button shows (no shift when a friend joins) —
   it floats a bit below the status line instead. */
.below-game {
    position: absolute;
    top: calc(100% + 24px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.links {
    display: grid;
    grid-template-columns: 34px auto 34px;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.pill {
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 42px;
    max-width: calc(100vw - 32px);
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--wash);
    color: var(--ink);
    font-size: 15px;
    padding: 0 20px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.icon {
    width: 16px;
    height: 16px;
    flex: none;
}

.icon-check {
    color: #1a9e5c;
}

button.pill:hover:not(:disabled) {
    background: var(--wash-hover);
}

.pill:disabled {
    cursor: default;
    opacity: 0.55;
}

.connect-icon-button,
.icon-button {
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
}

.connect-icon-button {
    width: 34px;
    height: 34px;
    padding: 0;
}

.connect-code-slot {
    position: relative;
    display: grid;
    justify-items: center;
    align-items: center;
    /* Reserve the code's width at all times (empty, loading, or filled) so
       the copy button never shifts — including the ~1s before the room code
       arrives, where the skeleton below fills the gap. */
    width: 6ch;
    height: 34px;
    overflow: hidden;
    color: var(--ink);
    /* 16px matches the input (and keeps iOS Safari from zooming on focus);
       tabular digits make the code exactly roomIdLen ch wide. */
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

/* Shimmer placeholder shown while we wait for the room code from the server.
   It sits behind the slot and drops out the moment a code lands or the join
   input opens (:has keeps it purely declarative — no extra JS). */
.code-skeleton {
    position: absolute;
    inset: 9px 1px;
    border-radius: 999px;
    background: var(--wash-hover);
    animation: code-skeleton 1.1s ease-in-out infinite;
}

.connect-code-slot:has(#invite-code:not(:empty)) .code-skeleton,
.connect-code-slot:has(#join-code:not(.hidden)) .code-skeleton {
    display: none;
}

@keyframes code-skeleton {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
    .code-skeleton { animation: none; }
}

#invite-code,
#join-code {
    grid-area: 1 / 1;
}

/* The input is sized to the same 6 digits the code shows, so switching
   between the code and the input never changes the slot's width — the copy
   button stays put. */
#join-code {
    width: 6ch;
    height: 34px;
    /* No padding: with border-box the 6ch is the whole box, so a UA default
       left/right padding would shrink the text area and clip the code. */
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: center;
    cursor: text;
}

.hidden {
    display: none !important;
}

.top-controls {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 10;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.top-controls .icon-button {
    width: 34px;
    height: 34px;
    padding: 0;
}

.game-switcher {
    position: relative;
}

.game-switcher-toggle {
    font-size: 22px;
    line-height: 1;
}

.lang-toggle img {
    display: block;
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.game-switcher-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    display: grid;
    grid-template-columns: repeat(3, 46px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
    text-align: left;
}

.game-switcher-menu a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 42px;
    color: var(--ink);
    font-size: 19px;
    line-height: 1.2;
    text-decoration: none;
}

.game-menu-image {
    width: 27px;
    height: 27px;
    object-fit: contain;
}

.game-switcher-menu a:hover {
    background: var(--wash-hover);
}

@media (min-width: 576px) {
    .score-nums { font-size: 60px; }
}

@media (min-width: 768px) {
    .score { margin-bottom: 30px; }
    .score-nums { font-size: 70px; }
    .play { margin-top: 30px; font-size: 24px; }
}

@media (min-width: 992px) {
    .score { margin-bottom: 40px; }
    .score-nums { font-size: 90px; }
    .play { margin-top: 40px; }
}

@media (min-width: 1200px) {
    .score { margin-bottom: 45px; }
    .score-nums { font-size: 100px; }
    .play { margin-top: 45px; }
}

/* WCAG 2.3.3: honour a reduced-motion preference. Games add their own rules
   for board-specific animated states. */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}
