:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #22252f;
    --bg-hover: #2a2d3a;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #5f6368;
    --accent: #4a9eff;
    --accent-hover: #6bb3ff;
    --accent-dim: rgba(74, 158, 255, 0.15);
    --success: #34d399;
    --success-dim: rgba(52, 211, 153, 0.15);
    --danger: #f87171;
    --danger-dim: rgba(248, 113, 113, 0.15);
    --warning: #fbbf24;
    --border: #2d3140;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding-bottom: 72px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Layout */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
}

@media (orientation: landscape) and (max-height: 600px) {
    body {
        padding-bottom: 56px;
    }
    .container {
        padding: 12px;
        padding-bottom: 68px;
    }
    .page-header {
        padding: 8px 0 12px;
    }
    .page-header h1 {
        font-size: 1.2rem;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .timer-bar {
        bottom: 56px;
    }
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 20px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
}

.back-btn:hover { color: var(--text-primary); }

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* List items */
.list-group {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg-hover); }

.list-item-title { font-weight: 500; }
.list-item-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.list-item-chevron {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.reorder-item {
    cursor: grab !important;
    transition: background 0.2s, transform 0.1s;
}

.reorder-item:active {
    cursor: grabbing !important;
}

.reorder-item:hover {
    background: var(--bg-hover) !important;
}

.list-action {
    padding: 12px 16px;
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.list-action:hover { background: var(--bg-hover); }

.list-action.danger { color: var(--danger); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

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

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

.btn-primary:hover { background: var(--accent-hover); }

.btn-success {
    background: var(--success);
    color: #000;
}

.btn-success:hover { filter: brightness(1.1); }

.btn-danger {
    background: var(--danger-dim);
    color: var(--danger);
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.25); }

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

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-block { width: 100%; }

.btn-lg {
    padding: 14px 28px;
    font-size: 1.05rem;
    border-radius: var(--radius);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

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

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    transition: border-color 0.15s;
}

.form-control:focus {
    border-color: var(--accent);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239aa0a6' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 12px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
    background: none;
    border: none;
}

.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--accent); }
.nav-item:hover { color: var(--text-secondary); }

/* Workout cards (home) */
.workout-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.workout-card.today {
    border-left: 3px solid var(--accent);
}

.workout-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.workout-card-header h3 { font-size: 1rem; font-weight: 600; }
.workout-card-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.workout-card-exercise {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.9rem;
}

.workout-card-exercise .name { color: var(--text-primary); }
.workout-card-exercise .detail {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.workout-card-more {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}

.start-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.start-bar .meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Set circles */
.sets-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.set-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: 2px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.set-circle:active {
    transform: scale(0.95);
}

.set-circle.completed {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.set-circle.partial {
    background: var(--warning);
    border-color: var(--warning);
    color: #000;
}

/* Active workout */
.exercise-block {
    margin-bottom: 20px;
}

.exercise-block-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.exercise-block-header h3 { font-size: 0.95rem; font-weight: 600; }
.exercise-block-header .detail {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.cardio-input {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.cardio-input input {
    width: 80px;
    text-align: center;
}

.timer-bar {
    position: fixed;
    bottom: 72px;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 99;
}

.timer-bar .time {
    font-size: 1.1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Calendar */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
}

.calendar-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 0;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.calendar-day:hover { background: var(--bg-hover); }
.calendar-day.today { color: var(--text-primary); font-weight: 600; }
.calendar-day.has-workout {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.calendar-day.empty { cursor: default; }
.calendar-day.empty:hover { background: none; }

.calendar-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.calendar-nav h3 { font-size: 1rem; }
.calendar-nav button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* History */
.history-entry {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
}

.history-entry-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.history-entry-header h3 { font-size: 0.95rem; font-weight: 600; }
.history-entry-header .date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-exercise {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 0.85rem;
}

.history-exercise .name { color: var(--text-primary); }
.history-exercise .result { color: var(--text-secondary); }
.history-exercise .skipped { color: var(--text-muted); font-style: italic; }

/* Tabs */
.tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 16px;
}

.tab {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
    background: none;
    border: none;
}

.tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    box-shadow: var(--shadow);
    z-index: 1000;
    transition: transform 0.3s ease;
    border: 1px solid var(--border);
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 400px;
}

.modal h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Auth pages */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-box {
    width: 100%;
    max-width: 380px;
}

.auth-box h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-box .subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.auth-box .form-group { margin-bottom: 20px; }

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Welcome card */
.welcome-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.welcome-card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.welcome-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 0.85rem;
    margin-bottom: 16px;
}

/* Utility */
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 0.85rem; }
.hidden { display: none !important; }
