@import url('https://fonts.googleapis.com/css2?family=Capriola&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap');

/* BANNER */
.winner-banner {
    position: fixed; top: -50%; left: 50%;
    transform: translate(-50%, -50%) rotate(-5deg);
    font-family: 'Capriola', sans-serif; 
    font-size: 6rem; 
    color: #fff; /* Crisp white text */
    text-shadow: 2px 2px 5px rgba(0,0,0,0.6); /* Clean drop-shadow instead of glow */
    
    /* NEW: 50% Transparent Boatzee Green Block */
    background-color: rgba(46, 204, 113, 0.75); 
    width: 120vw; /* Stretch safely past the left/right screen edges */
    padding: 20px 0; /* Thicken the block behind the text */
    box-shadow: 0 10px 30px rgba(0,0,0,0.2); /* Soft shadow beneath the block itself */
    
    z-index: 9999; transition: top 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none; text-align: center;
    white-space: normal; line-height: 1.1; 
}
.winner-show { top: 50%; }
@media (max-width: 600px) { .winner-banner { font-size: 3rem; } }

/* BASE STYLES - OPEN SANS */
:root { --primary: #2c3e50; --accent: #27ae60; --bg: #ecf0f1; --border: #bdc3c7; }

html, body { 
    font-family: 'Open Sans', sans-serif; 
    background: var(--bg); 
    color: var(--primary); 
    margin: 0; padding: 0;
    height: 100%; width: 100%;
    overflow: hidden; 
    position: fixed; 
    overscroll-behavior-y: none;
}

/* NEW: Dark Mode background */
body.dark-mode {
    background: #000 !important;
}

#app-wrapper {
    height: 100%; width: 100%;
    overflow-y: auto; 
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
    display: flex; flex-direction: column; align-items: center;
    padding: 5px; box-sizing: border-box;
}

/* UTILITIES */
.hidden { display: none !important; }
.inactive-col { background-color: #f0f2f5 !important; color: #ccc; }
.inactive-header { background-color: #eaeded !important; color: var(--primary) !important; }
.waiting-player { background-color: #7f8c8d !important; color: white !important; }
.active-turn { background-color: #27ae60 !important; color: white !important; }

/* Ensure empty error messages don't take up space */
#error-msg:empty { display: none; }

/* --- UNIFIED SPACING --- */
.standard-item {
    width: 50% !important; 
    max-width: 500px; 
    height: 48px !important; 
    margin: 0 auto 10px auto !important; 
    box-sizing: border-box !important;
}

/* Block elements */
input.standard-item, button.standard-item { display: block; }
/* Flex elements */
div.standard-item { display: flex !important; }

.setup-input { padding: 0 10px; font-size: 16px; border-radius: 4px; border: 1px solid #ccc; background: white; line-height: 46px; }
.action-btn { display: flex; justify-content: center; align-items: center; border: none; border-radius: 4px; font-size: 16px; font-weight: bold; color: white; cursor: pointer; padding: 0; }

.player-row { justify-content: space-between; align-items: center; padding: 0; border: none; background: transparent; }
.player-input-inner { width: 58% !important; height: 100%; border: 1px solid #ccc; border-radius: 4px; padding: 0 10px; font-size: 16px; box-sizing: border-box; background: white; }
.btn-status { width: 40% !important; height: 100%; border: none; border-radius: 4px; font-size: 14px; font-weight: bold; color: white; cursor: default; display: flex; justify-content: center; align-items: center; }
.btn-joined { background-color: #95a5a6; }
.btn-add { background-color: #3498db; cursor: pointer; }
#btn-action { background-color: var(--accent); } 
#btn-start { background-color: #27ae60; } 

#room-code-input { text-transform: uppercase; }
#room-code-input::placeholder { text-transform: none !important; opacity: 0.7; }

#setup { 
    background: white; 
    padding: 20px 10px; 
    border-radius: 8px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
    width: 100%; 
    max-width: 650px; 
    box-sizing: border-box; 
    text-align: center;
    min-height: 90vh; 
    display: flex; flex-direction: column;
}

/* FOOTER STYLES */
.footer-container {
    margin-top: auto;
    padding-top: 15px;
    padding-bottom: 10px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}
.footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    font-size: 14px;
    color: #7f8c8d;
}
.footer-copyright {
    font-size: 12px;
    color: #95a5a6;
    margin-top: 5px;
    cursor: pointer; /* Makes it clear it can be clicked */
    user-select: none; /* Prevents text highlighting on click */
}
.footer-copyright:hover {
    color: #7f8c8d;
}

#lobby-area { 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    width: 100%; 
}

#player-list { width: 100%; }

#game-board { 
    background: white; padding: 10px 15px; border-radius: 8px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
    width: 100%; max-width: 650px; 
    box-sizing: border-box; text-align: center;
    min-height: 90vh; display: flex; flex-direction: column;
}

.game-logo { width: 450px; margin: 0 auto 10px auto; display: block; }
.board-logo { width: 212px; margin: 0 auto 10px auto; display: block; }

.controls-row { display: flex; justify-content: center; align-items: center; gap: 22px; margin: 5px 0; padding: 10px 0; }
.dice-container { display: flex; gap: 6px; }

.die { 
    width: 52px; height: 52px; background: white; border: 2px solid var(--primary); border-radius: 8px; 
    display: flex; justify-content: center; align-items: center; cursor: pointer; user-select: none; 
    box-shadow: 2px 2px 0px rgba(0,0,0,0.15); position: relative; padding: 4px; box-sizing: border-box;
    touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none;
}
.die.held { background: var(--accent); border-color: var(--accent); transform: translateY(2px); box-shadow: none; }
@keyframes roll-shake { 0% { transform: rotate(0deg); } 25% { transform: rotate(15deg); } 50% { transform: rotate(-15deg); } 75% { transform: rotate(5deg); } 100% { transform: rotate(0deg); } }
.die.shaking { animation: roll-shake 0.4s ease-out; }
.die-face { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; width: 100%; height: 100%; }
.dot { background-color: var(--primary); border-radius: 50%; width: 8px; height: 8px; align-self: center; justify-self: center; }
.die.held .dot { background-color: white; }
.die-text { font-size: 24px; font-weight: bold; color: var(--primary); }
.die.held .die-text { color: white; }

button { background: var(--primary); color: white; border: none; padding: 8px 0; border-radius: 4px; cursor: pointer; font-size: 15px; width: 100%; margin: 5px 0; transition: background 0.2s ease; }
button:disabled { background: #bdc3c7; }
#btn-roll { background: #e74c3c !important; color: white; margin: 0 !important; width: 150px !important; height: 52px !important; font-weight: bold; font-size: 16px; line-height: 1.1; }
#btn-roll:disabled { background: #bdc3c7 !important; }

.btn-join { width: 50% !important; display: block; margin: 10px auto; }
.footer-controls { display: flex; justify-content: center; align-items: center; gap: 15px; margin-top: 15px; padding-top: 5px; font-size: 14px; color: #7f8c8d; font-weight: normal; }
.footer-separator { color: #bdc3c7; font-weight: normal; }
.room-wrapper { display: inline-flex; align-items: center; }
.footer-link { color: #7f8c8d; text-decoration: none; cursor: pointer; font-weight: normal; }
.btn-footer { width: auto !important; display: inline-block !important; padding: 6px 12px !important; font-size: 12px !important; background: #f8f9fa !important; color: #2c3e50 !important; border: 1px solid #bdc3c7 !important; border-radius: 4px; cursor: pointer; margin: 0 !important; }
.btn-footer:hover { background: #ecf0f1 !important; border-color: #95a5a6 !important; }
.btn-copy { background: none !important; border: none !important; cursor: pointer; font-size: 16px; margin-left: 8px; padding: 0; width: auto !important; color: var(--accent) !important; display: flex; align-items: center; }
.btn-copy:hover { opacity: 0.7; }

.table-wrapper { overflow-x: auto; margin-top: 10px; border: none; }

table { 
    width: 100%; 
    table-layout: fixed; 
    border-collapse: separate; 
    border-spacing: 0; 
    min-width: 600px;
}

th, td { border-right: 1px dashed var(--border); border-bottom: 1px dashed var(--border); padding: 4px 2px; text-align: center; font-size: 14px; height: 32px; }

th:first-child, td:first-child { 
    position: sticky; left: 0; z-index: 10; 
    border-right: 1px solid #95a5a6; 
    width: 160px; min-width: 160px; max-width: 160px;
}

th:last-child, td:last-child { border-right: none !important; }
th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ROUNDED CORNERS */
#scorecard thead tr th:first-child { border-top-left-radius: 8px; }
#scorecard thead tr th:last-child { border-top-right-radius: 8px; }
#score-body tr:last-child td:first-child { border-bottom-left-radius: 8px; }
#score-body tr:last-child td:last-child { border-bottom-right-radius: 8px; }

/* BOLD BORDERS */
.bold-border-top { border-top: 3px solid var(--primary) !important; }
.bold-border-bottom { border-bottom: 3px solid var(--primary) !important; }

.category-name { 
    text-align: right; padding-right: 8px; padding-left: 2px; 
    font-weight: bold; font-size: 15px; white-space: nowrap; 
    background: #ffffff; width: auto; 
}

th { 
    background: #eaeded !important; color: var(--primary) !important; 
    position: sticky; top: 0; z-index: 20; 
    border-bottom: 2px solid #bdc3c7;
    height: auto !important; padding: 6px 2px !important; 
    vertical-align: bottom; line-height: 1.2;
}
th:first-child { background: #eaeded !important; z-index: 30; } 

.header-score { display: block; font-size: 0.9em; color: var(--accent); font-weight: bold; margin-top: 2px; }
.player-border-left { border-left: 1px solid #34495e !important; }
.filled { background: #eee; color: #333; font-weight: bold; font-size: 16px; }

/* PREVIEW CLASSES */
.preview { background-color: #fffacd; color: #ff0800; font-weight: bold; cursor: pointer; font-size: 16px; }
.preview-remote { color: #ff0800; font-weight: bold; font-size: 16px; }

/* MODALS */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 10000; display: flex; justify-content: center; align-items: center; }
.modal-content { background: white; padding: 20px; border-radius: 8px; width: 90%; max-width: 450px; max-height: 80vh; overflow-y: auto; text-align: center; position: relative; }

/* HOW TO PLAY STYLES */
.htp-content { text-align: left; line-height: 1.6; color: #555; }
.htp-content h2 { font-family: 'Permanent Marker', cursive; color: var(--accent); border-bottom: 2px dashed var(--border); padding-bottom: 5px; margin-top: 30px; }
.htp-content h3 { color: #34495e; margin-top: 25px; margin-bottom: 10px; font-weight: 600; }
.htp-table { width: 100%; border-collapse: collapse; margin-top: 15px; }
.htp-table th, .htp-table td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.htp-table th { background-color: #f2f2f2; font-weight: bold; white-space: nowrap; }
.htp-box { padding: 15px; margin: 20px 0; border-radius: 0 4px 4px 0; border-left: 5px solid; }
.strategy-box { background-color: #e8f8f5; border-color: var(--accent); }
.bonus-box { background-color: #fffacd; border-color: #f39c12; }

/* SCORE MODAL STYLES */
#scores-modal .modal-content { max-width: 360px; }
/* UPDATED GRID COLUMNS TO ACCOMMODATE LOCALIZED TIME */
.score-row { display: grid; grid-template-columns: 15% 45% 20% 20%; align-items: center; padding: 8px 0; border-bottom: 1px solid #eee; font-size: 14px; text-align: left; }.score-row span:last-child { text-align: right; }
.score-row:first-child { font-weight: bold; border-bottom: 2px solid #333; }
.pagination-controls { display: flex; justify-content: center; align-items: center; gap: 15px; margin-top: 15px; }
.btn-page { background: var(--primary); color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; width: auto; font-size: 16px; }
.btn-page:disabled { background: #bdc3c7; cursor: default; }

@media (max-width: 600px) {
    .game-logo { width: 320px; }
    .die { width: 38px; height: 38px; }
    #btn-roll { width: 120px !important; height: 38px !important; font-size: 13px; }
    .setup-input, .player-row, .action-btn, .standard-item { width: 85% !important; }
}

/* --- BOATZEE ANIMATION --- */
.boat-wrapper {
    position: fixed;
    top: 40%;
    left: 120vw; /* Start off-screen right */
    z-index: 10001; 
    pointer-events: none; 
    animation: move-across 3.5s linear forwards;
}

.boat-image {
    width: 400px;
    height: auto;
    position: relative; /* Required for z-index to take effect */
    z-index: 5;         /* Pulls the boat to the front */
    transform-origin: center center;
    filter: drop-shadow(4px 4px 6px rgba(0,0,0,0.5));
    animation: bob-boat 3.5s ease-in-out forwards;
}

/* Handles only the horizontal movement */
@keyframes move-across {
    0%   { left: 120vw; }
    100% { left: -600px; }
}

/* Handles the bobbing cleanly without the scale hack */
@keyframes bob-boat {
    0%   { transform: translateY(0) rotate(5deg); }
    20%  { transform: translateY(-20px) rotate(-5deg); }
    40%  { transform: translateY(0) rotate(5deg); }
    60%  { transform: translateY(-20px) rotate(-5deg); }
    80%  { transform: translateY(0) rotate(5deg); }
    100% { transform: translateY(-20px) rotate(-5deg); }
}

/* --- SCORECARD HIGHLIGHTING --- */
.score-cell {
    /* Prevent text selection and native magnifying glass on long press */
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    position: relative; 
}

/* Single Cell Highlight: Thick red outline */
.highlighted-cell {
    background-color: #fff0f0 !important;
    box-shadow: inset 0 0 0 3px #e74c3c !important; /* Increased to 3px thick */
    animation: pulse-bg 1.2s infinite alternate;
}

/* --- ROW HIGHLIGHT --- */
/* Apply Background and Top/Bottom borders to ALL cells in the highlighted row */
.highlighted-row td {
    background-color: #fff0f0 !important;
    animation: pulse-bg 1.2s infinite alternate;
    box-shadow: inset 0 1px 0 0 #e74c3c, inset 0 -1px 0 0 #e74c3c; /* Top & Bottom Only */
}

/* Fix Left End of Row: Add Left Border */
.highlighted-row td:first-child {
    box-shadow: inset 1px 1px 0 0 #e74c3c, inset 0 -1px 0 0 #e74c3c;
}

/* Fix Right End of Row: Add Right Border */
.highlighted-row td:last-child {
    box-shadow: inset 0 1px 0 0 #e74c3c, inset -1px -1px 0 0 #e74c3c;
}

@keyframes pulse-bg {
    from { background-color: #ffe0e0; }
    to { background-color: #ffb3b3; }
}

/* --- BOATZEE ANIMATION --- */
.boat-animation {
    position: fixed;
    top: 50%;
    left: 120vw; /* Start off-screen to the right */
    font-size: 120px;
    z-index: 10001; /* Keeps it floating above the game board and modals */
    pointer-events: none; /* Ensures players can still click things behind it */
    animation: float-boat 5.0s linear forwards;
    transform: translateY(-50%);
    filter: drop-shadow(4px 4px 2px rgba(0,0,0,0.4));
}

@keyframes float-boat {
    0%   { left: 120vw; transform: translateY(-50%) rotate(5deg); }
    20%  { transform: translateY(-65%) rotate(-5deg); }
    40%  { transform: translateY(-35%) rotate(5deg); }
    60%  { transform: translateY(-65%) rotate(-5deg); }
    80%  { transform: translateY(-35%) rotate(5deg); }
    100% { left: -150px; transform: translateY(-50%) rotate(-5deg); }
}

/* --- NEW: SMOKE ANIMATION --- */
.boat-wrapper {
    /* (Ensure your existing .boat-wrapper still has these properties) */
    position: fixed;
    top: 40%;
    left: 120vw; 
    z-index: 10001; 
    pointer-events: none; 
    animation: move-across 5.0s linear forwards;
    
    /* ADD THIS so the smoke and boat align relative to the wrapper */
    display: flex;
    align-items: center;
    justify-content: center;
}

.smoke-container {
    position: absolute;
    top: 5px;   /* Decreased from 40px to move it UP */
    left: 220px; /* Increased from 180px to move it RIGHT */
    z-index: -1; 
}

.smoke-puff {
    position: absolute;
    width: 35px;
    height: 35px;
    background: rgba(149, 165, 166, 0.8); /* Nice grey smoke color */
    border-radius: 50%;
    opacity: 0;
    filter: blur(5px);
    animation: puff-rise 1.5s ease-out infinite;
}

@keyframes puff-rise {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 0.9;
    }
    100% {
        /* Pushes the smoke UP and to the RIGHT so it trails behind the left-moving boat */
        transform: translate(150px, -120px) scale(3.5);
        opacity: 0;
    }
}

/* --- CONFETTI ANIMATION --- */
#confetti-container {
    position: fixed;
    top: 0; 
    left: 0;
    width: 100vw; 
    height: 100vh;
    pointer-events: none; /* Let players click through it */
    z-index: 9998; /* Sits right behind the Winner Banner (9999) */
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    animation: fall linear forwards;
}

@keyframes fall {
    0% { transform: translateY(0) rotate(0deg) translateX(0); opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg) translateX(50px); opacity: 0.3; }
}

/* --- LOCALIZED CONFETTI EFFECT (Quick explosion) --- */
.bonus-confetti-piece {
    position: absolute;
    top: 0;
    left: 0;
    animation: bonus-confetti-shoot linear forwards;
    pointer-events: none;
    --shoot-x: 0px; /* Trajectory values will be set with JS */
    --shoot-y: 0px; 
    --spin: 0deg;
}

@keyframes bonus-confetti-shoot {
    0% { 
        transform: translate(0, 0) rotate(0deg); 
        opacity: 1; 
    }
    100% { 
        /* By grouping translate(X, Y) together BEFORE rotate, it shoots straight! */
        transform: translate(var(--shoot-x), var(--shoot-y)) rotate(var(--spin)); 
        opacity: 0; 
    }
}