:root {
    --bg: #0f1724;
    --card: #0b1220;
    --accent: #06b6d4;
    --muted: #94a3b8;
    --glass: rgba(255, 255, 255, 0.03);
}

* {
    box-sizing: border-box;
    font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans CJK TC', 'Helvetica Neue', Arial;
}

html,
body {
    height: 100%;
    margin: 0;
    background: linear-gradient(180deg, #071021 0%, #081426 100%);
    color: #e6eef6;
}

.no-select {
    user-select: none;
    -webkit-user-select: none;
}

.wrap {
    max-width: 980px;
    margin: 36px auto;
    padding: 20px;
}

header {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 18px;
    padding: 0;
    /* padding handled inside or by grid gap */
}

.header-left {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* This spreads the items out! */
    padding: 0 16px;
    /* Match padding of .card below */
}

h1 {
    margin: 0;
    font-size: 20px;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 18px;
    margin-top: 18px;
}

.card {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 6px 20px rgba(2, 6, 23, 0.6);
}

.timer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px;
    text-align: center;
}

.time {
    font-size: 72px;
    font-weight: 600;
    letter-spacing: 2px;
    transition: color 0.2s;
}

.ms {
    font-size: 20px;
    display: inline-block;
    vertical-align: top;
    margin-left: 8px;
    color: var(--muted);
}

.controls {
    margin-top: 16px;
    display: flex;
    gap: 8px;
}

button {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.04);
    color: inherit;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

button.primary {
    background: linear-gradient(90deg, var(--accent), #8b5cf6);
    color: #021124;
    border: none;
    font-weight: 600;
}

.small {
    padding: 6px 8px;
    font-size: 14px;
}

/* Timer control buttons - fixed size */
.controls button {
    min-width: 100px;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
}

.controls button .btn-label {
    font-size: 14px;
}

.controls button .btn-hint {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 2px;
}

.scramble {
    font-family: monospace;
    background: #061022;
    padding: 12px;
    border-radius: 8px;
    margin-top: 12px;
    color: #dbeafe;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent);
    border-radius: 8px;
}

.history {
    max-height: 420px;
    overflow: auto;
    margin-top: 12px;
}

.time-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

footer {
    margin-top: 18px;
    color: var(--muted);
    font-size: 13px;
}

/* Navigation Bar */
.navbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Login Button Container - holds Google button and parallelogram in same position */
.login-btn-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 36px;
}

/* Google button - positioned to overlap with parallelogram */
.login-btn-container .g_id_signin {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Parallelogram button - same position as Google button */
/* When hidden, use display:none for proper overlapping */
.login-btn-container .g_id_signin.hidden-login {
    display: none !important;
}

.login-btn-container .user-parallelogram.hidden {
    display: none !important;
}

.nav-btn {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 8px;
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.04);
    transition: all 0.2s;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.nav-btn.active {
    background: var(--accent);
    color: #021124;
    border: none;
    font-weight: 600;
}

/* Parallelogram User Button */
.user-parallelogram {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 24px 8px 16px;
    /* Extra right padding for balanced text */
    min-height: 36px;
    min-width: 80px;
    font-size: 14px;
    font-weight: 600;
    color: #e6eef6;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border: none;
    /* Trapezoid: AB (top) longer than CD (bottom), BC vertical, AD 45° slant */
    /* A=top-left, B=top-right, C=bottom-right, D=bottom-left */
    clip-path: polygon(0 0,
            /* A - top left */
            100% 0,
            /* B - top right */
            100% 100%,
            /* C - bottom right */
            12px 100%
            /* D - bottom left (shifted right for 45° slant) */
        );
    cursor: pointer;
    transition: all 0.2s;
}

.user-parallelogram:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.user-parallelogram:active {
    transform: translateY(0);
}

/* Parallelogram Color Variants */
.user-parallelogram.gradient-cyan {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
}

.user-parallelogram.gradient-purple {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.user-parallelogram.gradient-green {
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

.user-parallelogram.gradient-orange {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.hidden {
    visibility: hidden !important;
    pointer-events: none;
}

/* Page System */
.page {
    display: none;
}

.page.active {
    display: block;
}

.page-content {
    margin-top: 18px;
}

.page-content h2 {
    margin: 0 0 12px 0;
    font-size: 24px;
}

/* Settings Page */
.settings-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.settings-group label {
    font-size: 14px;
}


.settings-group input,
.settings-group select {
    background: var(--card);
    /* Match card background */
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e6eef6;
    /* Match text color */
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

.settings-group select option {
    background: var(--bg);
    /* Dark background for dropdown items */
    color: #e6eef6;
}

/* Global Select Styling (Dark Theme) */
select {
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e6eef6;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

select:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

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

select option {
    background: var(--bg);
    color: #e6eef6;
    padding: 8px;
}

/* More Menu */
.more-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.more-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    font-size: 16px;
    text-align: left;
    transition: all 0.2s;
}

.more-item:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateY(-2px);
}

.more-item .icon {
    font-size: 24px;
}

/* Scoreboard Filters */
.scoreboard-filters {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

.filter-row {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-row+.filter-row {
    margin-top: 12px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 12px;
    color: var(--muted);
}

.filter-group.toggle-group {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

.filter-group.toggle-group label:first-child {
    font-size: 14px;
    color: #e6eef6;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: #e6eef6;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked+.toggle-slider {
    background-color: #22c55e;
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(22px);
}

/* Submit Button */
.submit-btn {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
}

.submit-btn:hover {
    background: linear-gradient(135deg, #16a34a, #15803d);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

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

@media(max-width: 900px) {
    .grid {
        grid-template-columns: 1fr;
    }

    header {
        grid-template-columns: 1fr;
    }

    .time {
        font-size: 56px;
    }

    .wrap {
        padding: 12px;
    }
}

@media(max-width: 600px) {
    .header-left {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    header .navbar {
        width: auto;
        justify-content: flex-end;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .header-left h1 {
        padding-left: 0;
        align-self: auto;
        font-size: 24px;
    }

    .nav-btn {
        padding: 6px 10px;
        font-size: 13px;
    }
}

/* ================================
   Result Confirmation Popup
   ================================ */

.result-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.result-popup-overlay.hidden {
    display: none;
}

.result-popup {
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 32px 48px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.result-popup-time {
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 24px;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: #e6eef6;
}

.result-popup-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.result-btn {
    min-width: 80px;
    min-height: 50px;
    font-size: 18px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
}

.result-btn .btn-label {
    font-size: 18px;
}

.result-btn .btn-hint {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 2px;
}

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

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

.result-ok {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.result-plus2 {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.result-dnf {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

/* Sub-settings (collapsible) */
.sub-settings {
    margin-left: 16px;
    padding-left: 16px;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    margin-top: 8px;
}

.sub-settings.hidden {
    display: none;
}

.sub-setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.sub-setting-item label:first-child {
    font-size: 13px;
    color: var(--muted);
}