/* Core Reset & Variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 0: Dark (Default) */
    --bg-color: #050505;
    --card-bg: #111111;
    --text-primary: #ffffff;
    --text-secondary: #888888;
    --card-shadow: rgba(0, 0, 0, 0.5);
    --card-top-shade: rgba(0, 0, 0, 0.6);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #222222;
    --btn-bg-hover: #333333;
    --icon-color: #444444;
}

/* 1: Light */
html.theme-1 {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-primary: #111111;
    --text-secondary: #666666;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --card-top-shade: rgba(0, 0, 0, 0.05);
    --card-bottom-light: rgba(0, 0, 0, 0.02);
    --btn-bg: #e4e6e9;
    --btn-bg-hover: #d8dadf;
    --icon-color: #a0a0a0;
}

/* 2: Blue Depth */
html.theme-2 {
    --bg-color: #0f172a;
    /* slate-900 */
    --card-bg: #1e293b;
    /* slate-800 */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.5);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #334155;
    --btn-bg-hover: #475569;
    --icon-color: #64748b;
}

/* 3: Forest Green */
html.theme-3 {
    --bg-color: #022c22;
    /* emerald-950 */
    --card-bg: #064e3b;
    /* emerald-900 */
    --text-primary: #ecfdf5;
    --text-secondary: #6ee7b7;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.5);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #047857;
    --btn-bg-hover: #059669;
    --icon-color: #34d399;
}

/* 4: Crimson Red */
html.theme-4 {
    --bg-color: #450a0a;
    /* red-950 */
    --card-bg: #7f1d1d;
    /* red-900 */
    --text-primary: #fef2f2;
    --text-secondary: #fca5a5;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.5);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #991b1b;
    --btn-bg-hover: #b91c1c;
    --icon-color: #f87171;
}

/* 5: Deep Purple */
html.theme-5 {
    --bg-color: #2e1065;
    /* violet-950 */
    --card-bg: #4c1d95;
    /* violet-900 */
    --text-primary: #f5f3ff;
    --text-secondary: #c4b5fd;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.5);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #5b21b6;
    --btn-bg-hover: #6d28d9;
    --icon-color: #a78bfa;
}

/* 6: Sunset Orange */
html.theme-6 {
    --bg-color: #431407;
    /* orange-950 */
    --card-bg: #7c2d12;
    /* orange-900 */
    --text-primary: #fff7ed;
    --text-secondary: #fdba74;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.5);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #9a3412;
    --btn-bg-hover: #c2410c;
    --icon-color: #fb923c;
}

/* 7: Deep Teal */
html.theme-7 {
    --bg-color: #134e4a;
    /* teal-950 */
    --card-bg: #0f766e;
    /* teal-700 */
    --text-primary: #f0fdfa;
    --text-secondary: #5eead4;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.4);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #115e59;
    --btn-bg-hover: #0f766e;
    --icon-color: #2dd4bf;
}

/* 8: Hot Pink */
html.theme-8 {
    --bg-color: #831843;
    /* pink-950 */
    --card-bg: #be185d;
    /* pink-700 */
    --text-primary: #fdf2f8;
    --text-secondary: #f9a8d4;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --card-top-shade: rgba(0, 0, 0, 0.4);
    --card-bottom-light: rgba(255, 255, 255, 0.05);
    --btn-bg: #9d174d;
    --btn-bg-hover: #be185d;
    --icon-color: #f472b6;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
}

/* Progress Bar */
#progress-bar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background-color: rgba(255, 255, 255, 0.05);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#progress-bar-container.active {
    opacity: 1;
}

#progress-bar {
    height: 100%;
    width: 100%;
    background-color: var(--text-primary);
    transform-origin: left;
    transition: width 1s linear, background-color 0.4s ease;
}

.app-container {
    max-width: 1000px;
    width: 100%;
    min-height: calc(100vh - 40px);
    /* Account for body padding */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 20px;
}

.title {
    font-size: 2.5rem;
    font-weight: 500;
    letter-spacing: -0.5px;
}

/* Only dark theme 0 gets gradient title */
html:not([class^="theme-"]) .title,
html.theme-0 .title {
    background: linear-gradient(90deg, #ffffff, #888888);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.date-display {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    margin: 0 auto;
    transition: background 0.3s, border 0.3s, color 0.3s;
}

html.theme-1 .date-display {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

/* View Control */
.main-content {
    width: 100%;
    position: relative;
    flex: 1;
    /* Allow to grow and push footer down */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 480px;
    /* Force minimum height so card clusters don't cause vertical shifting */
}

.view-section {
    position: absolute;
    /* Keep them stacked so they don't shift the height */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    display: flex;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.view-section.active {
    opacity: 1;
    pointer-events: auto;
    position: relative;
    top: auto;
    left: auto;
    transform: none;
}

/* Timer layout */
.timer-container {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 30px;
    justify-items: center;
    width: 100%;
}

.timer-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Clock specifics */
.clock-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 40px;
    max-width: 600px;
    margin: 0 auto;
}

/* Flip Card design */
.card {
    position: relative;
    width: clamp(70px, 11vw, 120px);
    height: clamp(90px, 14vw, 140px);
    font-size: clamp(2.5rem, 5vw, 5rem);
    font-weight: 600;
    border-radius: 12px;
    perspective: 1000px;
    box-shadow: 0 10px 30px var(--card-shadow);
    background-color: var(--card-bg);
    transition: background-color 0.4s ease, box-shadow 0.4s ease;
}

.card-large {
    width: clamp(140px, 25vw, 240px);
    height: clamp(160px, 30vw, 280px);
    font-size: clamp(4rem, 12vw, 10rem);
}

.card-large.card-three-digits {
    font-size: clamp(2.5rem, 8vw, 7rem);
    /* Scale down text to fit "999" */
}

.modifier-label {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-secondary);
    z-index: 10;
    letter-spacing: 1px;
}

.half {
    position: absolute;
    left: 0;
    width: 100%;
    height: 50%;
    background: var(--card-bg);
    color: var(--text-primary);
    overflow: hidden;
    backface-visibility: hidden;
    transform-style: preserve-3d;
    transition: background-color 0.4s ease, color 0.4s ease;
}

.half::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    z-index: 10;
}

.top::before,
.top-flip::before {
    bottom: 0;
    background: var(--card-top-shade);
}

.bottom::before,
.bottom-flip::before {
    top: 0;
    background: var(--card-bottom-light);
}

.half::after {
    content: attr(data-value);
    position: absolute;
    left: 0;
    width: 100%;
    height: 200%;
    display: flex;
    justify-content: center;
    align-items: center;
    letter-spacing: -2px;
}

.top,
.top-flip {
    top: 0;
    transform-origin: bottom;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.top::after,
.top-flip::after {
    top: 0;
}

.bottom,
.bottom-flip {
    bottom: 0;
    transform-origin: top;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

.bottom::after,
.bottom-flip::after {
    bottom: 0;
}

/* Z-indexing for animation overlaps */
.top {
    z-index: 1;
}

.bottom {
    z-index: 1;
}

.top-flip {
    z-index: 2;
    animation: flipTop 0.3s ease-in forwards;
}

.bottom-flip {
    z-index: 2;
    transform: rotateX(90deg);
    animation: flipBottom 0.3s ease-out 0.3s forwards;
}

@keyframes flipTop {
    to {
        transform: rotateX(-90deg);
    }
}

@keyframes flipBottom {
    to {
        transform: rotateX(0deg);
    }
}

.label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 500;
}

/* Action button & Footer */
.footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
    gap: 30px;
    padding-bottom: 20px;
}

.controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--icon-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, transform 0.1s ease;
    font-family: inherit;
    padding: 5px;
    text-decoration: none;
}

.icon-btn:hover,
.icon-btn.active-icon {
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.95);
}

.text-icon {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 1px;
    padding-right: 5px;
}

/* Idle UI Hiding */
.header,
.footer {
    transition: opacity 0.5s ease, transform 0.5s ease;
}

body.idle .header,
body.idle .footer {
    opacity: 0;
    pointer-events: none;
}

body.idle .header {
    transform: translateY(-10px);
}

body.idle .footer {
    transform: translateY(10px);
}

/* Responsiveness */
@media (max-width: 900px) {
    .timer-container {
        grid-template-columns: repeat(3, 1fr);
        row-gap: 40px;
    }

    .clock-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .footer {
        flex-direction: column-reverse;
        justify-content: center;
        gap: 20px;
    }

    .app-button {
        margin: 0 auto;
    }
}

@media (max-width: 480px) {
    .timer-container {
        grid-template-columns: repeat(2, 1fr);
        column-gap: 20px;
        row-gap: 30px;
    }

    .clock-container {
        gap: 20px;
    }

    .title {
        font-size: 1.8rem;
    }
}

/* Custom Timer Elements */
.control-button {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--icon-color);
    padding: 10px 40px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-family: inherit;
    margin-top: 10px;
}

.control-button:hover {
    background: var(--text-primary);
    color: var(--card-bg);
}

/* Settings Popup */
.settings-popup {
    position: absolute;
    bottom: calc(100% + 20px);
    right: 0;
    background: var(--btn-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--card-shadow);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 100;
    min-width: 240px;
    text-align: left;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: all 0.2s ease;
}

.settings-popup.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.popup-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.popup-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.popup-label {
    font-size: 0.95rem;
    font-weight: 500;
}

.popup-label-small {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.popup-input {
    width: 60px;
    background: transparent;
    border: 1px solid var(--icon-color);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: inherit;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.3s ease;
}

select.popup-input {
    width: auto;
    text-align: left;
}

input[type="date"].popup-input {
    width: 130px;
}

.popup-input:focus {
    border-color: var(--text-primary);
}

.preset-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 5px;
}

.preset-btn {
    background: var(--bg-color);
    border: 1px solid var(--icon-color);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 6px 0;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.preset-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Theme Picker Popup Matrix */
.theme-popup {
    position: absolute;
    bottom: calc(100% + 20px);
    right: -20px;
    background: #2a2a2a;
    /* match reference image dark bg */
    padding: 24px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: all 0.2s ease;
}

.theme-popup.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s;
}

.color-dot:hover {
    transform: scale(1.15);
}

.color-dot.active-theme {
    box-shadow: 0 0 0 2px #2a2a2a, 0 0 0 4px var(--text-primary);
}

/* The actual dot preview colors from the screenshot */
.mix-dark {
    background-color: #111111;
}

/* theme-0 card-bg */
.mix-light {
    background-color: #ffffff;
}

/* theme-1 card-bg */
.mix-blue {
    background-color: #1e293b;
}

/* theme-2 card-bg */
.mix-green {
    background-color: #064e3b;
}

/* theme-3 card-bg */
.mix-red {
    background-color: #7f1d1d;
}

/* theme-4 card-bg */
.mix-purple {
    background-color: #4c1d95;
}

/* theme-5 card-bg */
.mix-orange {
    background-color: #7c2d12;
}

/* theme-6 card-bg */
.mix-teal {
    background-color: #0f766e;
}

/* theme-7 card-bg */
.mix-pink {
    background-color: #be185d;
}

/* theme-8 card-bg */

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

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

.slider,
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--icon-color);
    transition: .3s;
    border-radius: 24px;
}

.slider:before,
.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: var(--bg-color);
    transition: .3s;
    border-radius: 50%;
}

.toggle-switch input:checked+.slider,
.toggle-switch input:checked+.toggle-slider {
    background-color: var(--text-secondary);
}

.toggle-switch input:checked+.slider:before,
.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(20px);
    background-color: var(--text-primary);
}