/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #1a1a12;
    --surface: #2a2a1e;
    --surface2: #353528;
    --border: #4a4a38;
    --text: #e8e0c8;
    --text-dim: #9a9480;
    --accent: #c8a84e;
    --accent-dark: #8a7030;
    --green: #6abf5e;
    --red: #c45050;
    --white-sq: #e8dcc0;
    --black-sq: #1c1c14;
    --radius: 4px;
    --radius-sm: 3px;
}

html, body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

body {
    background-image:
        linear-gradient(45deg, #000 25%, transparent 25%),
        linear-gradient(-45deg, #000 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #000 75%),
        linear-gradient(-45deg, transparent 75%, #000 75%);
    background-size: 240px 240px;
    background-position: 0 0, 0 120px, 120px -120px, 120px 0;
    background-color: #fff;
}

.hidden { display: none !important; }

/* === Navigation === */
.main-nav {
    display: flex;
    justify-content: center;
    gap: 0;
    padding: 0;
    background: #000;
    border-bottom: 2px solid var(--accent-dark);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-link {
    color: var(--text-dim);
    text-decoration: none;
    padding: 10px 24px;
    font-weight: bold;
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-right: 1px solid var(--border);
    transition: all 0.15s;
}

.nav-link:last-child { border-right: none; }
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active {
    color: var(--accent);
    background: var(--bg);
    border-bottom: 2px solid var(--accent);
    margin-bottom: -2px;
}

/* === Buttons === */
.btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    border-radius: var(--radius);
    transition: all 0.1s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-start {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    background: var(--accent);
    color: var(--black-sq);
    border: 2px solid var(--accent-dark);
    margin-top: 16px;
}
.btn-start:hover { filter: brightness(1.1); }

.btn-ctrl {
    padding: 8px 18px;
    font-size: 0.8rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ctrl:hover { background: var(--border); }

.btn-end {
    padding: 8px 18px;
    font-size: 0.8rem;
    background: rgba(196, 80, 80, 0.2);
    color: var(--red);
    border: 1px solid var(--red);
}
.btn-end:hover { background: rgba(196, 80, 80, 0.35); }

.btn-result {
    padding: 10px 14px;
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--border);
    flex: 1;
    text-transform: none;
}
.btn-result:hover { border-color: var(--accent); }
.btn-result.selected {
    border-color: var(--accent);
    background: rgba(200, 168, 78, 0.15);
    color: var(--accent);
}

.btn-save {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    background: var(--green);
    color: #111;
    border: 2px solid #4a9a42;
    margin-top: 12px;
}
.btn-save:hover { filter: brightness(1.1); }

/* === Score Banner === */
.score-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.score-player {
    display: flex;
    align-items: center;
    gap: 8px;
}

.score-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent-dark);
}

.score-name { font-weight: bold; font-size: 0.85rem; }
.score-num {
    font-family: 'Georgia', serif;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
}
.score-separator {
    font-size: 1.2rem;
    color: var(--text-dim);
    font-weight: bold;
}

/* === Mode & Type Toggles === */
.mode-toggle, .game-type-toggle {
    display: flex;
    gap: 0;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 14px;
}

.mode-btn, .type-btn {
    flex: 1;
    padding: 9px 12px;
    border: none;
    background: var(--surface);
    color: var(--text-dim);
    font-family: inherit;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.1s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mode-btn + .mode-btn,
.type-btn + .type-btn {
    border-left: 1px solid var(--border);
}

.mode-btn.active, .type-btn.active {
    background: var(--accent);
    color: var(--black-sq);
}

/* === Setup Screen === */
.setup-screen {
    max-width: 400px;
    margin: 20px auto;
    padding: 20px 16px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 6px;
}

.setup-screen h2 {
    text-align: center;
    margin-bottom: 18px;
    font-size: 1.2rem;
    color: var(--accent);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.setup-players {
    display: flex;
    justify-content: center;
    gap: 28px;
    margin-bottom: 20px;
}

.setup-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    font-size: 0.9rem;
}

.setup-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--accent-dark);
}

.time-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 14px;
}

.preset-btn {
    padding: 8px 14px;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
}
.preset-btn:hover { border-color: var(--accent); }
.preset-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--black-sq);
}

.custom-time {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.custom-time label { font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; }

.custom-time input {
    width: 70px;
    padding: 7px 10px;
    background: var(--surface);
    border: 2px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-family: 'Georgia', serif;
    font-size: 1rem;
    text-align: center;
}

.color-select {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.color-select label { font-size: 0.85rem; color: var(--text-dim); }

.color-select select {
    flex: 1;
    padding: 8px 10px;
    background: var(--surface);
    border: 2px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
}

/* === Clock Screen === */
.clock-screen {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 44px);
}

.clock-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s;
    position: relative;
}

/* Black side (top) */
.clock-top {
    background: #111108;
    color: #e8e0c8;
    transform: rotate(180deg);
}

.clock-top .clock-time {
    color: #e8e0c8;
}

.clock-top .clock-player-name {
    color: #9a9480;
}

.clock-top .clock-avatar {
    border-color: #555;
}

/* White side (bottom) */
.clock-bottom {
    background: #e8dcc0;
    color: #1a1a12;
}

.clock-bottom .clock-time {
    color: #1a1a12;
}

.clock-bottom .clock-player-name {
    color: #5a5540;
}

.clock-bottom .clock-avatar {
    border-color: #b0a888;
}

/* Active = clock is running for this side */
.clock-top.active-clock {
    background: #1a1810;
}

.clock-bottom.active-clock {
    background: #f5ecd4;
}

/* Inactive side dims slightly */
.clock-half:not(.active-clock) {
    opacity: 0.7;
}

/* Low time warning */
.clock-half.low-time .clock-time {
    color: var(--red) !important;
    animation: pulse-red 0.8s ease-in-out infinite;
}

.clock-half.time-up {
    opacity: 0.4;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.clock-player-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.clock-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid;
}

.clock-player-name {
    font-weight: bold;
    font-size: 1rem;
}

.clock-time {
    font-family: 'Georgia', serif;
    font-size: 4.5rem;
    font-weight: bold;
    letter-spacing: 3px;
}

.clock-controls {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 5px 0;
    background: var(--surface);
    border-top: 2px solid var(--border);
    border-bottom: 2px solid var(--border);
    z-index: 10;
}

/* === Result Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}

.modal-content {
    background: var(--surface);
    border: 2px solid var(--accent-dark);
    border-radius: var(--radius);
    padding: 22px;
    width: 100%;
    max-width: 420px;
    max-height: 90dvh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 6px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 1.1rem;
}
.modal-content p { color: var(--text-dim); margin-bottom: 14px; font-size: 0.9rem; }

.result-buttons {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}

.photo-upload-section { margin-bottom: 10px; }

.photo-upload-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.photo-input {
    display: block;
    margin-top: 4px;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.photo-input::file-selector-button {
    padding: 5px 12px;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    margin-right: 8px;
}

.photo-preview {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.photo-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.match-notes {
    width: 100%;
    padding: 8px;
    background: var(--bg);
    border: 2px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 50px;
}

/* === History === */
.page-header {
    padding: 18px 16px 6px;
    max-width: 560px;
    margin: 0 auto;
}

.page-header h1 {
    font-size: 1.2rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.match-list {
    max-width: 560px;
    margin: 0 auto;
    padding: 8px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.match-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-dark);
    border-radius: var(--radius);
    padding: 14px;
}

.match-card::before { display: none; }

.match-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.match-time-ctrl {
    background: rgba(200, 168, 78, 0.12);
    padding: 2px 6px;
    border-radius: var(--radius);
    color: var(--accent);
    font-weight: bold;
    font-size: 0.78rem;
}

.match-players {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.match-player {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: bold;
    font-size: 0.9rem;
}

.match-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.match-vs {
    color: var(--text-dim);
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.color-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: bold;
}

.white-badge { background: var(--white-sq); color: #111; }
.black-badge { background: var(--black-sq); color: #ccc; border: 1px solid #444; }

.match-result {
    text-align: center;
    font-weight: bold;
    font-size: 0.9rem;
    padding: 5px;
    border-radius: var(--radius);
}
.match-result.win { color: var(--green); background: rgba(106, 191, 94, 0.1); }
.match-result.draw { color: var(--accent); background: rgba(200, 168, 78, 0.1); }

.match-notes-display {
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--text-dim);
    font-style: italic;
}

.match-photos {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.match-photo-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.1s;
}
.match-photo-thumb:hover { transform: scale(1.05); }

.empty-state, .loading {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 16px;
}

/* === Lightbox === */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    cursor: pointer;
    padding: 16px;
}

.lightbox img {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: var(--radius);
}

/* === Settings / Profile === */
.profile-cards {
    max-width: 560px;
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.profile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-dark);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
}

.profile-card::before { display: none; }

.profile-avatar-wrap {
    position: relative;
    display: inline-block;
    margin-bottom: 10px;
}

.profile-avatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--accent-dark);
}

.avatar-upload-btn {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--accent);
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.avatar-upload-btn:hover { text-decoration: underline; }

.hidden-input { display: none; }

.profile-name {
    font-size: 1.15rem;
    margin-bottom: 14px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-num {
    font-family: 'Georgia', serif;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* === Desktop Layout === */
@media (min-width: 768px) {
    .clock-screen { flex-direction: row; }
    .clock-top { transform: none; }
    .clock-controls {
        flex-direction: column;
        padding: 0 6px;
        align-self: center;
        border: none;
        border-left: 2px solid var(--border);
        border-right: 2px solid var(--border);
    }
    .clock-time { font-size: 6rem; }

    .result-buttons { flex-wrap: nowrap; }

    .profile-cards { flex-direction: row; }
    .profile-card { flex: 1; }
}
