:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #121829;
    --bg-glass: rgba(255, 255, 255, 0.04);
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.45);
    --accent-2: #8b5cf6;
    --increment: #10b981;
    --decrement: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --radius: 18px;
    --shadow: 0 20px 60px -15px rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: rgba(0, 0, 0, 0.08);
    --shadow: 0 20px 60px -15px rgba(99, 102, 241, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    min-height: 100vh;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(600px circle at 20% 10%, rgba(99, 102, 241, 0.15), transparent 40%),
        radial-gradient(600px circle at 80% 90%, rgba(139, 92, 246, 0.15), transparent 40%);
    pointer-events: none;
    z-index: 0;
}

.particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.3;
    animation: floatUp linear infinite;
}

@keyframes floatUp {
    0% { transform: translateY(100vh) scale(0); opacity: 0; }
    10% { opacity: 0.4; }
    90% { opacity: 0.4; }
    100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}

.counter-app {
    width: 100%;
    max-width: 480px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 8px);
    padding: 2rem;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    position: relative;
    z-index: 1;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.02em;
}

.title-icon {
    color: var(--accent);
    font-size: 1.4rem;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.app-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.theme-toggle {
    width: 52px;
    height: 28px;
    border-radius: 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px;
    position: relative;
    transition: background 0.3s ease;
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle svg {
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
}

.toggle-thumb {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    top: 50%;
    left: 4px;
    transform: translateY(-50%);
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 12px var(--accent-glow);
}

[data-theme="light"] .toggle-thumb {
    left: 28px;
}

.counter-display {
    position: relative;
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
}

.display-glass {
    position: relative;
    width: 100%;
    padding: 2.5rem 1rem;
    border-radius: var(--radius);
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.04));
    border: 1px solid var(--border);
    text-align: center;
    overflow: hidden;
}

.display-glass::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
    animation: shimmer 4s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { left: -100%; }
    50% { left: 100%; }
}

.counter-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 4.5rem;
    font-weight: 700;
    line-height: 1;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.counter-value.bump {
    transform: scale(1.12);
}

.counter-value.neg {
    background: linear-gradient(135deg, #f87171, #ef4444);
    -webkit-background-clip: text;
    background-clip: text;
}

.counter-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-secondary);
    margin-top: 0.75rem;
}

.display-glow {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    height: 40px;
    background: var(--accent-glow);
    filter: blur(40px);
    border-radius: 50%;
    z-index: -1;
}

.counter-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.control-row {
    display: flex;
    gap: 0.5rem;
}

.btn {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    color: var(--text-primary);
    border-radius: var(--radius);
    padding: 1rem 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
}

.btn:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.btn:active {
    transform: translateY(0) scale(0.97);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-increment {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05));
    border-color: rgba(16, 185, 129, 0.3);
    color: #34d399;
}
.btn-increment:hover {
    box-shadow: 0 8px 24px -8px rgba(16, 185, 129, 0.4);
    border-color: var(--increment);
}

.btn-decrement {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15), rgba(239, 68, 68, 0.05));
    border-color: rgba(239, 68, 68, 0.3);
    color: #f87171;
}
.btn-decrement:hover {
    box-shadow: 0 8px 24px -8px rgba(239, 68, 68, 0.4);
    border-color: var(--decrement);
}

.btn-reset {
    background: var(--bg-glass);
}
.btn-reset:hover {
    box-shadow: 0 8px 24px -8px var(--accent-glow);
}

.secondary-row .btn-step {
    flex-direction: row;
    gap: 0.4rem;
    font-size: 0.8rem;
    padding: 0.7rem 0.5rem;
    color: var(--text-secondary);
}

.step-input-wrapper {
    flex: 1.5;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.step-input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    padding: 0.7rem;
    outline: none;
    -moz-appearance: textfield;
}

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

.step-unit {
    position: absolute;
    right: 0.75rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
    pointer-events: none;
}

.counter-presets {
    margin-bottom: 2rem;
}

.presets-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.presets-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
}

.preset-btn {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.6rem 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.preset-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: translateY(-2px);
}

.preset-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.counter-history {
    margin-bottom: 2rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.history-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
}

.btn-clear-history {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 8px;
    transition: color 0.2s ease, background 0.2s ease;
    display: flex;
}

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

.btn-clear-history:hover {
    color: #f87171;
    background: rgba(239, 68, 68, 0.1);
}

.history-list {
    max-height: 140px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding-right: 0.25rem;
}

.history-list::-webkit-scrollbar {
    width: 4px;
}
.history-list::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

.history-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    padding: 1.5rem 0;
    font-style: italic;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--bg-glass);
    border-radius: 10px;
    font-size: 0.8rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.history-item .h-action {
    color: var(--text-secondary);
}
.history-item .h-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}
.history-item .h-value.up { color: #34d399; }
.history-item .h-value.down { color: #f87171; }

.counter-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.stat-card {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem 0.4rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.app-footer {
    margin-top: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    z-index: 1;
}

.footer-links {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}

.footer-link {
    color: var(--accent);
    text-decoration: none;
    transition: opacity 0.2s ease;
}
.footer-link:hover { opacity: 0.7; }

.footer-divider {
    opacity: 0.5;
}

@media (max-width: 420px) {
    .counter-app { padding: 1.5rem; }
    .counter-value { font-size: 3.5rem; }
    .presets-grid { grid-template-columns: repeat(3, 1fr); }
    .counter-stats { grid-template-columns: repeat(2, 1fr); }
    .btn-text { display: none; }
    .btn svg { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
