* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #1a1a1a;
    --surface: #252525;
    --text: #f0f0f0;
    --text-dim: #888;
    --accent: #4ade80;
    --fail: #ef4444;
    --pause: #f59e0b;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

/* Flash overlay - gentle green pulse */
.flash {
    position: fixed;
    inset: 0;
    background: var(--accent);
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
}

.flash.active {
    animation: flash 0.5s ease-in-out;
}

@keyframes flash {
    0% { opacity: 0; }
    50% { opacity: 0.4; }
    100% { opacity: 0; }
}

/* Update toast notification */
.update-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.3s ease-out;
}

.update-toast.hidden {
    display: none;
}

.update-toast span {
    font-size: 0.9rem;
    color: var(--text);
}

.update-toast button {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Setup Screen */
.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: max(2rem, env(safe-area-inset-top)) max(2rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left));
}

.screen.active {
    display: flex;
}

.setup-screen {
    justify-content: center;
    align-items: center;
    position: relative;
}

.setup-header {
    position: absolute;
    top: max(1rem, env(safe-area-inset-top));
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setup-content {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    text-align: center;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.home-screen {
    position: relative;
}

.home-header {
    position: absolute;
    top: max(1rem, env(safe-area-inset-top));
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.home-header .settings-toggle {
    margin-left: auto;
}

.home-content {
    text-align: center;
}

.home-tagline {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin: 0 0 1.5rem;
}

.home-footer {
    position: absolute;
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    text-align: center;
}

.home-footer a {
    color: var(--text-dim);
    font-size: 0.75rem;
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.home-footer a:hover {
    opacity: 1;
}

.home-logo {
    width: 96px;
    height: 96px;
    margin-bottom: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.875rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.time-inputs {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

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

.time-input input {
    width: 5rem;
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    text-align: center;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 0.5rem;
    color: var(--text);
    outline: none;
}

.time-input input:focus {
    border-color: var(--accent);
}

/* Hide number input spinners */
.time-input input::-webkit-inner-spin-button,
.time-input input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.time-input input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.time-input span {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.time-separator {
    font-size: 1.5rem;
    color: var(--text-dim);
    padding-top: 0.5rem;
}

.btn {
    padding: 1.25rem 2rem;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.125rem;
    font-weight: 600;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
}

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

.btn-primary {
    background: var(--accent);
    color: #1a1a1a;
}

.btn-fail {
    background: var(--fail);
    color: white;
}

.btn-pause {
    background: var(--pause);
    color: #1a1a1a;
}

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

/* Settings */
.settings-row {
    display: flex;
    justify-content: center;
}

.settings-toggle {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: color 0.15s;
}

.settings-toggle:hover,
.settings-toggle.active {
    color: var(--text);
}

.settings-panel {
    position: fixed;
    top: calc(max(1rem, env(safe-area-inset-top)) + 2.5rem);
    right: max(1rem, env(safe-area-inset-right));
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 100;
}

.settings-panel.hidden {
    display: none;
}

.setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-dim);
    gap: 1rem;
}

.setting > span:first-child {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.setting > span:first-child {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Toggle switch */
.setting input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    width: 44px;
    height: 24px;
    background: var(--bg);
    border-radius: 12px;
    position: relative;
    transition: background 0.2s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.setting input[type="checkbox"]:checked + .toggle-switch {
    background: var(--accent);
}

.setting input[type="checkbox"]:checked + .toggle-switch::after {
    transform: translateX(20px);
    background: white;
}

/* Color swatches */
.color-swatches {
    display: flex;
    gap: 0.5rem;
}

.color-swatches button {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
}

.color-swatches button[data-color="#4ade80"] { background: #4ade80; }
.color-swatches button[data-color="#3b82f6"] { background: #3b82f6; }
.color-swatches button[data-color="#a855f7"] { background: #a855f7; }
.color-swatches button[data-color="#f97316"] { background: #f97316; }

.color-swatches button.color-off {
    background: var(--bg);
    position: relative;
}

.color-swatches button.color-off::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70%;
    height: 2px;
    background: var(--text-dim);
    transform: translate(-50%, -50%) rotate(-45deg);
}

.color-swatches button.selected {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text);
}

.color-swatches button:active {
    transform: scale(0.9);
}

/* Sound swatches */
.sound-swatches {
    display: flex;
    gap: 0.5rem;
}

.sound-swatches button {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
    background: var(--bg);
    font-size: 0.875rem;
    line-height: 24px;
    text-align: center;
    padding: 0;
}

.sound-swatches button[data-sound="dog-clicker"]::before { content: '\1F514'; }
.sound-swatches button[data-sound="anime-cute"]::before { content: '\2728'; }
.sound-swatches button[data-sound="apple-pay"]::before { content: '\1F3B5'; }
.sound-swatches button[data-sound="good-job"]::before { content: '\1F389'; }

.sound-swatches button.sound-random::before { content: '\1F3B2'; }

.sound-swatches button.sound-off::before { content: '\1F6AB'; }

.sound-swatches button.selected {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text);
}

.sound-swatches button:active {
    transform: scale(0.9);
}

/* Training Screen */
.training-screen {
    justify-content: space-between;
    padding-bottom: 3rem;
}

.training-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.end-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Session timer in header */
.session-timer {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    color: var(--text-dim);
}

/* Countdown container - new hierarchy */
.countdown-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

/* Round info - now at top of countdown area */
.round-info {
    font-size: 0.875rem;
    color: var(--text-dim);
    order: 1;
}

/* Target - more prominent */
.target-info {
    text-align: center;
    color: var(--text);
    font-size: 1rem;
    order: 2;
}

.target-info span {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

/* Main countdown display */
.countdown-display {
    order: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.countdown {
    font-family: 'JetBrains Mono', monospace;
    font-size: 6rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
}

.countdown-ms {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    color: var(--text-dim);
}

/* Next target preview - directly under countdown */
.next-preview {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 0.5rem;
    order: 4;
}

.next-preview span {
    font-family: 'JetBrains Mono', monospace;
}

/* Round history - fixed height, no resizing */
.round-history {
    height: 120px;
    overflow-y: auto;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
}

.round-history-item {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

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

.round-history-item span {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text);
}

.round-history-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-style: italic;
}

/* Button row - fail left, pause right */
.button-row {
    display: flex;
    gap: 0.75rem;
}

.button-row .btn {
    flex: 1;
    padding: 1.5rem;
    font-size: 1.25rem;
}

.button-row.hidden,
.btn.hidden {
    display: none;
}

/* Resume button (full width when shown) */
.resume-btn {
    width: 100%;
    padding: 1.5rem;
    font-size: 1.25rem;
}

.resume-btn.hidden {
    display: none;
}

/* Fail message (shown when dog breaks) */
.fail-message {
    text-align: center;
    color: var(--text-dim);
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.fail-message.hidden {
    display: none;
}

/* Install Button (in header) */
.install-btn {
    display: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
}

/* Install Modal */
.install-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.install-modal.active {
    display: flex;
}

.install-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.install-modal-content {
    position: relative;
    background: var(--surface);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 320px;
    width: calc(100% - 2rem);
    margin: 1rem;
}

.install-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.install-modal-close:hover {
    color: var(--text);
}

.install-modal-content h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

.install-modal-content p {
    color: var(--text-dim);
    margin-bottom: 1rem;
}

.install-modal-content ol {
    padding-left: 1.25rem;
    color: var(--text);
}

.install-modal-content li {
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

.install-modal-content strong {
    color: var(--accent);
}

.share-icon::before {
    content: '\2191';
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    line-height: 1.5rem;
    text-align: center;
    background: var(--bg);
    border-radius: 0.25rem;
    margin-left: 0.25rem;
    font-size: 0.875rem;
}
