:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --bg-color: #ffffff;
    --surface-color: #f8fafc;
    --text-color: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

/* Load local Cal Sans semi-bold */
@font-face {
    font-family: 'Cal Sans';
    src: url('./CalSans-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

[data-theme="dark"] .icon-small-btn {
    color: #ffffff;
}

[data-theme="dark"] .week-btn {
    color: #ffffff;
    border-color: rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.02);
}

[data-theme="dark"] .week-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

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

/* Prevent text selection and touch behaviors */
body {
    font-family: 'Cal Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: contain;
}

body.modal-open {
    overflow: hidden;
    height: 100vh;
}

/* Allow text selection in inputs */
input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

#app {
    min-height: 100vh;
    max-width: 100vw;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem;
}

/* Header canvas effect (subtle lines/particles) */
.header-content {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 400px;
    margin: 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 2;
}

/* ensure canvas sits behind title and controls */
#header-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    z-index: 0;
    pointer-events: none;
    opacity: 0.12; /* subtle */
    transition: opacity 0.25s ease;
}

.header-content .app-title,
.header-actions {
    position: relative;
    z-index: 2;
}

/* slightly stronger effect in dark mode */
[data-theme="dark"] #header-canvas {
    opacity: 0.16;
}

/* App title refined — subtle backdrop glow + gradient text */
.app-title {
    position: relative;
    font-size: 2rem;
    margin-top: 5px;
    font-weight: 600;
    color: var(--primary-color);
    letter-spacing: 0.4px;
    padding: 0.15rem 0.5rem;
    border-radius: 8px;
    z-index: 2;
    background: linear-gradient(90deg, rgba(255,255,255,0.03), transparent);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    background-image: linear-gradient(90deg, var(--primary-color) 0%, #0ea5e9 100%);
    -webkit-text-fill-color: transparent;
    text-shadow: 0 1px 0 rgba(0,0,0,0.05), 0 6px 18px rgba(16,24,40,0.06);
}

/* soft blurred backdrop behind title */
.app-title::before {
    content: '';
    position: absolute;
    left: -8px;
    right: -8px;
    top: -6px;
    bottom: -6px;
    border-radius: 10px;
    background: linear-gradient(90deg, rgba(37,99,235,0.08), rgba(14,165,233,0.04));
    filter: blur(10px);
    z-index: 1;
    pointer-events: none;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.app-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    margin-right: -8px;
    margin-left: 10px;
    position: relative;
    z-index: 2;
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--border-color);
}

/* Main Content */
.main-content {
    max-width: 400px;
    margin: 0 auto;
    padding: 1rem;
    min-height: calc(100vh - 80px);
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Weekly View */
.week-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 1.5rem;
}

.week-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.week-selector {
    display: flex;
    gap: 6px;
    margin-right: auto;
    align-items: center;
    width: 100%;
}

.week-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    flex: 1;
    text-align: center;
}

.week-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.days-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.day-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow);
}

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

.day-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.exercise-count {
    background-color: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.exercises-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.exercise-item {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    align-items: center;
}

.exercise-info {
    flex: 1;
}

.exercise-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.exercise-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--primary-color);
    flex-shrink: 0;
    cursor: pointer;
}

.move-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.icon-small-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 32px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
}

.icon-small-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.exercise-thumbnail {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.exercise-thumbnail:hover {
    border-color: var(--primary-color);
}

.exercise-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.exercise-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.exercise-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Buttons */
.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    width: 100%;
    font-size: 1rem;
}

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

.secondary-btn {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.secondary-btn:hover {
    background-color: var(--border-color);
}

.back-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
}

.danger-btn {
    background-color: #dc2626;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.875rem;
    width: 100%;
}

.danger-btn:hover {
    background-color: #b91c1c;
}

.install-btn {
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

/* View Header */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.view-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Mode Selection */
.mode-selection {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mode-btn {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.mode-btn h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.mode-btn p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Forms */
.exercise-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

.form-group label {
    font-weight: 500;
    color: var(--text-color);
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group .select-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.form-group .select-row select {
    flex: 1;
}

/* @tweakable pattern for validating repetitions input (numbers and spaces) */
#exercise-reps {
    /* Allow numbers, spaces, and common rep notation characters */
    pattern: "[0-9\s\-xX\.,:]*";
}

/* @tweakable placeholder text color for repetitions field */
#exercise-reps::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Exercise Detail */
.exercise-detail {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.detail-section {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.detail-header {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.detail-value {
    font-weight: 500;
}

.exercise-image {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-top: 1rem;
}

.exercise-images-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.exercise-images-grid img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Settings */
.settings-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.setting-item {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.setting-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

/* Specific styling for theme setting to put button on the right */
.setting-item:has(#theme-switch) {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-item:has(#theme-switch) label {
    margin-bottom: 0;
}

.theme-switch {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.export-buttons {
    display: flex;
    gap: 0.5rem;
}

.export-buttons .secondary-btn {
    flex: 1;
}

/* Settings Footer */
.settings-footer {
    margin-top: 2rem;
    padding: 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

.settings-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.settings-footer a:hover {
    text-decoration: underline;
}

/* App Footer (for main view) */
.app-footer {
    margin-top: 2rem;
    padding: 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

.app-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

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

.modal {
    background-color: var(--bg-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 350px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-content {
    padding: 1rem;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    justify-content: flex-end;
}

.modal-actions .secondary-btn,
.modal-actions .primary-btn,
.modal-actions .danger-btn {
    flex: 1;
    max-width: 120px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Image Preview and Upload */
.image-preview {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.image-preview .image-thumb-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
}

.image-preview .remove-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #dc2626;
    color: white;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Image Modal */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1001;
    padding: 1rem;
}

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

.image-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.image-modal-content img {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
}

.image-modal-close {
    position: absolute;
    top: -10px;
    right: -10px;
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    box-shadow: var(--shadow);
}

.image-modal-close:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Muscle Groups Management */
.muscle-groups-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.muscle-groups-header {
    margin-bottom: 1rem;
}

.muscle-groups-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.muscle-group-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.muscle-group-header {
    display
}