@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;400;700&display=swap');

/* ── Reset & Base ──────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

/* ── Theme Variables ───────────────── */
[data-theme="dark"] {
    --bg: #000000;
    --text: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.35);
    --text-faint: rgba(255, 255, 255, 0.15);
    --surface: rgba(255, 255, 255, 0.06);
    --surface-hover: rgba(255, 255, 255, 0.12);
    --border: rgba(255, 255, 255, 0.1);
    --border-hover: rgba(255, 255, 255, 0.25);
    --accent: rgba(255, 200, 100, 0.8);
    --accent-bg: rgba(255, 200, 100, 0.08);
    --accent-border: rgba(255, 200, 100, 0.3);
    --gradient-bottom: rgba(0, 0, 0, 0.9);
}

[data-theme="light"] {
    --bg: #f5f5f5;
    --text: #1a1a1a;
    --text-dim: rgba(0, 0, 0, 0.35);
    --text-faint: rgba(0, 0, 0, 0.1);
    --surface: rgba(0, 0, 0, 0.04);
    --surface-hover: rgba(0, 0, 0, 0.08);
    --border: rgba(0, 0, 0, 0.1);
    --border-hover: rgba(0, 0, 0, 0.2);
    --accent: rgba(60, 130, 240, 0.85);
    --accent-bg: rgba(60, 130, 240, 0.06);
    --accent-border: rgba(60, 130, 240, 0.25);
    --gradient-bottom: rgba(245, 245, 245, 0.92);
}

html,
body {
    height: 100%;
}

body {
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Roboto Mono', 'Courier New', monospace;
    -webkit-font-smoothing: antialiased;
    user-select: none;
    cursor: default;
    transition: background 0.4s, color 0.4s;
    min-height: 100vh;
}

/* ── Top Bar ───────────────────────── */
.top-bar {
    position: fixed;
    top: 40px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    z-index: 100;
    transition: opacity 0.4s, transform 0.4s;
}

.mode-tabs {
    display: flex;
    gap: 2px;
    background: var(--surface);
    border-radius: 10px;
    padding: 3px;
}

.mode-tab {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: -apple-system, system-ui, 'Segoe UI', sans-serif;
    font-size: 0.82rem;
    padding: 7px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
    letter-spacing: 0.02em;
}

.mode-tab:hover {
    color: var(--text);
    background: var(--surface);
}

.mode-tab.active {
    background: var(--surface-hover);
    color: var(--text);
}

/* Theme toggle */
.theme-btn {
    position: fixed;
    top: 56px;
    right: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-dim);
    transition: all 0.2s;
    z-index: 101;
}

.theme-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--border-hover);
}

.theme-btn svg {
    width: 16px;
    height: 16px;
}

/* Show sun in dark mode, moon in light */
[data-theme="dark"] .icon-moon {
    display: none;
}

[data-theme="light"] .icon-sun {
    display: none;
}

/* ── Timer Main ────────────────────── */
.timer-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    position: relative;
    padding-top: 60px;
    /* space for top bar */
}

.fs-active .timer-main {
    padding-top: 0;
    min-height: 100vh;
}

.timer-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    line-height: 1;
    cursor: pointer;
    padding: 0 20px;
}

.time-text {
    /* Huge when only mm:ss is shown */
    font-size: clamp(6rem, 24vw, 32rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    transition: font-size 0.3s ease, color 0.3s;
}

.time-text.has-hours {
    /* Smaller when h:m:s is shown to prevent breaking the layout */
    font-size: clamp(4rem, 16vw, 22rem);
}

.time-ms {
    font-size: clamp(1.2rem, 4vw, 5rem);
    font-weight: 300;
    color: var(--text-dim);
    margin-left: 0.05em;
}

/* ── Alarm Flash ──────────────────── */
@keyframes alarm-flash {

    0%,
    100% {
        color: #ffcc00;
        /* Warm yellow */
    }

    50% {
        opacity: 0.25;
    }
}

.alarm .time-text {
    animation: alarm-flash 0.8s ease-in-out infinite;
}

.alarm-silenced .time-text {
    color: #ffcc00;
}

/* ── Controls ─────────────────────── */
.controls {
    position: relative;
    width: 100%;
    padding: 24px 20px 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    z-index: 100;
}

.fs-active .controls {
    position: fixed;
    bottom: 0;
    padding-bottom: 24px;
}

/* ── Preset Buttons ───────────────── */
.presets {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.preset-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.82rem;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 40px;
    text-align: center;
}

.preset-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-hover);
}

.preset-btn.selected {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-hover);
    font-weight: 700;
}

/* ── Custom Time Panel ──────────────── */
.custom-time-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.time-inputs {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 10px;
    transition: all 0.2s;
}

.time-inputs:focus-within {
    border-color: var(--accent-border);
    background: var(--surface-hover);
}

.time-inputs input {
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    width: 28px;
    text-align: center;
    outline: none;
    appearance: textfield;
    -moz-appearance: textfield;
}

.time-inputs input::-webkit-outer-spin-button,
.time-inputs input::-webkit-inner-spin-button {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
}

.time-inputs input::placeholder {
    color: var(--text-faint);
}

.time-inputs .sep {
    color: var(--text-dim);
    font-weight: 700;
    margin: 0 1px;
}


/* ── Action Buttons ───────────────── */
.action-bar {
    display: flex;
    gap: 12px;
    align-items: center;
}

.action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    color: var(--text);
    transform: scale(1.08);
}

.action-btn:active {
    transform: scale(0.95);
}

.action-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.action-btn svg path[fill="none"],
.action-btn svg circle[fill="none"] {
    fill: none;
}

/* Start button: larger */
#btnStart {
    width: 60px;
    height: 60px;
    border-color: var(--border-hover);
    background: var(--surface-hover);
}

#btnStart svg {
    width: 24px;
    height: 24px;
}

#btnStart:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
}

/* Running state */
.running #btnStart {
    border-color: var(--accent-border);
    background: var(--accent-bg);
    color: var(--accent);
}

/* ── Lap Container & Laps ─────────── */
.lap-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 20px 140px;
    /* leaves room for bottom controls */
}

.lap-list {
    width: 100%;
    max-width: 440px;
    background: transparent;
}

.lap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 0.9rem;
    color: var(--text-dim);
    border-bottom: 2px solid var(--border);
    margin-bottom: 12px;
}

.lap-clear {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 5px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.lap-clear:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--border-hover);
}

.lap-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lap-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 1rem;
    color: var(--text);
    font-family: 'Roboto Mono', monospace;
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid var(--border);
}

.lap-item .lap-num {
    color: var(--text-dim);
    min-width: 32px;
}

.lap-item .lap-split {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* ── Toast Notifications ────────────── */
.toast-container {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 360px;
    align-items: center;
}

.toast {
    background: var(--surface-hover);
    border: 1px solid var(--border-hover);
    padding: 10px 20px;
    border-radius: 30px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: -apple-system, system-ui, sans-serif;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    animation: toastIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), toastOut 0.3s ease 2.5s forwards;
    text-align: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

/* ── Fullscreen Mode ──────────────── */
.fs-active .top-bar,
.fs-active .presets,
.fs-active .lap-container,
.fs-active #toolhub-nav-host,
.fs-active .theme-btn {
    display: none !important;
}

/* ── Responsive ───────────────────── */
@media (max-width: 600px) {
    .mode-tab {
        font-size: 0.75rem;
        padding: 6px 12px;
    }

    .preset-btn {
        font-size: 0.75rem;
        padding: 5px 12px;
    }

    .action-btn {
        width: 44px;
        height: 44px;
    }

    #btnStart {
        width: 54px;
        height: 54px;
    }

    .theme-btn {
        width: 32px;
        height: 32px;
    }

    .theme-btn svg {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 380px) {
    .time-text {
        font-size: clamp(4.5rem, 23vw, 8rem);
    }

    .time-text.has-hours {
        font-size: clamp(3rem, 15vw, 6rem);
    }

    .preset-btn {
        padding: 4px 10px;
        font-size: 0.7rem;
    }
}

@media (max-height: 500px) {
    .top-bar {
        padding: 8px 16px;
    }

    .controls {
        padding: 8px 20px 12px;
        gap: 6px;
    }

    .preset-btn {
        padding: 3px 10px;
        font-size: 0.7rem;
    }

    .action-btn {
        width: 38px;
        height: 38px;
    }

    #btnStart {
        width: 48px;
        height: 48px;
    }
}

::-webkit-scrollbar {
    width: 0;
    height: 0;
}