/**
 * Time Flow - Zhween Classroom Tools
 * Clean, brand-consistent timer & stopwatch
 */

/* Override min-height from base template to prevent gap */
.tool-page-wrapper:has(.timeflow) {
    min-height: 0 !important;
}

.tool-content-area:has(.timeflow) {
    min-height: 0 !important;
}

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

:root {
    --tf-primary: #15aebf;
    --tf-primary-light: #4ecdc4;
    --tf-primary-dark: #0e9bb2;
    --tf-primary-rgb: 21, 174, 191;
    --tf-secondary: #ff6b35;
    --tf-accent: #ffd93d;
    --tf-success: #00b894;
    --tf-warning: #fdcb6e;
    --tf-danger: #e53e3e;
    --tf-white: #ffffff;
    --tf-bg: #f7fafc;
    --tf-surface: #ffffff;
    --tf-text: #2d3748;
    --tf-text-secondary: #4a5568;
    --tf-text-muted: #718096;
    --tf-border: #e2e8f0;
    --tf-border-light: #edf2f7;
    --tf-radius: 1rem;
    --tf-radius-sm: 0.5rem;
    --tf-radius-full: 9999px;
    --tf-shadow: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.04);
    --tf-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
    --tf-shadow-primary: 0 4px 14px rgba(21, 174, 191, 0.25);
    --tf-transition: 0.2s ease;
    --tf-gradient: linear-gradient(135deg, #15aebf 0%, #4ecdc4 100%);
}

/* ==========================================================================
   Base Layout
   ========================================================================== */

.timeflow {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    background: var(--tf-bg);
    font-family: 'Poppins', 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
    padding: 2rem;
    color: var(--tf-text);
}

/* ==========================================================================
   Card
   ========================================================================== */

.timeflow__card {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: var(--tf-surface);
    border: 1px solid var(--tf-border);
    border-radius: var(--tf-radius);
    padding: 2.5rem 2.5rem 2rem;
    box-shadow: var(--tf-shadow-lg);
    text-align: center;
    overflow: hidden;
}

/* ==========================================================================
   Top Accent Bar
   ========================================================================== */

.timeflow__rainbow {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--tf-gradient);
    border-radius: 0 0 2px 2px;
}

/* ==========================================================================
   Title
   ========================================================================== */

.timeflow__title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--tf-primary);
    margin: 1rem 0 0.25rem;
    letter-spacing: 0.04em;
}

.timeflow__subtitle {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--tf-text-muted);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin: 0 0 1.75rem;
}

/* ==========================================================================
   Mode Switcher
   ========================================================================== */

.timeflow__switcher {
    position: relative;
    display: flex;
    background: var(--tf-border-light);
    border-radius: var(--tf-radius-full);
    padding: 4px;
    margin: 0 auto 1.75rem;
    max-width: 320px;
    border: 1px solid var(--tf-border);
}

.timeflow__switcher-btn {
    flex: 1;
    position: relative;
    z-index: 2;
    padding: 0.6rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--tf-text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: color var(--tf-transition);
    text-transform: uppercase;
}

.timeflow__switcher-btn.active {
    color: var(--tf-white);
}

.timeflow__switcher-slider {
    position: absolute;
    top: 4px;
    bottom: 4px;
    inset-inline-start: 4px;
    width: calc(50% - 4px);
    background: var(--tf-gradient);
    border-radius: var(--tf-radius-full);
    transition: inset-inline-start 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
    box-shadow: var(--tf-shadow-primary);
}

.timeflow__switcher[data-mode="stopwatch"] .timeflow__switcher-slider {
    inset-inline-start: 50%;
}

/* ==========================================================================
   Timer Settings
   ========================================================================== */

.timeflow__settings {
    margin-bottom: 1.25rem;
}

.timeflow__time-inputs {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    direction: ltr;
}

.timeflow__input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.timeflow__input-group input {
    width: 60px;
    padding: 0.5rem;
    border: 1.5px solid var(--tf-border);
    border-radius: var(--tf-radius-sm);
    background: var(--tf-surface);
    font-size: 1.35rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    text-align: center;
    color: var(--tf-primary);
    transition: all var(--tf-transition);
}

.timeflow__input-group input:focus {
    outline: none;
    border-color: var(--tf-primary);
    box-shadow: 0 0 0 3px rgba(21, 174, 191, 0.15);
}


.timeflow__input-group label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--tf-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.timeflow__time-sep {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--tf-text-muted);
    margin-top: -1rem;
}

/* ==========================================================================
   Presets
   ========================================================================== */

.timeflow__presets {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.timeflow__preset-btn {
    padding: 0.3rem 0.85rem;
    border: 1.5px solid var(--tf-border);
    border-radius: var(--tf-radius-full);
    background: var(--tf-surface);
    color: var(--tf-text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--tf-transition);
}

.timeflow__preset-btn:hover {
    border-color: var(--tf-primary);
    color: var(--tf-primary);
    background: rgba(21, 174, 191, 0.06);
}

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

/* ==========================================================================
   Timer Display
   ========================================================================== */

.timeflow__display {
    font-family: 'Courier New', monospace;
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--tf-text);
    direction: ltr;
    margin: 0.75rem 0 0.25rem;
    letter-spacing: 0.04em;
    line-height: 1.2;
}

.timeflow__display.countdown {
    color: var(--tf-danger);
    animation: tf-pulse 0.5s ease-in-out infinite;
}

.timeflow__display.finished {
    color: var(--tf-success);
}

@keyframes tf-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

.timeflow__status {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--tf-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Action Buttons
   ========================================================================== */

.timeflow__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.timeflow__btn {
    flex: 1;
    max-width: 140px;
    padding: 0.7rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.04em;
    border-radius: var(--tf-radius-sm);
    cursor: pointer;
    transition: all var(--tf-transition);
    text-transform: uppercase;
}

.timeflow__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Start Button */
.timeflow__btn--start {
    background: var(--tf-gradient);
    border: 2px solid transparent;
    color: var(--tf-white);
    box-shadow: var(--tf-shadow-primary);
}

.timeflow__btn--start:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(21, 174, 191, 0.35);
    transform: translateY(-1px);
}

/* Pause Button */
.timeflow__btn--pause {
    background: var(--tf-text-muted);
    border: 2px solid transparent;
    color: var(--tf-white);
}

.timeflow__btn--pause:hover:not(:disabled) {
    background: var(--tf-text-secondary);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

/* Reset Button */
.timeflow__btn--reset {
    background: transparent;
    border: 2px solid var(--tf-border);
    color: var(--tf-text-secondary);
}

.timeflow__btn--reset:hover:not(:disabled) {
    border-color: var(--tf-danger);
    color: var(--tf-danger);
    background: rgba(229, 62, 62, 0.06);
}

/* ==========================================================================
   Sound Toggle (corner icon)
   ========================================================================== */

.timeflow__sound-btn {
    position: absolute;
    top: 1rem;
    inset-inline-end: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--tf-border-light);
    border: 1px solid var(--tf-border);
    border-radius: var(--tf-radius-full);
    color: var(--tf-text-muted);
    cursor: pointer;
    transition: all var(--tf-transition);
    z-index: 10;
}

.timeflow__sound-btn:hover {
    border-color: var(--tf-primary);
    color: var(--tf-primary);
    background: rgba(21, 174, 191, 0.06);
}

.timeflow__sound-btn[aria-pressed="true"] {
    color: var(--tf-primary);
    border-color: rgba(21, 174, 191, 0.3);
    background: rgba(21, 174, 191, 0.06);
}

.timeflow__sound-btn[aria-pressed="false"] {
    color: var(--tf-text-muted);
    opacity: 0.5;
}

.timeflow__sound-btn svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Running State - hide setup UI, show only time + controls
   ========================================================================== */

.timeflow__card--running .timeflow__title,
.timeflow__card--running .timeflow__subtitle,
.timeflow__card--running .timeflow__switcher,
.timeflow__card--running .timeflow__settings,
.timeflow__card--running .timeflow__rainbow,
.timeflow__card--running .timeflow__sound-btn,
.timeflow__card--running #timeflowStartBtn {
    display: none !important;
}

.timeflow__card--running .timeflow__display {
    font-size: 5rem;
    margin: 1.5rem 0 0.5rem;
    color: var(--tf-primary);
    text-shadow: 0 0 20px rgba(21, 174, 191, 0.4), 0 0 40px rgba(21, 174, 191, 0.15);
    animation: tf-glow 2s ease-in-out infinite;
}

@keyframes tf-glow {
    0%, 100% { text-shadow: 0 0 20px rgba(21, 174, 191, 0.4), 0 0 40px rgba(21, 174, 191, 0.15); }
    50% { text-shadow: 0 0 30px rgba(21, 174, 191, 0.6), 0 0 60px rgba(21, 174, 191, 0.25); }
}

.timeflow__card--running .timeflow__display.countdown {
    color: var(--tf-danger);
    text-shadow: 0 0 20px rgba(229, 62, 62, 0.5), 0 0 40px rgba(229, 62, 62, 0.2);
    animation: tf-glow-danger 0.5s ease-in-out infinite;
}

@keyframes tf-glow-danger {
    0%, 100% { text-shadow: 0 0 20px rgba(229, 62, 62, 0.5), 0 0 40px rgba(229, 62, 62, 0.2); }
    50% { text-shadow: 0 0 30px rgba(229, 62, 62, 0.7), 0 0 60px rgba(229, 62, 62, 0.35); }
}

/* Hide sound icon in stopwatch running mode */
.timeflow__card--stopwatch.timeflow__card--running .timeflow__sound-btn {
    display: none;
}

.timeflow__card--running .timeflow__status {
    margin-bottom: 2rem;
}

/* ==========================================================================
   Completion Overlay
   ========================================================================== */

.timeflow__overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.timeflow__overlay--visible {
    display: flex;
}

.timeflow__overlay-content {
    background: var(--tf-surface);
    border: 1px solid var(--tf-border);
    padding: 2.5rem;
    border-radius: var(--tf-radius);
    text-align: center;
    box-shadow: var(--tf-shadow-lg);
    animation: tf-pop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    max-width: 350px;
    width: 100%;
}

.timeflow__overlay-icon {
    font-size: 3.5rem;
    margin-bottom: 0.75rem;
    animation: tf-bounce 0.6s ease infinite;
}

@keyframes tf-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.timeflow__overlay-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--tf-primary);
    margin: 0 0 0.5rem 0;
}

.timeflow__overlay-text {
    color: var(--tf-text-muted);
    margin: 0 0 1.5rem 0;
    font-size: 0.95rem;
}

@keyframes tf-pop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Fullscreen Mode - Center & Scale Up
   ========================================================================== */

.tool-page-wrapper:fullscreen .timeflow,
.tool-page-wrapper:-webkit-full-screen .timeflow,
.tool-page-wrapper:-moz-full-screen .timeflow {
    min-height: 100vh;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.tool-page-wrapper:fullscreen .timeflow__card,
.tool-page-wrapper:-webkit-full-screen .timeflow__card,
.tool-page-wrapper:-moz-full-screen .timeflow__card {
    max-width: 640px;
    padding: 3.5rem 3.5rem 3rem;
}

.tool-page-wrapper:fullscreen .timeflow__display,
.tool-page-wrapper:-webkit-full-screen .timeflow__display,
.tool-page-wrapper:-moz-full-screen .timeflow__display {
    font-size: 5rem;
}

.tool-page-wrapper:fullscreen .timeflow__card--running .timeflow__display,
.tool-page-wrapper:-webkit-full-screen .timeflow__card--running .timeflow__display,
.tool-page-wrapper:-moz-full-screen .timeflow__card--running .timeflow__display {
    font-size: 8rem;
}

.tool-page-wrapper:fullscreen .timeflow__title,
.tool-page-wrapper:-webkit-full-screen .timeflow__title,
.tool-page-wrapper:-moz-full-screen .timeflow__title {
    font-size: 2.25rem;
}

.tool-page-wrapper:fullscreen .timeflow__status,
.tool-page-wrapper:-webkit-full-screen .timeflow__status,
.tool-page-wrapper:-moz-full-screen .timeflow__status {
    font-size: 0.9rem;
    letter-spacing: 0.2em;
}

.tool-page-wrapper:fullscreen .timeflow__btn,
.tool-page-wrapper:-webkit-full-screen .timeflow__btn,
.tool-page-wrapper:-moz-full-screen .timeflow__btn {
    max-width: 180px;
    padding: 0.9rem 2rem;
    font-size: 1rem;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 540px) {
    .timeflow {
        padding: 1rem;
    }

    .timeflow__card {
        padding: 2rem 1.5rem 1.5rem;
    }

    .timeflow__title {
        font-size: 1.4rem;
    }

    .timeflow__subtitle {
        font-size: 0.55rem;
        margin-bottom: 1.25rem;
    }

    .timeflow__display {
        font-size: 2.5rem;
    }

    .timeflow__card--running .timeflow__display {
        font-size: 3.5rem;
    }

    .timeflow__switcher {
        max-width: 280px;
    }

    .timeflow__switcher-btn {
        font-size: 0.7rem;
        padding: 0.5rem 1rem;
    }

    .timeflow__input-group input {
        width: 50px;
        font-size: 1.1rem;
        padding: 0.4rem;
    }

    .timeflow__btn {
        padding: 0.6rem 1rem;
        font-size: 0.75rem;
    }

    .timeflow__actions {
        gap: 0.5rem;
    }

    .timeflow__sound-btn {
        top: 0.75rem;
        inset-inline-end: 0.75rem;
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 360px) {
    .timeflow__title {
        font-size: 1.15rem;
    }

    .timeflow__display {
        font-size: 2rem;
    }

    .timeflow__card--running .timeflow__display {
        font-size: 2.75rem;
    }

    .timeflow__card {
        padding: 1.5rem 1rem 1.25rem;
    }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .timeflow__display,
    .timeflow__overlay-icon,
    .timeflow__overlay-content,
    .timeflow__switcher-slider {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================================
   RTL Support
   ========================================================================== */

[dir="rtl"] .timeflow {
    font-family: 'Vazirmatn', 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
}

[dir="rtl"] .timeflow__display {
    direction: ltr;
    text-align: center;
}

[dir="rtl"] .timeflow__status {
    text-align: center;
}

[dir="rtl"] .timeflow__time-inputs {
    direction: ltr;
}

[dir="rtl"] .timeflow__card {
    text-align: center;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .timeflow {
        background: white;
        min-height: 0;
    }

    .timeflow__card {
        background: white;
        border: 1px solid #ccc;
        box-shadow: none;
    }

    .timeflow__overlay,
    .timeflow__sound-btn,
    .timeflow__actions,
    .timeflow__rainbow {
        display: none !important;
    }

    .timeflow__title {
        color: #333;
    }

    .timeflow__display {
        color: #000;
    }
}
