/* Global Variables & Reset */
:root {
    --bg-color: #09090b;
    --text-color: #e4e4e7;
    --text-muted: #a1a1aa;

    --card-bg: #18181b;
    --card-bg-hover: #27272a;

    --accent-color: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.4);

    --panel-bg: rgba(24, 24, 27, 0.75);
    --border-color: rgba(255, 255, 255, 0.1);

    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Flip Dimensions */
    --u-width: 15vw;
    --u-height: 15vw;
    --u-radius: 16px;
    --u-font-size: 10vw;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

body.theme-light {
    --bg-color: #f4f4f5;
    --text-color: #18181b;
    --text-muted: #71717a;
    --card-bg: #ffffff;
    --card-bg-hover: #fafafa;
    --accent-color: #4f46e5;
    --accent-glow: rgba(79, 70, 229, 0.2);
    --panel-bg: rgba(255, 255, 255, 0.85);
    --border-color: rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    width: 100vw;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    /* Allow scrolling if content is too tall */
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background-color 0.5s var(--ease-out), color 0.5s;
}

/* Background Ambient Glow */
body::before {
    content: '';
    position: absolute;
    width: 120vw;
    height: 120vw;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 60%);
    opacity: 0.15;
    top: -50%;
    left: -50%;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

/* Layout */
.app-container {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    max-width: 1600px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* Stack from top instead of spacing out */
    padding: 0 1rem;
    /* Remove top/bottom padding */
    gap: 0;
    /* Remove gap between header and main for tighter fit */
    /* Control spacing between header, main, footer */
}

/* Header */
/* Header */
/* Header */
.top-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    height: auto;
    padding: 1rem 0;
    /* Add some padding for spacing */
    flex-shrink: 0;
    width: 100%;
}

.logo {
    display: flex;
    align-items: center;
    /* Removed the ::before pseudo-element (blue ball) */
}

.top-controls {
    display: flex;
    gap: 12px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn:hover {
    background: var(--card-bg-hover);
    border-color: var(--border-color);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: translateY(1px);
}

/* Main Content (Centered) */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* Align content to top, right below header */
    align-items: center;
    width: 100%;
    margin-top: 0;
    padding-top: 0;
    gap: 1rem;
    /* Reduced gap between elements */
}

.brand-logo {
    height: 60px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    transition: transform 0.3s ease;
    margin: 0.5rem 0;
}

.brand-logo:hover {
    transform: scale(1.05);
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.2));
}

/* FLIP CLOCK STYLES */
.flip-clock-wrapper {
    display: flex;
    gap: 2vw;
    align-items: center;
    justify-content: center;
}

.flip-unit {
    position: relative;
    width: var(--u-width);
    height: var(--u-height);
    background: var(--card-bg);
    border-radius: var(--u-radius);
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        inset 0 1px 1px rgba(255, 255, 255, 0.05);

    font-size: var(--u-font-size);
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--text-color);
    perspective: 2000px;
    letter-spacing: -0.06em;
}

/* The Cards */
.upper,
.lower,
.flip-card {
    width: 100%;
    height: 50%;
    overflow: hidden;
    position: absolute;
    left: 0;
    right: 0;
    background: var(--card-bg);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
}

/* Static Cards */
.upper {
    top: 0;
    align-items: flex-end;
    border-radius: var(--u-radius) var(--u-radius) 0 0;
    border-bottom: 2px solid rgba(0, 0, 0, 0.3);
    z-index: 1;
}

.upper span {
    transform: translateY(50%);
}

.lower {
    bottom: 0;
    align-items: flex-start;
    border-radius: 0 0 var(--u-radius) var(--u-radius);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 1;
}

.lower span {
    transform: translateY(-50%);
}

/* Animating Cards */
.flip-card {
    z-index: 2;
    transform-style: preserve-3d;
}

.flip-card.front {
    top: 0;
    align-items: flex-end;
    border-radius: var(--u-radius) var(--u-radius) 0 0;
    transform-origin: bottom;
    transform: rotateX(0deg);
}

.flip-card.front span {
    transform: translateY(50%);
}

.flip-card.back {
    bottom: 0;
    align-items: flex-start;
    border-radius: 0 0 var(--u-radius) var(--u-radius);
    transform-origin: top;
    transform: rotateX(180deg);
}

.flip-card.back span {
    transform: translateY(-50%);
}

.flip-unit,
.upper,
.lower,
.flip-card {
    line-height: normal;
}


/* Animation Classes */
.flip-unit.flipping .flip-card.front {
    animation: flipDownFront 0.6s cubic-bezier(0.15, 0.45, 0.28, 1) forwards;
}

.flip-unit.flipping .flip-card.back {
    animation: flipDownBack 0.6s cubic-bezier(0.15, 0.45, 0.28, 1) forwards;
}

@keyframes flipDownFront {
    0% {
        transform: rotateX(0deg);
    }

    100% {
        transform: rotateX(-180deg);
    }
}

@keyframes flipDownBack {
    0% {
        transform: rotateX(180deg);
    }

    100% {
        transform: rotateX(0deg);
    }
}

/* Controls Bottom Area */
.controls-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    /* Reduced gap slightly */
}

.presets {
    display: flex;
    gap: 12px;
    background: var(--card-bg);
    padding: 6px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

.preset-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.preset-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.preset-btn.active {
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.preset-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    opacity: 0.7;
    margin-top: -12px;
    font-weight: 500;
}

.actions {
    display: flex;
    gap: 24px;
}

.action-btn {
    border: none;
    height: 56px;
    padding: 0 48px;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    text-transform: uppercase;
}

.action-btn.primary {
    background: var(--text-color);
    color: var(--bg-color);
}

.action-btn.primary:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 20px -4px rgba(255, 255, 255, 0.15);
}

.action-btn.primary:active {
    transform: scale(0.97);
}

.action-btn.secondary {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-muted);
}

.action-btn.secondary:hover:not(:disabled) {
    border-color: var(--text-color);
    color: var(--text-color);
}

.action-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* Premium Modals & Float Panels */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s var(--ease-out);
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    width: 380px;
    padding: 32px;
    border-radius: 24px;
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95) translateY(10px);
    transition: transform 0.3s var(--ease-out);
}

.modal-overlay:not(.hidden) .modal-content {
    transform: scale(1) translateY(0);
}

.float-panel {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 320px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    backdrop-filter: blur(16px);
    box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.4);
    z-index: 90;

    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    pointer-events: none;
    transition: all 0.25s var(--ease-out);
}

.float-panel.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#lofi-player-container {
    position: fixed;
    top: 80px;
    right: 80px;
    bottom: auto;
    left: auto;

    /* Apply float panel style rules locally since .float-panel isn't directly on it in HTML yet */
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    backdrop-filter: blur(16px);
    box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.4);
    width: 320px;

    /* Animation base state */
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    pointer-events: none;
    transition: all 0.25s var(--ease-out);

    display: flex;
    flex-direction: column;
    gap: 16px;
}

#lofi-player-container.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    /* remove display:none since we toggle 'hidden' class */
}

/* Headers in Panels */
.modal-header,
.lofi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    font-size: 1.1rem;
    font-weight: 700;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-color);
}

/* Inputs & Toggles */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.time-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.time-input-group input {
    width: 56px;
    height: 56px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-color);
    font-size: 1.25rem;
    text-align: center;
    font-family: var(--font-mono);
}

.time-input-group input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: rgba(0, 0, 0, 0.4);
}

select {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    font-family: var(--font-main);
}

input[type="range"] {
    width: 100px;
    accent-color: var(--accent-color);
}

.custom-lofi-input {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-color);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--card-bg);
    color: var(--text-color);
    padding: 12px 24px;
    border-radius: 50px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s var(--ease-out);
    z-index: 200;
}

.toast:not(.hidden) {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Credits Footer */
.credits-footer {
    width: 100%;
    text-align: center;
    font-size: 0.65rem;
    /* ~10px very small */
    color: var(--text-muted);
    opacity: 0.4;
    margin-top: 1rem;
    font-weight: 400;
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --u-width: 22vw;
        --u-height: 22vw;
        --u-font-size: 16vw;
    }

    .app-container {
        padding: 1rem;
    }

    .flip-clock-wrapper {
        gap: 8px;
    }

    .actions {
        width: 100%;
    }

    .action-btn {
        flex: 1;
        padding: 0;
    }

    #lofi-player-container {
        right: 16px;
        left: 16px;
        top: 70px;
        width: auto;
    }
}

/* Utility to ensure elements are truly hidden */
.hidden {
    display: none !important;
}

/* Utility to ensure elements are truly hidden */
.hidden {
    display: none !important;
}

/* Exam Presets */
.exam-presets {
    margin-top: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 0;
}

.exam-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    height: auto;
    padding: 10px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.exam-btn span {
    font-size: 0.75rem;
    opacity: 0.6;
    font-weight: 400;
}

.exam-btn:hover {
    border-color: var(--accent-color);
}

.exam-btn.active {
    background: var(--accent-color);
    color: white;
}

.exam-btn.active span {
    opacity: 0.9;
}

/* Analog Clock */
.analog-clock {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    animation: fadeIn 0.5s var(--ease-out);
}

.clock-face {
    width: 360px;
    /* Reset to reasonable size fitting screen, user previously complained about overflow */
    height: 360px;

    /* Single consolidated background: White face + Ticks */
    background:
        /* Cover center (white) leaving only edges for ticks */
        radial-gradient(circle at center, #fff 90%, transparent 90.5%),
        /* Hour Ticks (Black) */
        repeating-conic-gradient(from -0.5deg, #000 0deg 1deg, transparent 1deg 30deg),
        /* Minute Ticks (Grey) */
        repeating-conic-gradient(from -0.25deg, #a1a1aa 0deg 0.5deg, transparent 0.5deg 6deg);

    background-color: #fff;
    /* Fallback */

    border: 12px solid #18181b;
    border-radius: 50%;
    position: relative;
    box-shadow:
        0 15px 30px rgba(0, 0, 0, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.1);
}

.clock-logo {
    position: absolute;
    top: 30%;
    /* Position in the upper half */
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    /* Small size */
    height: auto;
    object-fit: contain;
    opacity: 0.8;
    z-index: 5;
    pointer-events: none;
}

.center-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    background: #000;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.hand {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform-origin: bottom center;
    z-index: 10;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
    transition: transform 0.05s cubic-bezier(0.4, 2.3, 0.3, 1);
    /* Bouncy tick */
}

/* Hour Hand: Thicker, Shorter */
.hour-hand {
    width: 10px;
    height: 90px;
    margin-left: -5px;
    background: #000;
    /* Tapered look via clip-path or border, simple rect is okay for "modern" */
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

/* Minute Hand: Thinner, Longer */
.min-hand {
    width: 6px;
    height: 130px;
    margin-left: -3px;
    background: #333;
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
}

/* Second Hand: Red, Thin, with Tail */
.second-hand {
    width: 2px;
    height: 140px;
    margin-left: -1px;
    background: #000;
    z-index: 15;
    transform-origin: bottom center;
    bottom: 50%;
    transition: transform 0.05s linear;
    /* Smooth sweep often preferred for seconds or simple tick */
}

.number {
    position: absolute;
    width: 100%;
    height: 100%;
    text-align: center;
    color: #000;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-main);
    padding-top: 10px;
}

/* Positioning Numbers */
.number {
    position: absolute;
    top: 48.5%;
    /* Slightly further up */
    left: 50%;
    width: 30px;
    height: 30px;
    margin-left: -15px;
    margin-top: -15px;
    text-align: center;
    line-height: 30px;
    color: #000;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-main);
    z-index: 5;
}

/* Positioning Numbers - Inside the clock face */
/* Desktop: Clock 360px -> Radius 180px.
   Moving out towards edge again. 135px was previous value.
*/
.n1 {
    transform: rotate(30deg) translate(0, -150px) rotate(-30deg);
}

.n2 {
    transform: rotate(60deg) translate(0, -150px) rotate(-60deg);
}

.n3 {
    transform: rotate(90deg) translate(0, -150px) rotate(-90deg);
}

.n4 {
    transform: rotate(120deg) translate(0, -150px) rotate(-120deg);
}

.n5 {
    transform: rotate(150deg) translate(0, -150px) rotate(-150deg);
}

.n6 {
    transform: rotate(180deg) translate(0, -150px) rotate(-180deg);
}

.n7 {
    transform: rotate(210deg) translate(0, -150px) rotate(-210deg);
}

.n8 {
    transform: rotate(240deg) translate(0, -150px) rotate(-240deg);
}

.n9 {
    transform: rotate(270deg) translate(0, -150px) rotate(-270deg);
}

.n10 {
    transform: rotate(300deg) translate(0, -150px) rotate(-300deg);
}

.n11 {
    transform: rotate(330deg) translate(0, -150px) rotate(-330deg);
}

.n12 {
    transform: rotate(0deg) translate(0, -150px) rotate(0deg);
}

/* Clock Mode State */
body.clock-mode .controls-area {
    display: none !important;
}

body.clock-mode #timer-display {
    transform: scale(0.3);
    /* Smaller symbolic size */
    opacity: 0.8;
    margin-top: -4vh;
    /* Move closer to clock */
    order: 10;
    pointer-events: none;
    /* Make it just a display */
}

body.clock-mode .main-content {
    justify-content: flex-start;
    /* Align to top in clock mode too */
    padding-top: 10px;
    gap: 0;
}

/* Ensure controls are hidden in clock mode for both mobile and desktop */
@media (max-width: 768px) {
    .clock-face {
        width: 250px;
        height: 250px;
    }

    /* Adjust radius for smaller clock (Radius 125px -> Numbers at ~105px) */
    .n1 {
        transform: rotate(30deg) translate(0, -105px) rotate(-30deg);
    }

    .n2 {
        transform: rotate(60deg) translate(0, -105px) rotate(-60deg);
    }

    .n3 {
        transform: rotate(90deg) translate(0, -105px) rotate(-90deg);
    }

    .n4 {
        transform: rotate(120deg) translate(0, -105px) rotate(-120deg);
    }

    .n5 {
        transform: rotate(150deg) translate(0, -105px) rotate(-150deg);
    }

    .n6 {
        transform: rotate(180deg) translate(0, -105px) rotate(-180deg);
    }

    .n7 {
        transform: rotate(210deg) translate(0, -105px) rotate(-210deg);
    }

    .n8 {
        transform: rotate(240deg) translate(0, -105px) rotate(-240deg);
    }

    .n9 {
        transform: rotate(270deg) translate(0, -105px) rotate(-270deg);
    }

    .n10 {
        transform: rotate(300deg) translate(0, -105px) rotate(-300deg);
    }

    .n11 {
        transform: rotate(330deg) translate(0, -105px) rotate(-330deg);
    }

    .n12 {
        transform: rotate(0deg) translate(0, -105px) rotate(0deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Brand Container in Main Content */
.brand-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    animation: fadeIn 0.8s var(--ease-out);
}

.brand-logo-large {
    height: 180px;
    /* 3x original 60px size */
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.2));
    transition: transform 0.4s var(--ease-out);
}

.brand-logo-large:hover {
    transform: scale(1.05) rotate(2deg);
    filter: drop-shadow(0 15px 30px rgba(0, 0, 0, 0.3));
}

.app-title {
    margin-top: 1rem;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    background: linear-gradient(135deg, var(--text-color) 0%, var(--text-muted) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Update flip clock wrapper to have less top margin since logo is huge */
.flip-clock-wrapper {
    margin-top: 1rem;
}

/* Responsive adjustments for the large logo */
@media (max-width: 768px) {
    .brand-logo-large {
        height: 120px;
    }

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