/* Theme tokens. Everything else uses these; the peg colors come from PegPalette. */
:root {
    color-scheme: light dark;
    --bg: #F4F5F9;
    --surface: #FFFFFF;
    --text: #1F2433;
    --muted: #5A6175;
    --accent: #3B4CCA;
    --accent-ink: #FFFFFF;
    --peg-ring: #1F2433;
    --border: #D5D8E3;
    --danger: #B3261E;
    --danger-ink: #FFFFFF;
    --ok: #1B7F3B;
    --warn-bg: #FFF1D6;
    --warn-ink: #5C3B00;
    --info-bg: #E4E8FF;
    --info-ink: #1F2433;
    --shadow: 0 1px 3px rgba(20, 24, 40, 0.12);
    --backdrop: rgba(10, 12, 20, 0.55);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11151F;
        --surface: #1B2130;
        --text: #E8EAF2;
        --muted: #A7AEC2;
        --accent: #9AA8FF;
        --accent-ink: #11151F;
        --peg-ring: #E8EAF2;
        --border: #343C52;
        --danger: #FFB4AB;
        --danger-ink: #11151F;
        --ok: #7DDB9A;
        --warn-bg: #4A3A12;
        --warn-ink: #FFE7B0;
        --info-bg: #26305C;
        --info-ink: #E8EAF2;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
        --backdrop: rgba(0, 0, 0, 0.7);
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 100%;
    line-height: 1.4;
}

body {
    overflow-x: hidden;
    overflow-wrap: anywhere;
}

.loading {
    padding: 16px;
}

/* The safe-area insets keep content clear of notches and the home indicator (viewport-fit=cover). */
main.app {
    --pad: 16px;
    max-width: 1100px;
    margin: 0 auto;
    padding:
        max(var(--pad), env(safe-area-inset-top))
        max(var(--pad), env(safe-area-inset-right))
        max(var(--pad), env(safe-area-inset-bottom))
        max(var(--pad), env(safe-area-inset-left));
}

.page {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

h1, h2, h3, h4 {
    margin: 0;
    line-height: 1.2;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; font-weight: 600; }

p { margin: 0; }

.title { text-align: center; padding-top: 8px; }
.tagline { text-align: center; color: var(--muted); }
.muted { color: var(--muted); }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.card-primary {
    border-color: var(--accent);
}

/* Forms and buttons */
label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-weight: 600;
}

label.check {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    font-weight: 400;
}

input[type="checkbox"] {
    width: 24px;
    height: 24px;
    accent-color: var(--accent);
}

input[type="text"],
select {
    font: inherit;
    font-size: 1rem;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    width: 100%;
}

.code-field {
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    text-transform: uppercase;
    letter-spacing: 0.3em;
    text-align: center;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn,
.peg,
.opponent-strip {
    touch-action: manipulation;
}

.btn {
    font: inherit;
    font-weight: 600;
    min-height: 44px;
    min-width: 44px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--danger-ink);
}

.btn-quiet {
    background: transparent;
    color: var(--muted);
    font-weight: 500;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.button-row .btn {
    flex: 1 1 auto;
}

.quiet-row,
.leave-row {
    display: flex;
    justify-content: center;
}

.error {
    color: var(--danger);
    font-weight: 600;
}

.notice {
    background: var(--info-bg);
    color: var(--info-ink);
    border-radius: 8px;
    padding: 8px 12px;
}

.banner {
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-weight: 600;
}

.banner-warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner-info { background: var(--info-bg); color: var(--info-ink); }

/* Game header */
.game-header {
    gap: 8px;
}

.header-line {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-weight: 600;
}

.header-timer {
    font-variant-numeric: tabular-nums;
}

.tally {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    font-size: 1.1rem;
}

.tally span {
    overflow-wrap: anywhere;
}

.presence {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: none;
}

.dot-on { background: var(--ok); }
.dot-off { border: 2px solid var(--muted); }

.game-code {
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    text-align: center;
    padding-left: 0.25em;
}

/* Pegs */
.peg {
    --size: 44px;
    flex: none;
    width: var(--size);
    height: var(--size);
    padding: 0;
    border-radius: 50%;
    border: 2px solid var(--peg-ring);
    background: var(--peg-fill, transparent);
    color: var(--peg-ink, var(--text));
    font: inherit;
    font-weight: 700;
    font-size: calc(var(--size) * 0.45);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.peg-lg { --size: 44px; }
.peg-sm { --size: 28px; }

button.peg { cursor: pointer; }
button.peg:disabled { opacity: 0.35; cursor: not-allowed; }

.peg-empty {
    border-style: dashed;
    background: transparent;
}

.peg-selected {
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--accent);
}

.code-input {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.slots,
.picker {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 214px;
}

.slots {
    max-width: 100%;
    padding: 6px;
}

.code-row {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
}

/* Boards */
.board {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.guess-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.guess-number {
    width: 1.6em;
    text-align: right;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.board-empty {
    color: var(--muted);
}

.feedback {
    margin-left: auto;
    display: inline-grid;
    grid-template-columns: repeat(3, 12px);
    gap: 3px;
    min-width: 48px;
}

.fb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--text);
}

.fb-exact { background: var(--text); }
.fb-partial { background: transparent; }

.own-secret {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.opponent-strip {
    font: inherit;
    color: var(--text);
    cursor: pointer;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    gap: 4px 12px;
    min-height: 44px;
    padding: 8px 16px;
}

.strip-name { font-weight: 700; overflow-wrap: anywhere; }
.strip-action { color: var(--accent); font-weight: 600; }

.guessing {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.boards {
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr);
}

.guessing[data-view="own"] .board-opponent { display: none; }
.guessing[data-view="opponent"] .board-own { display: none; }

.guess-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Phones: the guessing screen fills the viewport. Header, strip and action card keep their size,
   only the boards scroll, so the newest guess and the opponent strip are always on screen.
   On short viewports the boards keep a 120px minimum and the page scrolls instead.
   Landscape phones 768px wide or more (short and wide) use the same layout, boards side by side. */
@media (max-width: 767px), (min-width: 768px) and (max-height: 500px) {
    .page.game-guessing > * { flex: none; }

    .page.game-guessing > .guessing {
        flex: 1 1 0;
    }

    .guessing > * { flex: none; }

    .guessing > .boards {
        flex: 1 1 0;
        min-height: 120px;
        overflow-y: auto;
    }

    .guessing .picker { max-width: none; gap: 6px; }
}

/* Part C: with 7 or 8 colors the picker wraps in rows of 4, as in Setup. Up to 6 colors the wide
   picker keeps one row, which saves height. Landscape keeps one row of 8 (boards are at their minimum). */
@media (max-width: 767px) and (orientation: portrait) {
    .guessing .picker:has(> :nth-child(7)) { max-width: 214px; }
}

@media (max-width: 767px) {
    .page.game-guessing {
        min-height: calc(100vh - 2 * var(--pad));
        min-height: calc(100dvh - 2 * var(--pad) - max(0px, env(safe-area-inset-top) - var(--pad)) - max(0px, env(safe-area-inset-bottom) - var(--pad)));
    }

    .guessing[data-view="opponent"] .guess-controls { display: none; }
}

@media (min-width: 768px) and (max-height: 500px) {
    .page.game-guessing {
        min-height: calc(100vh - 2 * var(--pad));
        min-height: calc(100dvh - 2 * var(--pad) - max(0px, env(safe-area-inset-top) - var(--pad)) - max(0px, env(safe-area-inset-bottom) - var(--pad)));
    }
}

.claim-win {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.round-over {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result { text-align: center; }
.result h2 { font-size: 1.75rem; }

.reveal {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.reveal li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.reveal li span:first-child { overflow-wrap: anywhere; }

.boards-final { grid-template-columns: minmax(0, 1fr); }

/* Dialog */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 20;
}

.dialog {
    width: 100%;
    max-width: 400px;
}

/* Wide screens: both boards side by side, opponent strip hidden. */
@media (min-width: 768px) {
    main.app { --pad: 24px; }

    .opponent-strip { display: none; }

    .guessing .boards { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .guessing[data-view] .board-col { display: flex; }

    .boards-final { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

    .page { max-width: 1100px; }
    .home { max-width: 520px; margin: 0 auto; }
}

/* Blazor shows this element when an unhandled exception occurs. */
#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    background: var(--warn-bg);
    color: var(--warn-ink);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    z-index: 50;
    font-weight: 600;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    border-top: 2px solid var(--warn-ink);
}

#blazor-error-ui[style*="block"] {
    display: flex !important;
}

#blazor-error-ui .reload {
    color: inherit;
    text-decoration: underline;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

#blazor-error-ui .dismiss {
    margin-left: auto;
    min-height: 44px;
    min-width: 44px;
    padding: 8px 16px;
    font: inherit;
    font-weight: 600;
    color: inherit;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
}

.connection-banner {
    justify-content: flex-start;
}

.resume {
    align-items: center;
    text-align: center;
    padding-top: 15vh;
}

.resume .btn {
    margin-top: 12px;
}

/* No motion for people who ask for none: no animation, instant scrolling, no transitions. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

@media (max-width: 767px) {
    .card { padding: 12px; }
    .slots { gap: 6px; padding: 4px 0; }
}
