: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 */
    --grid: #1a1a2e;    /* board lines */
    --accent: #0b57d0;  /* O mark; >=4.5:1 on white */
}

* {
    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;
}

.exit {
    padding: 12px;
    font-size: 13px;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.15s ease;
}

.exit:hover {
    color: var(--ink);
}

.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;
}

/* The board: a 3×3 grid drawn with only the two inner horizontal and two
   inner vertical lines — no outer border. Right border on every cell that
   isn't in the last column, bottom border on every cell not in the last row. */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: min(78vw, 340px);
    aspect-ratio: 1;
    margin: 0 auto;
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    background: none;
    border: 0;
    padding: 0;
    line-height: 1;
    font-size: clamp(44px, 17vw, 92px);
    font-weight: 800;
    color: var(--ink);
    cursor: pointer;
}

.cell:not(:nth-child(3n)) { border-right: 4px solid var(--grid); }
.cell:nth-child(-n + 6)   { border-bottom: 4px solid var(--grid); }

.cell.mark-o { color: var(--accent); }

.cell:disabled { cursor: default; }

/* Only real pointers hover; on touch :hover sticks after a tap. */
@media (hover: hover) {
    .cell:not(:disabled):hover {
        background: var(--wash);
    }
}

.cell.win {
    background: var(--wash-hover);
}

.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 these controls are shown (no shift when a friend joins) —
   they float a bit below the status line instead. One positioned wrapper for
   .links/.again/.exit means they stack in a column instead of ever
   overlapping, however many of the three happen to be visible at once. */
.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: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.cell, .pill {
    -webkit-tap-highlight-color: transparent;
}

.pill {
    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;
}

/* Fixed widths so the row's geometry is identical in every state:
   [ code + copy/check icon ]  ⇄  [ code input ]. #join keeps one label
   in both states, so it just sizes to its own content. */
#invite, #join-code {
    width: 170px;
}

#join-code {
    text-align: center;
    cursor: text;
    background: var(--paper);
}

.hidden {
    display: none !important;
}

@media (max-width: 399px) {
    .links {
        flex-direction: column;
    }
}

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

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

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

/* WCAG 2.3.3: honour a reduced-motion preference. The picked/hover lift is
   a scale transform; drop the animation but keep the state legible. */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
    .hand:hover:not(:disabled),
    .hand.picked {
        transform: none;
    }
    .hand.picked {
        outline: 3px solid var(--focus);
        outline-offset: 4px;
        border-radius: 12px;
    }
}
