/* ═══════════════════════════════════════
   Timer — FrisQuiz Tools
   Dark Theme UI
   ═══════════════════════════════════════ */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Fredoka', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #0c0e1a;
    color: #e2e8f0;
    min-height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ═══ TOP BAR ═══ */
.top-bar {
    height: 56px;
    background: rgba(20, 22, 39, 0.95);
    border-bottom: 1px solid rgba(139, 92, 246, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    backdrop-filter: blur(10px);
    z-index: 50;
    position: relative;
}

.top-bar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #e2e8f0;
    text-decoration: none;
    font-size: 18px;
    font-weight: 700;
    transition: color 0.2s;
}

.top-bar-brand i {
    color: #8b5cf6;
    font-size: 22px;
}

.top-bar-brand:hover {
    color: #a78bfa;
}

.top-bar-back {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    margin-right: 12px;
    color: #c4b5fd;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(139, 92, 246, 0.12);
    border: 1px solid rgba(139, 92, 246, 0.25);
    transition: all 0.2s;
}

.top-bar-back:hover {
    color: #fff;
    background: rgba(139, 92, 246, 0.28);
    border-color: rgba(139, 92, 246, 0.5);
    transform: translateY(-1px);
}

.top-bar-back i {
    font-size: 14px;
}

.top-bar-actions {
    display: flex;
    gap: 8px;
}

.top-bar-btn {
    background: rgba(139, 92, 246, 0.12);
    border: 1px solid rgba(139, 92, 246, 0.25);
    color: #c4b5fd;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.top-bar-btn:hover {
    background: rgba(139, 92, 246, 0.28);
    border-color: rgba(139, 92, 246, 0.5);
    color: #fff;
    transform: translateY(-1px);
}

/* ═══ MAIN LAYOUT ═══ */
.main-layout {
    display: flex;
    height: calc(100vh - 56px);
}

.timer-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    gap: 40px;
    min-width: 0;
    transition: background 0.4s;
}

/* ═══ RING SVG ═══ */
.ring-svg {
    position: absolute;
    width: min(460px, 55vh, calc(100vw - 420px));
    height: min(460px, 55vh, calc(100vw - 420px));
    transform: rotate(-90deg);
    pointer-events: none;
}

.ring-bg {
    fill: none;
    stroke: rgba(139, 92, 246, 0.08);
    stroke-width: 8;
}

.ring-progress {
    fill: none;
    stroke: var(--timer-color, #8b5cf6);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 1099.56;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.3s linear, stroke 0.4s;
    filter: drop-shadow(0 0 8px var(--timer-color, rgba(139, 92, 246, 0.4)));
}

/* ═══ TIMER DISPLAY ═══ */
.timer-display {
    text-align: center;
    z-index: 2;
}

.timer-digits {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.digit-input {
    width: 130px;
    font-family: 'Fredoka', monospace;
    font-size: 96px;
    font-weight: 700;
    color: var(--timer-color, #e2e8f0);
    background: transparent;
    border: 2px solid transparent;
    border-radius: 12px;
    text-align: center;
    padding: 4px;
    transition: all 0.3s;
    -moz-appearance: textfield;
    appearance: textfield;
}

.digit-input::-webkit-outer-spin-button,
.digit-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.digit-input:hover {
    border-color: rgba(139, 92, 246, 0.25);
    background: rgba(139, 92, 246, 0.04);
}

.digit-input:focus {
    outline: none;
    border-color: var(--timer-color, #8b5cf6);
    background: rgba(139, 92, 246, 0.08);
}

.digit-input.readonly {
    pointer-events: none;
    border-color: transparent !important;
    background: transparent !important;
}

.digit-sep {
    font-size: 80px;
    font-weight: 700;
    color: rgba(139, 92, 246, 0.4);
    padding-bottom: 8px;
    user-select: none;
}

.timer-label {
    font-size: 16px;
    color: #64748b;
    margin-top: 8px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* ═══ CONTROLS ═══ */
.timer-controls {
    display: flex;
    gap: 16px;
    z-index: 2;
}

.ctrl-btn {
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 22px;
    color: white;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.ctrl-btn:hover {
    transform: translateY(-2px) scale(1.05);
}

.ctrl-btn:active {
    transform: translateY(0) scale(0.98);
}

.ctrl-btn.start,
.ctrl-btn.resume {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    box-shadow: 0 4px 20px rgba(34, 197, 94, 0.35);
}

.ctrl-btn.start:hover,
.ctrl-btn.resume:hover {
    box-shadow: 0 6px 25px rgba(34, 197, 94, 0.5);
}

.ctrl-btn.pause {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.35);
}

.ctrl-btn.pause:hover {
    box-shadow: 0 6px 25px rgba(245, 158, 11, 0.5);
}

.ctrl-btn.reset {
    background: linear-gradient(135deg, #475569, #334155);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.ctrl-btn.reset:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.ctrl-btn.lap {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
}

.ctrl-btn.lap:hover {
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

/* ═══ CONTROLS PANEL ═══ */
.controls-panel {
    width: 360px;
    background: rgba(20, 22, 39, 0.95);
    border-left: 1px solid rgba(139, 92, 246, 0.12);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.controls-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.controls-scroll::-webkit-scrollbar {
    width: 5px;
}

.controls-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.controls-scroll::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.25);
    border-radius: 3px;
}

/* ═══ SECTIONS ═══ */
.section {
    margin-bottom: 24px;
}

.section h3 {
    font-size: 15px;
    font-weight: 600;
    color: #c4b5fd;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section h3 i {
    font-size: 14px;
    opacity: 0.7;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    margin-bottom: 0;
}

.sub-section {
    margin-bottom: 16px;
}

.sub-section label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 8px;
}

/* ═══ MODE TOGGLE ═══ */
.mode-toggle {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    padding: 4px;
    border: 1px solid rgba(139, 92, 246, 0.12);
}

.mode-btn {
    flex: 1;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #94a3b8;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mode-btn:hover {
    color: #e2e8f0;
    background: rgba(139, 92, 246, 0.08);
}

.mode-btn.active {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
}

/* ═══ PRESETS ═══ */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.preset-btn {
    padding: 10px 6px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 10px;
    color: #a5b4fc;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.4);
    color: #fff;
    transform: translateY(-1px);
}

.preset-btn:active {
    transform: translateY(0);
}

/* ═══ COLOR SWATCHES ═══ */
.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

/* ═══ ALARM PICKER ═══ */
.alarm-picker {
    display: flex;
    gap: 8px;
    align-items: center;
}

.alarm-select {
    flex: 1;
    padding: 9px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 8px;
    color: #e2e8f0;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.2s;
    appearance: auto;
}

.alarm-select:focus {
    outline: none;
    border-color: #8b5cf6;
}

.alarm-select option {
    background: #1a1d35;
    color: #e2e8f0;
}

/* ═══ AUDIO ═══ */
.audio-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    color: #c4b5fd;
    transition: transform 0.2s;
}

.icon-btn:hover {
    transform: scale(1.15);
}

.volume-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(139, 92, 246, 0.25);
    border-radius: 2px;
    outline: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #8b5cf6;
    border-radius: 50%;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #8b5cf6;
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

/* ═══ TOGGLES ═══ */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    gap: 12px;
}

.toggle-row span:first-child {
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
}

.toggle-input {
    display: none;
}

.toggle-switch {
    width: 42px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    position: relative;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: transform 0.3s;
}

.toggle-input:checked+.toggle-switch {
    background: var(--timer-color, #8b5cf6);
}

.toggle-input:checked+.toggle-switch::after {
    transform: translateX(18px);
}

/* ═══ LAPS ═══ */
.laps-list {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.laps-list::-webkit-scrollbar {
    width: 4px;
}

.laps-list::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.2);
    border-radius: 2px;
}

.laps-empty {
    text-align: center;
    color: #475569;
    font-size: 13px;
    padding: 20px 0;
    font-style: italic;
}

.lap-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.025);
    border-radius: 8px;
    font-size: 13px;
}

.lap-item .lap-num {
    color: #8b5cf6;
    font-weight: 700;
    min-width: 40px;
}

.lap-item .lap-time {
    color: #e2e8f0;
    font-weight: 600;
    font-family: 'Fredoka', monospace;
}

.lap-item .lap-diff {
    color: #64748b;
    font-size: 11px;
}

.text-btn {
    background: none;
    border: none;
    color: #64748b;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}

.text-btn:hover {
    color: #e2e8f0;
}

/* ═══ FINISH OVERLAY ═══ */
.finish-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.finish-card {
    text-align: center;
    animation: finishBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes finishBounce {
    from { transform: scale(0.6); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.finish-icon {
    font-size: 72px;
    color: var(--timer-color, #8b5cf6);
    margin-bottom: 20px;
    animation: bellShake 0.6s ease-in-out infinite alternate;
}

@keyframes bellShake {
    0% { transform: rotate(-10deg); }
    100% { transform: rotate(10deg); }
}

.finish-text {
    font-size: 56px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
    margin-bottom: 30px;
}

.finish-dismiss {
    padding: 14px 40px;
    background: var(--timer-color, #8b5cf6);
    color: white;
    border: none;
    border-radius: 14px;
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.finish-dismiss:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(139, 92, 246, 0.5);
}

/* Flash animation */
@keyframes flashRed {
    0%, 100% { background: #0c0e1a; }
    50% { background: rgba(239, 68, 68, 0.15); }
}

.timer-section.flashing {
    animation: flashRed 0.5s ease-in-out 6;
}

/* ═══ FULLSCREEN ═══ */
.timer-section:fullscreen {
    background: #0c0e1a;
}

.timer-section:fullscreen .mobile-settings-btn {
    display: none !important;
}

.fullscreen-exit-btn {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 10px;
    color: #c4b5fd;
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s;
}

.fullscreen-exit-btn:hover {
    background: rgba(139, 92, 246, 0.3);
    color: #fff;
}

.timer-section:fullscreen .fullscreen-exit-btn {
    display: flex;
}

/* ═══ MOBILE ELEMENTS (hidden on desktop) ═══ */
.mobile-settings-btn {
    display: none;
}

.panel-backdrop {
    display: none;
}

.panel-mobile-header {
    display: none;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .main-layout {
        flex-direction: column;
        overflow-y: auto;
        height: auto;
        min-height: calc(100vh - 56px);
    }

    .timer-section {
        padding: 30px 20px;
        gap: 24px;
        min-height: 0;
    }

    .ring-svg {
        width: min(320px, 55vw);
        height: min(320px, 55vw);
    }

    .digit-input {
        width: 80px;
        font-size: 56px;
    }

    .digit-sep {
        font-size: 48px;
    }

    .controls-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid rgba(139, 92, 246, 0.12);
    }

    .finish-text {
        font-size: 40px;
    }

    .presets-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 640px) {
    body {
        overflow: hidden;
    }

    .main-layout {
        flex-direction: column;
        height: calc(100vh - 56px);
        overflow: hidden;
    }

    /* Timer fills the screen */
    .timer-section {
        flex: 1;
        padding: 20px 16px 60px;
        gap: 16px;
        min-height: 0;
        justify-content: center;
    }

    .ring-svg {
        width: min(280px, 65vw, 45vh);
        height: min(280px, 65vw, 45vh);
    }

    .digit-input {
        width: 68px;
        font-size: 48px;
        padding: 6px 2px;
        border-radius: 10px;
    }

    .digit-sep {
        font-size: 40px;
    }

    .timer-label {
        font-size: 13px;
    }

    /* Push settings button to the bottom, out of the ring area */
    .mobile-settings-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 20px;
        background: rgba(139, 92, 246, 0.12);
        border: 1px solid rgba(139, 92, 246, 0.25);
        border-radius: 12px;
        color: #c4b5fd;
        font-family: inherit;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        z-index: 2;
        transition: all 0.2s;
        position: absolute;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
    }

    .mobile-settings-btn:active {
        background: rgba(139, 92, 246, 0.25);
    }

    .top-bar-back span {
        display: none;
    }

    /* Panel backdrop */
    .panel-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 90;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }

    .panel-backdrop.visible {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    /* Controls panel as bottom drawer */
    .controls-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 75vh;
        border-left: none;
        border-top: 1px solid rgba(139, 92, 246, 0.2);
        border-radius: 20px 20px 0 0;
        z-index: 100;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .controls-panel.open {
        transform: translateY(0);
    }

    /* Mobile panel header */
    .panel-mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 4px 0 12px;
        border-bottom: 1px solid rgba(139, 92, 246, 0.1);
        margin-bottom: 16px;
    }

    .panel-mobile-header h3 {
        font-size: 18px;
        font-weight: 700;
        color: #e2e8f0;
    }

    .panel-close-btn {
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.06);
        border: none;
        border-radius: 50%;
        color: #94a3b8;
        font-size: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }

    .panel-close-btn:active {
        background: rgba(255, 255, 255, 0.12);
        color: #e2e8f0;
    }

    .controls-scroll {
        padding: 20px 20px 32px;
        max-height: 75vh;
        overflow-y: auto;
    }

    /* Better touch targets */
    .preset-btn {
        padding: 12px 8px;
        font-size: 14px;
        min-height: 44px;
    }

    .presets-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .color-swatch {
        width: 36px;
        height: 36px;
    }

    .mode-btn {
        padding: 12px;
        font-size: 14px;
        min-height: 44px;
    }

    .alarm-select {
        padding: 12px;
        font-size: 14px;
        min-height: 44px;
    }

    .toggle-row {
        min-height: 44px;
    }

    .ctrl-btn {
        width: 60px;
        height: 60px;
        font-size: 20px;
    }

    /* Finish overlay */
    .finish-text {
        font-size: 36px;
    }

    .finish-icon {
        font-size: 56px;
    }

    .finish-dismiss {
        padding: 12px 32px;
        font-size: 16px;
    }
}

@media (max-width: 380px) {
    .digit-input {
        width: 56px;
        font-size: 38px;
    }

    .digit-sep {
        font-size: 32px;
    }

    .ring-svg {
        width: min(230px, 60vw, 40vh);
        height: min(230px, 60vw, 40vh);
    }

    .ctrl-btn {
        width: 52px;
        height: 52px;
        font-size: 18px;
    }

    .presets-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .preset-btn {
        padding: 10px 4px;
        font-size: 13px;
    }

    .finish-text {
        font-size: 28px;
    }

    .finish-icon {
        font-size: 48px;
    }

    .finish-dismiss {
        padding: 10px 28px;
        font-size: 15px;
    }
}
