/* ============================================================
   Timer & Countdown Utility — Styles
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #253349;
    --accent: #60a5fa;
    --accent-bold: #3b82f6;
    --accent-glow: rgba(96, 165, 250, 0.35);
    --purple: #7c3aed;
    --green: #34d399;
    --cyan: #06b6d4;
    --red: #ef4444;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    --radius: 10px;
    --radius-lg: 14px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --ring-size: 260px;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ---------- Header ---------- */
.header {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    gap: 1rem;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #fff;
    flex-shrink: 0;
}

.header-icon {
    width: 26px;
    height: 26px;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ---------- Mode Tabs ---------- */
.mode-tabs {
    display: flex;
    gap: 2px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 3px;
}

.mode-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mode-tab svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.mode-tab:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.mode-tab.active {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-weight: 600;
}

/* ---------- Main Content ---------- */
.main-content {
    flex: 1;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.25rem;
}

.mode-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.mode-panel.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Display Area ---------- */
.display-area {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem 0;
}

/* ---------- Time Display (Stopwatch) ---------- */
.time-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    font-weight: 800;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    user-select: none;
}

.stopwatch-display {
    font-size: 4.5rem;
    color: var(--text-primary);
    text-shadow: 0 0 40px var(--accent-glow), 0 0 80px rgba(96, 165, 250, 0.15);
}

.stopwatch-display .time-ms {
    font-size: 2.8rem;
    color: var(--accent);
    min-width: 2ch;
}

.stopwatch-display .time-sep-ms {
    font-size: 3rem;
    color: var(--text-dim);
}

.time-sep {
    color: var(--text-dim);
    margin: 0 2px;
    animation: blink 1s step-end infinite;
}

.running .time-sep {
    animation: none;
    color: var(--text-dim);
}

@keyframes blink {
    50% { opacity: 0.3; }
}

/* ---------- Countdown / Pomodoro Display ---------- */
.countdown-display {
    font-size: 3.2rem;
    color: var(--text-primary);
    text-shadow: 0 0 30px var(--accent-glow);
}

.cd-label, .pomo-phase-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
    font-weight: 500;
}

.pomo-quote {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 12px;
    font-style: italic;
    max-width: 22rem;
    line-height: 1.4;
    min-height: 1.4em;
    opacity: 0;
    transition: opacity 0.4s ease;
    padding: 0 1rem;
}

.pomo-quote.visible {
    opacity: 0.85;
}

/* ---------- Progress Ring ---------- */
.progress-ring-wrapper {
    position: relative;
    width: var(--ring-size);
    height: var(--ring-size);
}

.progress-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.progress-ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 6;
}

.progress-ring-fill {
    fill: none;
    stroke: url(#ringGradient);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 753.98;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s ease;
}

.pomo-ring {
    stroke: url(#pomoGradient);
}

.pomo-ring.break-phase {
    stroke: url(#pomoBreakGradient);
}

.ring-inner-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 200px;
}

/* ---------- Countdown Input Mode ---------- */
.cd-input-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.time-input-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.time-input-col label {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    order: 3;
    margin-top: -2px;
}

.time-input {
    width: 48px;
    height: 44px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
    order: 2;
}

.time-input::-webkit-inner-spin-button,
.time-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.time-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.spin-btn {
    width: 32px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
}

.spin-btn:first-child {
    order: 1;
}

.spin-btn:last-child {
    order: 4;
}

.spin-btn svg {
    width: 16px;
    height: 16px;
}

.spin-btn:hover {
    color: var(--accent);
    background: rgba(96, 165, 250, 0.1);
}

.input-sep {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-dim);
    margin: 0 1px;
    align-self: center;
}

.hidden {
    display: none !important;
}

/* ---------- Presets Bar ---------- */
.presets-bar {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 0.5rem;
}

.preset-btn {
    padding: 6px 16px;
    border: 1px solid var(--border-light);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(96, 165, 250, 0.08);
}

.preset-btn:active {
    transform: scale(0.96);
}

/* ---------- Control Buttons ---------- */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 1rem 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn:active {
    transform: scale(0.96);
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-bold), var(--purple));
    color: #fff;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 25px rgba(59, 130, 246, 0.45);
    transform: translateY(-1px);
}

.btn-primary.running-state {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface);
    color: var(--text-primary);
    border-color: var(--border-light);
}

/* ---------- Laps ---------- */
.laps-container {
    max-width: 500px;
    margin: 1rem auto 0;
    display: none;
}

.laps-container.has-laps {
    display: block;
}

.laps-header {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.laps-list {
    list-style: none;
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--text-dim) transparent;
}

.laps-list::-webkit-scrollbar {
    width: 5px;
}

.laps-list::-webkit-scrollbar-track {
    background: transparent;
}

.laps-list::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 3px;
}

.lap-item {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    border-bottom: 1px solid var(--border);
    animation: lapSlideIn 0.25s ease;
}

.lap-item:last-child {
    border-bottom: none;
}

@keyframes lapSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.lap-num {
    color: var(--text-dim);
    font-weight: 600;
}

.lap-split {
    color: var(--accent);
    font-weight: 600;
}

.lap-total {
    color: var(--text-secondary);
}

.lap-item.best .lap-split {
    color: var(--green);
}

.lap-item.worst .lap-split {
    color: var(--red);
}

/* ---------- Pomodoro ---------- */
.pomo-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.pomo-phase {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
}

.pomo-phase.break-active {
    color: var(--green);
}

.pomo-session-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pomo-session-count span {
    color: var(--text-primary);
    font-weight: 700;
}

/* ---------- Pomodoro Settings ---------- */
.pomo-settings {
    max-width: 400px;
    margin: 2rem auto 0;
    padding: 20px 24px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.settings-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 16px;
}

.settings-grid {
    display: flex;
    gap: 16px;
}

.setting-item {
    flex: 1;
}

.setting-item label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.setting-input-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 4px 10px;
}

.setting-input {
    width: 50px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}

.setting-input::-webkit-inner-spin-button,
.setting-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.setting-unit {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 500;
}

/* ---------- Keyboard Shortcut Bar ---------- */
.shortcut-bar {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
}

.shortcut {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
}

kbd {
    display: inline-block;
    padding: 2px 7px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 22px;
    text-align: center;
}

/* ---------- Timer Complete Flash ---------- */
@keyframes flashComplete {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.flash-complete .countdown-display,
.flash-complete .pomo-time-display {
    animation: flashComplete 0.6s ease 4;
    color: var(--green);
    text-shadow: 0 0 30px rgba(52, 211, 153, 0.5);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .header-inner {
        flex-direction: column;
        height: auto;
        padding: 10px 1rem;
        gap: 8px;
    }

    .mode-tabs {
        width: 100%;
        justify-content: center;
    }

    .mode-tab {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .mode-tab svg {
        width: 14px;
        height: 14px;
    }

    .stopwatch-display {
        font-size: 3rem;
    }

    .stopwatch-display .time-ms {
        font-size: 1.8rem;
    }

    .stopwatch-display .time-sep-ms {
        font-size: 2rem;
    }

    .countdown-display {
        font-size: 2.4rem;
    }

    :root {
        --ring-size: 220px;
    }

    .ring-inner-display {
        width: 170px;
    }

    .time-input {
        width: 40px;
        height: 38px;
        font-size: 1.2rem;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.85rem;
    }

    .shortcut-bar {
        gap: 12px;
        flex-wrap: wrap;
    }

    .presets-bar {
        gap: 6px;
    }

    .preset-btn {
        padding: 5px 12px;
        font-size: 0.75rem;
    }

    .settings-grid {
        flex-direction: column;
        gap: 12px;
    }
}

@media (max-width: 380px) {
    .stopwatch-display {
        font-size: 2.4rem;
    }

    .stopwatch-display .time-ms {
        font-size: 1.4rem;
    }

    .countdown-display {
        font-size: 2rem;
    }

    :root {
        --ring-size: 190px;
    }

    .ring-inner-display {
        width: 145px;
    }
}
