@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%;
    overflow: 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;
}

/* ── 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;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.timer-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    line-height: 1;
    cursor: pointer;
    padding: 0 20px;
}

.time-text {
    /* Adjusted to avoid overflow when showing hours (e.g. 119:59:59) */
    font-size: clamp(4.5rem, 16vw, 24rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    transition: color 0.3s;
}

.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: #ff3333;
    }

    50% {
        opacity: 0.25;
    }
}

.alarm .time-text {
    animation: alarm-flash 0.8s ease-in-out infinite;
}

/* ── Controls ─────────────────────── */
.controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 14px 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: linear-gradient(to top, var(--gradient-bottom) 0%, transparent 100%);
    z-index: 100;
    transition: opacity 0.4s, transform 0.4s;
}

/* ── 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;
}

/* ── 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 List ─────────────────────── */
.lap-list {
    position: fixed;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%);
    width: 88%;
    max-width: 360px;
    max-height: 28vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    z-index: 90;
    flex-direction: column;
}

.lap-list:not([hidden]) {
    display: flex;
}

.lap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    font-size: 0.7rem;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.lap-clear {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.lap-clear:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.lap-items {
    overflow-y: auto;
    padding: 4px 0;
    flex: 1;
}

.lap-items::-webkit-scrollbar {
    width: 3px;
}

.lap-items::-webkit-scrollbar-thumb {
    background: var(--text-faint);
    border-radius: 2px;
}

.lap-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 14px;
    font-size: 0.78rem;
    color: var(--text-dim);
    font-family: 'Roboto Mono', monospace;
}

.lap-item .lap-num {
    color: var(--text-faint);
    min-width: 24px;
}

.lap-item .lap-split {
    color: var(--text-faint);
    font-size: 0.7rem;
}

/* ── Fullscreen Mode ──────────────── */
.fs-active .top-bar,
.fs-active .presets,
.fs-active .lap-list,
.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(3.5rem, 22vw, 8rem);
    }

    .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;
}