* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

body {
    background-color: #12100E;
    color: #FFFFFF;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    max-height: 900px;
    background-color: #1E1B18;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Responsive breakpoints: the board is JS-sized to fit the container, so
   widening .app-container on larger viewports lets the board grow instead of
   sitting in a fixed 480px column. (Mobile/narrow stays at 480px.) */
@media (min-width: 600px)  { .app-container { max-width: 540px; } }
@media (min-width: 768px)  { .app-container { max-width: 680px; } }
@media (min-width: 1024px) {
    .app-container { max-width: 880px; max-height: none; }
}
@media (min-width: 1440px) { .app-container { max-width: 1040px; } }

.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: 20px;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* Anchor for the absolutely-positioned celebration overlay. */
#game-screen {
    position: relative;
}

/* Single <main> landmark wraps both screens (a11y: content in landmarks). */
.app-container > main {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
}

.app-container > main > .screen {
    height: 100%;
}

/* Logo */
.logo-area {
    text-align: center;
    margin: 20px 0 30px;
}

.logo-area h1 {
    color: #FFD54F;
    font-size: 34px;
    font-weight: 800;
    letter-spacing: 2px;
}

.tagline {
    color: #A1887F;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
}

/* Configuration Cards */
.card-section {
    background-color: #2C241E;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

.card-section h2 {
    color: #FFB74D;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 12px;
}

.chip-group {
    display: flex;
    gap: 10px;
}

.chip {
    flex: 1;
    background: #1E1B18;
    border: 1px solid #4E342E;
    border-radius: 12px;
    padding: 12px 6px;
    color: #D7CCC8;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.2s ease;
}

.chip.active {
    background: #5D4037;
    border: 2px solid #FFD54F;
    color: #FFFFFF;
}

.chip-title {
    font-size: 13px;
    font-weight: 700;
}

.chip-sub {
    font-size: 10px;
    color: #BCAFA1;
}

.chip.active .chip-sub {
    color: #FFD54F;
}

/* Buttons */
.btn-primary {
    background: #2E7D32;
    color: #FFF;
    border: none;
    border-radius: 14px;
    padding: 16px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.4);

}

.btn-secondary {
    background: transparent;
    border: 1px solid #FFB74D;
    color: #FFB74D;
    border-radius: 14px;
    padding: 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 10px;
}

/* ---- Online lobby (auth + room create/join) ---- */
.online-chip-row {
    display: flex;
    gap: 10px;
    margin-bottom: 4px;
}
.online-join-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}
.online-join-row .online-input {
    flex: 1;
}
.online-input {
    background: #1E1B18;
    border: 1px solid #4E342E;
    border-radius: 12px;
    padding: 12px;
    color: #FFFFFF;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    outline: none;
}
.online-input::placeholder {
    color: #8D6E63;
    font-weight: 400;
    letter-spacing: 0.5px;
}
.online-input:focus {
    border-color: #FFD54F;
}
.online-status {
    font-size: 13px;
    font-weight: 700;
    color: #76FF03;
    margin-top: 10px;
    min-height: 16px;
}
.online-status.error {
    color: #FF8A65;
}
.online-wait-text {
    font-size: 14px;
    font-weight: 700;
    color: #FFD54F;
    margin-top: 10px;
}
.online-code-display {
    font-size: 14px;
    font-weight: 700;
    color: #D7CCC8;
    margin-top: 6px;
}
.online-code-display b {
    color: #FFD54F;
    font-size: 20px;
    letter-spacing: 3px;
}
body.senior-mode .online-input      { font-size: 17px; padding: 14px; }
body.senior-mode .online-status     { font-size: 16px; }
body.senior-mode .online-wait-text  { font-size: 17px; }
body.senior-mode .online-code-display { font-size: 16px; }

.btn-sm {
    background: #2C241E;
    border: 1px solid #FFB74D;
    color: #FFB74D;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.btn-restart {
    background: #5D4037;
    color: #FFF;
    border: none;
}

/* Header & Banner */
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.header-bar h1 {
    color: #FFD54F;
    font-size: 16px;
    font-weight: 700;
}

.turn-banner {
    background: #E53935;
    border-radius: 12px;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 800;
    margin-bottom: 8px;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
}

.badge.locked {
    background: rgba(0,0,0,0.3);
    color: #FFD54F;
}

.badge.unlocked {
    background: rgba(0,0,0,0.3);
    color: #76FF03;
}

.game-log {
    color: #D7CCC8;
    font-size: 12px;
    text-align: center;
    min-height: 20px;
    margin-bottom: 8px;
}

/* Board zone: the mat on the left, big roll readout on its right side. */
.board-zone {
    display: flex;
    gap: 12px;
    align-items: stretch;
    width: 100%;
    margin-bottom: 12px;
}

.board-zone > .board-wrapper {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    margin-bottom: 0;
}

.roll-side {
    flex: 0 0 120px;
    background: #2C241E;
    border: 2px solid #5D4037;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    text-align: center;
}

.roll-side-label {
    color: #FFD54F;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}

.roll-side-number {
    font-size: 64px;
    font-weight: 800;
    line-height: 1;
    color: #D7CCC8;
}

.roll-side-number.is-extra {
    text-shadow: 0 0 12px currentColor;
}

.roll-side-name {
    font-size: 12px;
    font-weight: 700;
    color: #D7CCC8;
}

/* Narrow screens: the readout drops below the mat instead of crowding it. */
@media (max-width: 560px) {
    .board-zone {
        flex-direction: column;
    }
    .board-zone > .board-wrapper {
        /* Column mode: opt out of the row's flex sizing (flex-basis: 0
           collapses the JS-set height to zero); plain block sizing wins. */
        flex: none;
        width: 100%;
    }
    .roll-side {
        flex: none;
        flex-direction: row;
        gap: 10px;
        padding: 8px 12px;
    }
    .roll-side-number {
        font-size: 40px;
    }
}
.board-wrapper {
    width: 100%;
    aspect-ratio: 1;
    flex: 0 0 auto;          /* never let the flex column squash it non-square */
    background: #12100E;
    border-radius: 12px;
    border: 3px solid #5D4037;
    overflow: hidden;
    margin-bottom: 12px;
}

#board-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: manipulation; /* snappier taps, no double-tap zoom delay */
}

/* Keyboard play: the canvas is focusable (tabindex=0); make focus visible. */
#board-canvas:focus-visible {
    outline: 3px solid #FFD54F;
    outline-offset: 2px;
}

/* Cowry Section */
.cowry-container {
    background: #2C241E;
    border-radius: 16px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cowry-title {
    color: #FFD54F;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}

.cowry-shells {
    display: flex;
    gap: 12px;
    margin: 10px 0;
}

.shell {
    width: 44px;
    height: 52px;
    border-radius: 24px;
    position: relative;
    transition: transform 0.3s ease;
}

.shell.open {
    background: #FFF8E1;
    border: 2px solid #8D6E63;
}

.shell.open::after {
    content: '';
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 70%;
    background: #4E342E;
    border-radius: 2px;
}

.shell.closed {
    background: #8D6E63;
    border: 2px solid #3E2723;
}

.shell.closed::after {
    content: '';
    position: absolute;
    top: 30%;
    left: 20%;
    width: 60%;
    height: 40%;
    border-top: 3px solid #A1887F;
    border-radius: 50%;
}

.btn-roll {
    width: 80%;
    background: #FF8F00;
    color: #FFF;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
}

.btn-roll:disabled {
    background: #5D4037;
    color: #8D6E63;
    cursor: not-allowed;
}

.roll-score-display {
    color: #76FF03;
    font-weight: 800;
    margin-top: 6px;
    font-size: 14px;
}

/* US-06: visual highlight when the roll grants an extra roll (Chowka/Baara). */
.roll-score-display.is-extra {
    color: #FFD54F;
    text-shadow: 0 0 10px rgba(255, 213, 79, 0.7);
    animation: rollGlow 0.9s ease-out 2;
}

@keyframes rollGlow {
    0%   { box-shadow: 0 0 0 0 rgba(255, 213, 79, 0.55); }
    100% { box-shadow: 0 0 0 10px rgba(255, 213, 79, 0); }
}

/* ============================================================
   CELEBRATION OVERLAY (big-event animations)
   ------------------------------------------------------------
   A full-screen, tap-transparent layer inside #game-screen. The JS
   celebrate() helper swaps the per-event class; each class runs its
   own short keyframe set, then the helper hides the layer again.
   ============================================================ */
.celebration-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}

.celebration-emoji {
    font-size: 72px;
    line-height: 1;
}

.celebration-text {
    font-size: 22px;
    font-weight: 800;
    color: #FFFFFF;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    text-align: center;
    padding: 0 24px;
}

/* Capture: red burst pop + one quick shake. */
.celebration-overlay.celebrate-capture .celebration-emoji {
    animation: celebratePop 0.9s ease-out 1;
}
.celebration-overlay.celebrate-capture .celebration-text {
    color: #FF8A80;
    animation: celebratePop 0.9s ease-out 1;
}
.celebration-overlay.celebrate-capture ~ .board-zone {
    animation: celebrateShake 0.45s ease-out 1;
}

@keyframes celebratePop {
    0%   { transform: scale(0.3); opacity: 0; }
    35%  { transform: scale(1.25); opacity: 1; }
    70%  { transform: scale(1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes celebrateShake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-7px); }
    50%      { transform: translateX(6px); }
    75%      { transform: translateX(-3px); }
}

/* Gatti: gold shimmer pulse. */
.celebration-overlay.celebrate-gatti .celebration-emoji,
.celebration-overlay.celebrate-gatti .celebration-text {
    animation: celebrateShimmer 1.1s ease-in-out 1;
}
.celebration-overlay.celebrate-gatti .celebration-text {
    color: #FFD54F;
}

@keyframes celebrateShimmer {
    0%   { transform: scale(0.7); opacity: 0; text-shadow: none; }
    40%  { transform: scale(1.1); opacity: 1; text-shadow: 0 0 18px rgba(255, 213, 79, 0.9); }
    100% { transform: scale(1); opacity: 1; text-shadow: 0 0 6px rgba(255, 213, 79, 0.5); }
}

/* Extra roll: glow pulse echoing the rollGlow cue. */
.celebration-overlay.celebrate-extra .celebration-emoji,
.celebration-overlay.celebrate-extra .celebration-text {
    animation: celebrateExtraGlow 1s ease-out 1;
}
.celebration-overlay.celebrate-extra .celebration-text {
    color: #FFD54F;
}

@keyframes celebrateExtraGlow {
    0%   { transform: scale(0.6); opacity: 0; }
    40%  { transform: scale(1.15); opacity: 1; text-shadow: 0 0 16px rgba(255, 213, 79, 0.9); }
    100% { transform: scale(1); opacity: 1; }
}

/* Home arrival: small sparkle pop. */
.celebration-overlay.celebrate-home .celebration-emoji,
.celebration-overlay.celebrate-home .celebration-text {
    animation: celebrateHomePop 1.1s ease-out 1;
}
.celebration-overlay.celebrate-home .celebration-text {
    color: #A5D6A7;
}

@keyframes celebrateHomePop {
    0%   { transform: scale(0.4) rotate(-8deg); opacity: 0; }
    40%  { transform: scale(1.2) rotate(4deg); opacity: 1; }
    70%  { transform: scale(1) rotate(0deg); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Victory: confetti emoji rain + rising banner. */
.celebration-overlay.celebrate-victory .celebration-emoji {
    animation: celebrateConfetti 2.2s ease-in 1;
}
.celebration-overlay.celebrate-victory .celebration-text {
    color: #FFD54F;
    animation: celebrateVictoryRise 2.2s ease-out 1;
}

@keyframes celebrateConfetti {
    0%   { transform: translateY(-40vh) rotate(0deg); opacity: 0; }
    15%  { opacity: 1; }
    100% { transform: translateY(30vh) rotate(340deg); opacity: 1; }
}

@keyframes celebrateVictoryRise {
    0%   { transform: scale(0.5); opacity: 0; }
    25%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Reduced motion + senior mode: static banner, no motion. */
@media (prefers-reduced-motion: reduce) {
    .celebration-overlay * {
        animation: none !important;
    }
}
body.senior-mode .celebration-emoji { font-size: 88px; }
body.senior-mode .celebration-text { font-size: 28px; }

/* US-04 / US-24: player names/colors legend strip with active-turn highlight. */
.player-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
    margin: 6px 0 4px;
    min-height: 30px;
}

.player-chip {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 800;
    border-left: 2px solid transparent;
    transition: transform 0.25s ease;
}

.player-chip.active {
    transform: scale(1.08);
    outline: 2px solid #FFFFFF;
    border-left: 2px solid transparent;
}

.pawn-select-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
}

.select-label {
    color: #FFB74D;
    font-size: 11px;
    font-weight: 700;
}

.pawn-buttons-container {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.pawn-btn {
    background: #5D4037;
    color: #FFF;
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    /* Touch-target minimum (WCAG 2.5.5 / Material): quick-select buttons
       must be comfortably tappable without senior mode. */
    min-height: 48px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

/* Rules modal separator (replaces inline style attributes for CSP). */
.rule-sep {
    border: none;
    border-top: 2px solid #5D4037;
    margin: 8px 0;
}

/* Modal */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 100;
}

.modal-content {
    background: #2C241E;
    border-radius: 16px;
    padding: 20px;
    max-width: 94%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-content h2 {
    color: #FFD54F;
    font-size: 20px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.rules-body {
    overflow-y: auto;
    flex: 1;
    margin-bottom: 12px;
    padding-right: 4px;
}

.rules-body p {
    color: #D7CCC8;
    font-size: 13px;
    margin-bottom: 10px;
    line-height: 1.5;
}

/* Gatti gold shimmer badge */
.gatti-badge {
    display: inline-block;
    background: linear-gradient(90deg, #FFD54F, #FF8F00);
    color: #1E1B18;
    font-size: 10px;
    font-weight: 800;
    padding: 1px 5px;
    border-radius: 4px;
    letter-spacing: 1px;
}

/* ============================================================
   SENIOR MODE (accessibility)
   ------------------------------------------------------------
   Driven by `body.senior-mode` (toggled in app.js). Goes back to a
   larger canvas, bigger type/buttons, higher contrast and reduced
   motion so the game is comfortable for senior players.
   ============================================================ */

body.senior-mode {
    background-color: #000000;
    font-size: 20px;
}

body.senior-mode .app-container {
    max-width: 640px;               /* wider board -> bigger cells */
    background-color: #141210;
}

/* Reduced motion: strip the roll glow + hover/motion transforms. */
body.senior-mode .app-container * {
    animation: none !important;
    transition: none !important;
}

/* Help text that explains the toggle. */
.senior-desc {
    color: #D7CCC8;
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 10px;
}

/* Home screen sizing */
body.senior-mode .logo-area h1    { font-size: 42px; }
body.senior-mode .tagline         { font-size: 15px; }
body.senior-mode .card-section h2 { font-size: 18px; }
body.senior-mode .senior-desc     { font-size: 17px; }
body.senior-mode .chip             { padding: 18px 8px; }
body.senior-mode .chip-title       { font-size: 19px; }
body.senior-mode .chip-sub         { font-size: 16px; }
body.senior-mode .btn-primary      { padding: 22px; font-size: 22px; }
body.senior-mode .btn-secondary    { padding: 18px; font-size: 18px; }

/* Game screen sizing */
body.senior-mode .btn-sm           { padding: 10px 16px; font-size: 16px; }
body.senior-mode .header-bar h1    { font-size: 20px; }
body.senior-mode .turn-banner      { font-size: 19px; padding: 14px 18px; }
body.senior-mode .badge            { font-size: 15px; }
body.senior-mode .game-log         { font-size: 18px; line-height: 1.5; }
body.senior-mode .select-label     { font-size: 16px; }
body.senior-mode .pawn-btn         { padding: 12px 16px; font-size: 16px; }
body.senior-mode .cowry-title      { font-size: 16px; }
body.senior-mode .shell            { width: 58px; height: 68px; }
body.senior-mode .btn-roll         { padding: 18px; font-size: 20px; width: 92%; }
body.senior-mode .roll-score-display { font-size: 24px; }
body.senior-mode .roll-side { flex-basis: 150px; }
body.senior-mode .roll-side-label { font-size: 16px; }
body.senior-mode .roll-side-number { font-size: 84px; }
body.senior-mode .roll-side-name { font-size: 16px; }
@media (max-width: 560px) {
    body.senior-mode .roll-side-number { font-size: 52px; }
}
body.senior-mode .player-chip      { font-size: 16px; padding: 8px 16px; }

/* Higher contrast microcopy that is otherwise dim. */
body.senior-mode .game-log         { color: #FFF1E6; }
body.senior-mode .chip-sub         { color: #E0CFC0; }
body.senior-mode .btn-roll:disabled {
    background: #6D4C41;
    color: #F0E4DA;                 /* readable, not grey-on-brown */
}
body.senior-mode .modal-content h2 { font-size: 24px; }
body.senior-mode .rules-body p     { font-size: 18px; line-height: 1.7; }
body.senior-mode .modal-content .btn-primary { padding: 18px; font-size: 18px; }
