:root {
    --bg-color: #fdfbf7;
    --line-color: #aaccff;
    /* Light blue grid lines */
    --text-color: #2c3e50;
    /* Dark blue/grey ink */
    --primary-color: #2c3e50;
    --accent-color: #d35400;
    /* Burnt orange for highlights */
    --font-main: "Patrick Hand", cursive;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
}

body {
    background-color: var(--bg-color);
    background-image:
        linear-gradient(var(--line-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--line-color) 1px, transparent 1px);
    background-size: 20px 20px;
    /* Grid size */
    color: var(--text-color);
    display: flex;
    justify-content: center;
    height: 100vh;
    /* biome-ignore lint/suspicious/noDuplicateProperties: dvh with vh fallback for older browsers */
    height: 100dvh;
    overflow: hidden;
}

.screen {
    width: 100%;
    height: 100vh;
    /* biome-ignore lint/suspicious/noDuplicateProperties: dvh with vh fallback for older browsers */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    justify-content: safe center;
    padding: 10px;
    position: relative;
    overflow-y: auto;
    /* Allow scrolling if content overflows */
}

.hidden {
    display: none !important;
}

/* #app is a shrink-wrapped flex item: without this, screens are only as wide
   as their content and their scrollbar hugs that column instead of the
   window's right edge */
#app {
    width: 100%;
}

/* Paper sheet frame for secondary screens (tutorial, stats, FAQ) */
.card {
    background: white;
    padding: 2rem;
    border: 3px solid var(--text-color);
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    /* Sketchy border */
    text-align: center;
    box-shadow: 10px 10px 0px rgba(0, 0, 0, 0.1);
}

/* Lobby Styles */
h1 {
    font-size: 2.5rem;
    margin: 1rem 0 2rem 0;
    text-align: center;
}

.lobby-controls {
    background: rgba(255, 255, 255, 0.8);
    padding: 1.5rem;
    border: 2px solid var(--text-color);
    border-radius: 5px;
    /* Slightly rounded, hand-drawn feel? */
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 500px;
    /* Cap width on tablets */
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 1.2rem;
    font-weight: bold;
}

input {
    padding: 15px;
    /* Larger touch target */
    font-size: 1.2rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--text-color);
    color: var(--text-color);
    outline: none;
    transition: border-color 0.3s;
    width: 100%;
}

input:focus {
    border-bottom-color: var(--accent-color);
}

.btn-group {
    display: flex;
    flex-direction: column;
    /* Stack buttons */
    gap: 1rem;
    justify-content: center;
}

button {
    padding: 15px 20px;
    /* Larger touch target */
    font-size: 1.2rem;
    cursor: pointer;
    background: transparent;
    border: 2px solid var(--text-color);
    color: var(--text-color);
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    /* Sketchy border */
    transition:
        transform 0.1s,
        background 0.2s;
    width: 100%;
    /* Full width */
}

button:hover {
    transform: scale(1.02) rotate(-1deg);
    /* Subtle scale */
    background: rgba(0, 0, 0, 0.05);
}

button:active {
    transform: scale(0.98);
}

.primary-btn {
    background-color: #646cff;
    color: white;
    border: none;
    /* Remove border for solid look, or keep it? Let's remove to match "old" style more */
    font-weight: bold;
}

.primary-btn:hover {
    background-color: #535bf2;
    transform: scale(1.02) rotate(-1deg);
}

.secondary-btn {
    background-color: #e0e0e0;
    color: #333;
    border: none;
}

.secondary-btn:hover {
    background-color: #d0d0d0;
    transform: scale(1.02) rotate(1deg);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    color: var(--text-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        transform 0.2s,
        color 0.2s;
    width: auto;
    /* Override full width */
    border-radius: 50%;
    /* Circular touch target */
}

.icon-btn:hover {
    transform: scale(1.2);
    color: var(--accent-color);
    background: rgba(0, 0, 0, 0.05);
}

#my-games-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
    max-height: 150px;
    /* Limit height */
    overflow-y: auto;
    /* Enable scrolling */
    padding-right: 5px;
    /* Space for scrollbar */
}

/* Custom Scrollbar for my-games-list */
#my-games-list::-webkit-scrollbar {
    width: 6px;
}

#my-games-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

#my-games-list::-webkit-scrollbar-thumb {
    background: var(--text-color);
    border-radius: 3px;
    opacity: 0.5;
}

.join-room {
    display: flex;
    flex-direction: column;
    /* Stack inputs and buttons */
    gap: 1rem;
    width: 100%;
}

/* Point Selector - Compact Radio Buttons REMOVED */
/* Replaced with grouped select + button */

.create-room-group {
    display: flex;
    gap: 10px;
    width: 100%;
}

.create-room-group select {
    flex: 0 0 auto;
    width: auto;
    padding: 10px;
    font-size: 1.1rem;
    background: transparent;
    border: 2px solid var(--text-color);
    border-radius: 15px 5px 15px 5px / 5px 15px 5px 15px;
    color: var(--text-color);
    outline: none;
    cursor: pointer;
}

.create-room-group button {
    flex: 1;
}

.join-room-group {
    display: flex;
    gap: 5px;
    /* Reduced gap */
    width: 100%;
}

.join-room-group input {
    flex: 1 1 auto;
    /* Allow growing */
    width: auto;
    min-width: 100px;
    /* Ensure it's not too small */
    border: 2px solid var(--text-color);
    border-radius: 15px 5px 15px 5px / 5px 15px 5px 15px;
}

.join-room-group button {
    min-width: auto;
    /* Remove fixed min-width */
    padding: 10px 8px;
    /* Very tight padding */
    font-size: 1rem;
    white-space: nowrap;
    /* Prevent text wrapping */
    flex-shrink: 2;
}

.create-room-group button {
    flex: 1;
    padding: 10px 15px;
    /* Consistent sizing */
    font-size: 1rem;
}

.join-room-group input,
.create-room-group select {
    padding: 10px;
    /* Ensure input/select matches button height */
    font-size: 1rem;
}

/* Turn Indicator with Animation */
#current-player-display {
    font-weight: bold;
    padding: 8px 16px;
    border-radius: 20px;
    display: inline-block;
    transition: all 0.3s;
}

#current-player-display.my-turn {
    background: #4caf50;
    color: white;
    animation: pulse 2s infinite;
}

#current-player-display.opponent-turn {
    background: #ff9800;
    color: white;
}

@keyframes pulse {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
}

.pulse-btn {
    animation: btn-pulse 1.5s infinite;
    background-color: #4caf50 !important;
    color: white !important;
    border-color: #4caf50 !important;
}

@keyframes btn-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

/* Game Screen */
#game-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 2px solid var(--text-color);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.room-header-center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-badge {
    font-weight: bold;
    padding: 5px 15px;
    border: 2px dashed var(--text-color);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.5);
    transform: rotate(-1deg);
}

.game-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 10px;
}

.next-number-badge {
    display: flex;
    align-items: center;
    gap: 8px;
}

.number-circle {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 30px;
    height: 30px;
    background: var(--text-color);
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-family: monospace;
}

.canvas-container {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 600 / 800;
    /* Portrait aspect ratio */
    max-height: 75vh;
    /* Don't take full height */
    position: relative;
    background: rgba(255, 255, 255, 0.5);
    /* Slight white tint to distinguish from bg */
    border: 3px solid var(--text-color);
    /* Visible border */
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    /* Sketchy border */
    overflow: hidden;
    /* Clip canvas to the sketchy border */
    cursor: crosshair;
    margin: 0 auto;
    /* Center it */
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.1);
    touch-action: none;
    /* Prevent scrolling while drawing */
}

#stats-screen h2 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 2rem;
}

/* Hand-drawn wave underline: wavy text-decoration reads as the browser's
   spellcheck squiggle, so titles get a chunkier marker-stroke SVG instead */
h1,
#stats-screen h2 {
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    padding-bottom: 10px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='9' viewBox='0 0 20 9'%3E%3Cpath d='M0 4.5 Q 5 0.5 10 4.5 T 20 4.5' fill='none' stroke='%23d35400' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: left bottom;
    background-size: 20px 9px;
}

#stats-summary {
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.5);
    border: 2px dashed var(--text-color);
    border-radius: 10px;
}

#stats-summary > div {
    text-align: center;
}

#stats-summary > div > div:first-child {
    font-size: 3em;
    font-weight: bold;
    margin-bottom: 5px;
}

.stats-item {
    display: flex;
    justify-content: space-between;
    padding: 15px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.6);
    border: 2px solid var(--text-color);
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}

.faq-content h3 {
    margin-top: 15px;
    margin-bottom: 5px;
    color: var(--accent-color);
    font-size: 1.2rem;
}

.faq-content p {
    margin-bottom: 10px;
    font-size: 1rem;
    color: #555;
}

/* Fixed overlays must repaint the paper grid: a flat background hides the
   body's grid lines and breaks the page's look */
#tutorial-overlay {
    background-color: var(--bg-color);
    background-image:
        linear-gradient(var(--line-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--line-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.stats-item:last-child {
    margin-bottom: 20px;
}

.stats-name {
    font-weight: bold;
    font-size: 1.2em;
}

.stats-score {
    font-family: var(--font-main);
    font-size: 1.2em;
    font-weight: bold;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Game Over Modal */
#game-over-screen {
    position: fixed;
    /* Fixed to cover the entire viewport */
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(253, 251, 247, 0.95);
    /* Paper color, high opacity */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    /* High z-index to be on top */
    max-width: none;
    /* Override .screen max-width */
}

.modal-content {
    background: white;
    padding: 2rem;
    border: 3px solid var(--text-color);
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    /* Sketchy border */
    text-align: center;
    box-shadow: 10px 10px 0px rgba(0, 0, 0, 0.1);
    max-width: 90%;
    width: 100%;
    /* Full width on mobile */
}

#game-over-message {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: var(--accent-color);
    font-weight: bold;
}

.btn.primary {
    background-color: var(--primary-color);
    color: white;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 8px rgba(100, 108, 255, 0.4);
}

.btn.secondary {
    background-color: #3a3a3a;
    color: white;
}

.btn.secondary:hover {
    background-color: #4a4a4a;
}

/* Game Over Overlay */
.overlay {
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 100;
}

.modal {
    background: #2a2a2a;
    padding: 3rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 400px;
    width: 90%;
}

.modal h2 {
    margin-bottom: 1.5rem;
    color: var(--error-color);
    font-size: 2rem;
}

.modal p {
    margin-bottom: 2rem;
    font-size: 1.2rem;
    color: #ccc;
}
