:root {
    --bg-color: #FFFBF0;
    /* Cream */
    --text-color: #5D5D5D;
    --card-bg: #FFFFFF;

    --p1-color: #87CEEB;
    /* Sky Blue */
    --p1-dark: #00BFFF;
    --p2-color: #A5D6A7;
    /* Cozy Green */
    --p2-dark: #A5D6A7;

    --dot-color: #D3C4BE;
    --dot-active: #888;
    --line-color: #555;

    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --radius: 20px;
    --last-move-color: #FFB347;
    /* Pastel Orange */
}

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.screen.active {
    display: flex;
}

.game-layer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

/* Cards */
.card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

h1 {
    margin: 0;
    color: #FFDAC1;
    font-size: 3rem;
    text-shadow: 2px 2px 0px #FFB7B2;
}

.subtitle {
    margin-top: 5px;
    color: #B5EAD7;
    font-weight: bold;
    letter-spacing: 1px;
}

/* Forms */
.form-group {
    margin: 20px 0;
    text-align: left;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #888;
}

input {
    width: 100%;
    padding: 12px;
    border: 2px solid #EEE;
    border-radius: 12px;
    font-size: 1rem;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.3s;
}

input:focus {
    outline: none;
    border-color: #B5EAD7;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.join-section {
    display: flex;
    gap: 10px;
}

.btn-primary,
.btn-secondary {
    border: none;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    flex: 1;
}

.btn-primary {
    background: #B5EAD7;
    color: #555;
    width: 100%;
}

.btn-primary:hover {
    transform: scale(1.02);
    background: #A3D8C5;
}

.btn-secondary {
    background: #EEE;
    color: #555;
}

.btn-secondary:hover {
    background: #DDD;
}

.btn-small {
    background: #EEE;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
}

.divider {
    margin: 20px 0;
    position: relative;
    text-align: center;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    background: #EEE;
    z-index: 0;
}

.divider span {
    background: white;
    padding: 0 10px;
    color: #CCC;
    position: relative;
    z-index: 1;
    font-size: 0.8rem;
}

.code-display {
    background: #F9F9F9;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: monospace;
    font-size: 1.2rem;
    border: 2px dashed #DDD;
}

.error-msg {
    color: #FF6B6B;
    font-size: 0.9rem;
    min-height: 1.2em;
}

/* Game Container */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    max-width: 600px;
    width: 95%;
    padding: 20px;
    background: transparent;
    /* Elements have their own bg or use one main card? Let's keep elements separate for now or one big card? User said "top of the gameboard itself". */
}

/* Header Title */
.game-header {
    text-align: center;
    margin-bottom: 5px;
}

/* Score Board Row */
.score-board {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: transparent;
    padding: 0;
    box-shadow: none;
    margin-bottom: 10px;
}

.player-badge {
    background: white;
    padding: 8px 15px;
    border-radius: 50px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0.7;
    font-weight: bold;
    transition: all 0.3s;
    border: 2px solid transparent;
    /* Reserve space for active border */
}

.player-badge.active {
    opacity: 1;
    transform: scale(1.05);
    background: white;
    border: 2px solid currentColor;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}

.player-badge.p1 {
    color: var(--p1-dark);
}

.player-badge.p2 {
    color: var(--p2-dark);
}

.player-badge .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
}


/* Game Board Wrapper */
.game-board-container {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    /* Remove margin */
}

.game-board {
    display: grid;
    /* Grid template set by JS */
    gap: 0;
    user-select: none;
}

.dot-cell {
    width: 14px;
    height: 14px;
    background: var(--dot-color);
    border-radius: 50%;
    z-index: 2;
    position: relative;
}

/* Lines and Boxes */
.h-line,
.v-line {
    position: relative;
    cursor: pointer;
    z-index: 1;
}

.h-line {
    width: 100%;
    height: 100%;
    align-self: center;
}

.h-line::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 8px;
    background: #EEE;
    transform: translateY(-50%);
    border-radius: 4px;
    transition: background 0.3s, transform 0.2s;
}

.v-line {
    height: 100%;
    width: 100%;
    justify-self: center;
}

.v-line::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    width: 8px;
    background: #EEE;
    transform: translateX(-50%);
    border-radius: 4px;
    transition: background 0.3s, transform 0.2s;
}

.h-line:hover::after,
.v-line:hover::after {
    background: #DDD;
    transform: scale(1.1) translateY(-50%);
    /* Keep centered for h-line */
}

.v-line:hover::after {
    transform: scale(1.1) translateX(-50%);
    /* Keep centered for v-line */
}

.h-line.taken::after,
.v-line.taken::after {
    background: var(--line-color);
}

.box {
    background: transparent;
    transition: background 0.5s;
    border-radius: 4px;
}

.box.p0 {
    background: var(--p1-color);
}

.box.p1 {
    background: var(--p2-color);
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    text-align: center;
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #B5EAD7;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Grid Options */
.grid-options {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.grid-option {
    flex: 1;
    position: relative;
}

.grid-option input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    margin: 0;
}

.grid-option span {
    display: block;
    padding: 10px;
    background: #EEE;
    border-radius: 50px;
    text-align: center;
    font-weight: bold;
    color: #888;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.grid-option input:checked+span {
    background: #B5EAD7;
    color: #555;
    border-color: #88D8B0;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.grid-option:hover span {
    background: #E0E0E0;
}

/* Last Move Highlight */
.h-line.last-move.p0::after,
.v-line.last-move.p0::after {
    background: var(--p1-color) !important;
    box-shadow: 0 0 8px var(--p1-color);
}

.h-line.last-move.p1::after,
.v-line.last-move.p1::after {
    background: var(--p2-color) !important;
    box-shadow: 0 0 8px var(--p2-color);
}