/* ============================================
   GOnnect4
   CSS following GO brand guidelines
   ============================================ */

/* ============================================
   1. Rest & Base
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================
   2. CSS variables (theme from GO brand book)
   ============================================ */

:root {
    /* Background colors */
    --bg-dark: #18222C;
    --bg-card: #253443;
    --bg-hover: #414153;

    /* Brand colors */
    --primary: #00add8;
    --primary-hover: #5dc9e2;
    --success: #2FBF9A;
    --success-hover: #58D6B8;
    --warning: #E6B450;
    --warning-hover: #F0C56E;
    --danger: #E06C75;
    --danger-hover: #F08C94;

    /* Text colors */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Border colors */
    --border: #475569;
    --border-active: #5dc9e2;

    /* Token colors */
    --red-token: #ce3262;
    --yellow-token: #fddd00;

    /* Spacing system */
    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2rem;
    --space-xl: 2.5rem;
}

/* ============================================
   3. Typography
   Using work sans from GO brand guidelines
   ============================================ */

body {
    font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: all ease-in-out .3s;
}

a:hover {
    color: var(--primary-hover);
}

h1 {
    font-family: 'Work Sans', sans-serif;
    font-weight: 700; /* Bold for headlines */
    font-size: 2.5rem;
    line-height: 1.2;
    margin-bottom: var(--space-sm);
}

h2 {
    font-family: 'Work Sans', sans-serif;
    font-weight: 600; /* SemiBold for subheads */
    font-size: 1.75rem;
    line-height: 1.3;
    margin-bottom: var(--space-md);
}

h3 {
    font-family: 'Work Sans', sans-serif;
    font-weight: 600;
    font-size: 1.35rem;
    line-height: 1.4;
    margin-bottom: var(--space-sm);
}

/* ============================================
   4. Layout
   ============================================ */

body {
    background: var(--bg-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: var(--bg-card);
    padding: .05rem var(--space-lg);
    border-bottom: 2px solid var(--border);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header .logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

header .logo img {
    height: 110px;
    width: auto;
}

header .logo h1 {
    font-family: 'Work Sans', sans-serif;
    font-size: 2.35rem;
    font-weight: 600;
    margin: 0;
}

.header-user-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.header-username {
    font-family: 'Work Sans', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Main */
main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
    overflow-y: auto;
    min-height: 0;
    width: 100%;
}

/* Footer */
footer {
    background: var(--bg-card);
    padding: 1rem var(--space-lg);
    border-top: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: var(--space-md);
}

footer .footer-left {
    display: flex;
    align-items: center;
}

footer .footer-logo {
    height: 36px;
}

footer .footer-right {
    font-family: 'Work Sans', sans-serif;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
}

footer a.img-link {
    display: flex;
}

footer a:hover.img-link {
    transform: scale(1.05);
    margin-left: 3px;
}

/* ============================================
   4.5. Utility classes (display)
   ============================================ */

.d-none {
    display: none !important;
}

.d-block {
    display: block !important;
}

.d-flex {
    display: flex !important;
}

.d-inline {
    display: inline !important;
}

.d-inline-block {
    display: inline-block !important;
}

.sr-only {
    display: none;
}

/* ============================================
   5. Components - Screens
   ============================================ */

.screen {
    display: none;
    justify-content: center;
    width: 100%;
    max-width: 1200px;
    min-height: 70vh;
}

.screen.active {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* ============================================
   6. Components - Cards
   ============================================ */

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: var(--space-lg);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.card h1 {
    text-align: center;
}

.card h2 {
    text-align: center;
}

/* User info card */
.user-info-card {
    padding: 1.25rem var(--space-lg);
}

.user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-greeting h2 {
    margin: 0;
    font-size: 1.5rem;
}

/* Card header */
.card-header {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.card-title {
    font-size: 2rem;
    margin: 0;
    text-align: center;
}

.card-header .btn-back {
    position: absolute;
    left: 0;
}

.subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: var(--space-lg);
    font-size: 1.125rem;
    font-weight: 400;
}

/* ============================================
   7. Components - Forms
   ============================================ */

/* Inputs */
input[type="text"] {
    width: 100%;
    padding: 0.875rem var(--space-sm);
    font-size: 1rem;
    font-family: 'Work Sans', sans-serif;
    font-weight: 400;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-dark);
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    transition: all 0.2s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--border-active);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

.input-uppercase {
    text-transform: uppercase;
}

.input-group {
    display: flex;
    gap: 0.75rem;
}

.input-group input {
    flex: 1;
    margin-bottom: 0;
}

/* Buttons */
.btn {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
    font-family: 'Work Sans', sans-serif;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Button variants */
.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
}

.btn-warning {
    background: var(--warning);
    color: var(--bg-dark);
}

.btn-warning:hover:not(:disabled) {
    background: var(--warning-hover);
}

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

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn-back {
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-back:hover {
    background: var(--bg-hover);
    border-color: var(--border-active);
}

/* Button sizes */
.btn-large {
    width: 100%;
    padding: 1.25rem;
    font-size: 1.125rem;
}

.btn-small {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.875rem;
}

#username-input {
    margin: var(--space-lg) 0;
}

#connect-btn {
    display: block;
    margin-left: auto;
    margin-top: var(--space-sm);
}

/* ============================================
   8. Components - Messages
   ============================================ */

.message {
    margin-top: var(--space-sm);
    margin-bottom: calc(var(--space-sm) / 2);
    padding: 0;
    border-radius: 6px;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
}

.message:empty {
    display: none;
}

.message.error,
.message.success {
    padding: 0.75rem;
}

.message.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.message.success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid var(--success);
}

/* ============================================
   9. Components - Lobby & Modes
   ============================================ */

.lobby-container {
    width: 100%;
}

.lobby-section {
    margin: var(--space-md) 0;
}

.lobby-section label {
    display: block;
    margin-bottom: var(--space-xs);
    color: var(--text-secondary);
    font-weight: 500;
}

/* Mode selection */
.mode-selection-card {
    padding: var(--space-xl);
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-lg);
}

.mode-option {
    background: var(--bg-dark);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: var(--space-lg) var(--space-md);
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.mode-option:not(.mode-disabled):hover {
    border-color: var(--border-active);
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.mode-icon {
    font-size: 3rem;
    margin-bottom: var(--space-xs);
}

.mode-icon img {
    height: 100px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.mode-option h3 {
    margin: 0;
}

.mode-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    flex: 1;
    font-weight: 400;
}

.mode-option.mode-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Players online indicator */
.players-online {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-xs);
    margin: var(--space-xs) 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse-animation 2s infinite;
}

.pulse-dot.large {
    width: 12px;
    height: 12px;
}

/* Separator */
.separator {
    text-align: center;
    margin: var(--space-lg) 0;
    color: var(--text-muted);
    font-weight: 600;
    position: relative;
}

.separator::before,
.separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.separator::before {
    left: 0;
}

.separator::after {
    right: 0;
}

/* Waiting area */
.waiting-area {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    background: var(--bg-dark);
    border-radius: 8px;
    border: 2px solid var(--border-active);
    text-align: center;
}

.waiting-area h3 {
    color: var(--warning);
    margin-bottom: var(--space-md);
    font-size: 1.5rem;
}

.code-display {
    margin: var(--space-md) 0;
}

.code-display label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
}

.code-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--success);
    letter-spacing: 0.25rem;
    font-family: 'Courier New', monospace;
}

.share-text {
    color: var(--text-secondary);
    margin-top: var(--space-sm);
    font-size: 0.875rem;
}

/* Matchmaking info */
.matchmaking-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    margin: var(--space-sm) 0;
}

/* Spinner */
.spinner {
    margin: var(--space-md) auto;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ============================================
   10. Components - Game screen
   ============================================ */

#game-screen {
    position: relative;
    width: 100%;
    max-width: 1600px;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: var(--space-sm);
}

#game-screen.active {
    display: flex;
}

/* Game header */
.game-header {
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: var(--space-lg);
    margin: 0 auto var(--space-sm);
}

/* Player cards */
.player-card {
    width: 200px;
    min-width: 200px;
    background: var(--bg-card);
    padding: var(--space-sm);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    border: 3px solid transparent;
    transition: all 0.3s ease;
    text-align: center;
}

.player-card.player-0 {
    border-color: var(--red-token);
}

.player-card.player-1 {
    border-color: var(--yellow-token);
}

.player-card.player-0.active {
    box-shadow: 0 0 20px rgba(220, 38, 38, 0.85);
}

.player-card.player-1.active {
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.85);
}

.player-token {
    width: 50px;
    height: 50px;
}

.player-info {
    width: 100%;
}

.player-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.player-badge {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-dark);
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    display: inline-block;
    font-weight: 500;
}

.player-timer {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    margin-top: 0.75rem;
    padding: var(--space-xs);
    background: var(--bg-dark);
    border-radius: 6px;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.player-timer.warning {
    color: var(--warning);
    animation: pulse 1s infinite;
}

.player-timer.danger {
    color: var(--danger);
    animation: pulse 0.5s infinite;
}

/* Game info center */
.game-info-center {
    flex: 1;
    background: var(--bg-card);
    padding: var(--space-sm);
    border-radius: 12px;
    border: 1px solid var(--border);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.status-message {
    font-size: 1.125rem;
    font-weight: 600;
    padding: 0.75rem;
    background: var(--bg-dark);
    border-radius: 8px;
}

.code-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.code-area span {
    font-family: 'Courier New', monospace;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--success);
}

.replay-area {
    margin-top: var(--space-xs);
    display: flex;
    justify-content: center;
    gap: var(--space-xs);
}

.replay-area .btn {
    margin: var(--space-xs) 0;
}

/* Game actions */
.game-actions {
    position: absolute;
    right: var(--space-sm);
    bottom: var(--space-sm);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    gap: var(--space-xs);
}

/* ============================================
   11. Components - Board
   ============================================ */

.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    overflow-x: auto;
}

#game-board {
    display: block;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    margin: 0 auto;
    width: 100%;
    max-width: min(560px, 100vw - 2rem);
    height: auto;
    aspect-ratio: 7 / 6 !important;
}

/* ============================================
   12. Animations
   ============================================ */

@keyframes pulse-animation {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   13. Media queries (Responsive)
   ============================================ */

/* Laptop */
@media (max-width: 1600px) {
    header .logo img {
        height: 100px;
    }

    .mode-icon img {
        height: 90px;
    }

    footer {
        padding: 1rem var(--space-md);
    }

    footer .footer-logo {
        height: 28px;
    }
}

/* Tablet / small screen */
@media (max-width: 1024px) {
    .card {
        padding: var(--space-lg);
    }

    .card h1 {
        font-size: 2.1rem;
    }

    .card h2 {
        font-size: 1.5rem;
    }

    .game-header {
        max-width: 900px;
        gap: var(--space-md);
    }

    .player-card {
        width: 160px;
    }
}

/* Tablet / very small screen */
@media (max-width: 825px) {
    main {
        align-items: flex-start;
    }

    .game-header {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-sm);
        max-width: 100%;
    }

    .player-card {
        flex: 1 1 45%;
        width: auto;
        padding: 0.6rem;
        gap: var(--space-xs);
    }

    .player-token {
        width: 30px;
        height: 30px;
    }

    .player-name {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }

    .player-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }

    #player-0 {
        order: 1;
    }

    #player-1 {
        order: 2;
    }

    .game-info-center {
        order: 3;
        flex: 1 1 100%;
        padding: 0.75rem;
    }

    .status-message {
        font-size: 1rem;
        padding: 0.6rem;
    }

    .game-actions {
        flex-direction: row;
        margin-bottom: -5rem;
    }

    .game-actions button {
        margin-bottom: var(--space-sm);
    }
}

/* Mobile */
@media (max-width: 768px) {
    body {
        font-size: 0.95rem;
    }

    header {
        padding: 0.75rem var(--space-md);
    }

    header .logo img {
        height: 60px;
    }

    header .logo h1 {
        font-size: 1.6rem;
    }

    .header-username {
        font-size: 0.9rem;
    }

    .card {
        padding: var(--space-md);
    }

    .card h1 {
        font-size: 2rem;
    }

    .card h2 {
        font-size: 1.4rem;
    }

    .mode-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .mode-option h3 {
        font-size: 1.2rem;
    }

    .mode-description {
        font-size: 0.9rem;
    }

    .mode-icon {
        font-size: 2.5rem;
    }

    main {
        padding: var(--space-xs) var(--space-sm);
    }

    #game-screen {
        padding: var(--space-xs) var(--space-sm) 0 var(--space-sm);
        max-width: 100%;
    }

    footer {
        padding: 0.75rem var(--space-sm);
    }

    footer .footer-logo {
        height: 20px;
    }
}

/* Very small mobile */
@media (max-width: 492px) {
    body {
        font-size: 0.9rem;
    }

    main {
        padding: var(--space-xs) 0;
    }

    header {
        padding: 0.5rem var(--space-md);
    }

    header .logo img {
        height: 50px;
    }

    header .logo h1 {
        font-size: 1.3rem;
    }

    .header-username {
        font-size: 0.8rem;
    }

    footer {
        padding: 0.5rem var(--space-xs);
    }

    footer .footer-logo {
        height: 16px;
    }

    footer .footer-right {
        font-size: 0.8rem;
    }

    .card {
        padding: 1.25rem;
    }

    .card h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
        margin-bottom: var(--space-md);
    }

    .player-name {
        font-size: 0.85rem;
    }

    .player-badge {
        font-size: 0.65rem;
    }

    .code-area span {
        font-size: 1rem;
    }

    .code-value {
        font-size: 2.1rem;
    }

    #game-board {
        width: 100% !important;
    }

    .hidden-sm {
        display: none !important;
    }

    .btn-back {
        position: relative;
        margin-right: auto;
    }

    .replay-area .btn {
        width: 100%;
    }
}

/* Short height screens fixes */
@media (max-height: 850px) {
    main {
        align-items: flex-start;
    }

    #game-board {
        max-height: 45vh;
        width: auto;
    }
}

@media (max-height: 600px) {
    #game-board {
        max-height: 40vh;
    }
}
