:root {
    --primary-color: #6200ee;
    --primary-light: #9e47ff;
    --primary-dark: #0400ba;
    --secondary-color: #03dac6;
    --secondary-light: #66fff9;
    --secondary-dark: #00a895;
    --error-color: #b00020;
    --background-dark: #121212;
    --surface-dark: #1e1e1e;
    --on-dark: #ffffff;
    --background-light: #f5f5f5;
    --surface-light: #ffffff;
    --on-light: #000000;
}

@media screen and (orientation: landscape) {
    body {
        transform: rotate(90deg);
        width: 100vh;
        height: 100vw;
        overflow: auto;
        position: relative;
    }
}

html,
body {
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    /* Ensures smooth scrolling on iOS */
}

/* Base Styles */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    position: relative;

    background-color: var(--background-dark);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow: visible !important;
}

body.dark-mode {
    background-color: var(--background-dark);
    color: var(--on-dark);
}

body.light-mode {
    background-color: var(--background-light);
    color: var(--on-light);
}

/* Layout */
header {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 1rem;
    margin: 0;
    padding: 0;
}

nav a {
    color: inherit;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

nav a:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

main {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Buttons */
button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 1rem;
}

button:hover {
    background-color: var(--primary-light);
}

button:disabled {
    background-color: #666;
    cursor: not-allowed;
}

.custom-button {
    margin: 10px 5px;
}

/* Routine Form View */
#routine-form-view {
    max-width: 100%;
    width: 100%;
    padding: 0 1rem;
    box-sizing: border-box;
}

@media (min-width: 480px) {
    #routine-form-view {
        max-width: 480px;
        margin: 0 auto;
    }
}

/* Exercise Item Styling */
.exercise-item {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.exercise-content {
    margin-top: 2rem;
    padding: 0 0.5rem;
}

.exercise-controls {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    right: 0.5rem;
    display: flex;
    justify-content: space-between;
}

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

.exercise-controls button {
    background: rgba(252, 0, 0, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 1rem;
}

.exercise-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.delete-exercise::before {
    content: '❌';
}

.move-exercise-up::before {
    content: '↑';
}

.move-exercise-down::before {
    content: '↓';
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #666;
    border-radius: 4px;
    background-color: transparent;
    color: inherit;
}

.form-actions {
    margin-top: 1rem;
    display: flex;
    gap: 1rem;
}

/* Routine List */
#routines-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.routine-card {
    background-color: var(--surface-dark);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.routine-card.light-mode {
    background-color: var(--surface-light);
}

.routine-card h3 {
    margin-top: 0;
}

.routine-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Modern Workout View */
#workout-view {
    text-align: center;
    padding: 2rem;
    max-width: 500px;
    margin: 0 auto;
}

.timer {
    font-size: 7rem;
    margin: 1rem 0;
    font-weight: bold;
    color: #ffffff;
    font-family: 'Arial', sans-serif;
}

.exercise-name {
    font-size: 2rem;
    color: #ffffff;
    margin-bottom: 1rem;
    font-weight: 600;
}

.set-info {
    font-size: 1.2rem;
    color: #ffffff;
    margin-bottom: 1rem;
}

.next-exercise {
    font-size: 1rem;
    color: #ffffff;
    margin-top: 1.5rem;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    color: white;
}

.exercise-name {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.timer {
    font-size: 7rem;
    font-weight: 300;
    margin: 1rem 0;
    letter-spacing: 2px;
}

.workout-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-top: 2rem;
}

.nav-buttons {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.main-action-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: transparent;
    color: white;
    border: 1px solid white;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.main-action-btn:hover {
    background: transparent;
    transform: scale(1.05);
}

.icon-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #ecf0f1;
    color: #2c3e50;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: #bdc3c7;
}

.stop-btn {
    padding: 0.8rem 1.5rem;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.stop-btn:hover {
    background: #c0392b;
}

/* Workout States */
.workout-active {
    background-color: rgba(231, 76, 60, 0.1) !important;
}

.rest-active {
    background-color: rgba(46, 204, 113, 0.1) !important;
}

/* Exercise Item */
.exercise-item {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
    position: relative;
}

.exercise-item.light-mode {
    background-color: rgba(0, 0, 0, 0.05);
}

.delete-exercise {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--error-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
}

/* Workout States */
.workout-active {
    background-color: rgba(255, 0, 0, 0.1);
}

.rest-active {
    background-color: rgba(0, 255, 0, 0.1);
}

/* Exercise Library Modal */
#exercise-library-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

#exercise-library-modal.modal-show {
    display: flex !important;
}

.modal-content {
    background: var(--surface-dark);
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--on-dark);
}

.category-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.category-tabs button {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
}

.category-tabs button.active {
    background: var(--primary-color);
}

.exercise-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.library-exercise-item {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    cursor: pointer;
}

.library-exercise-item:hover {
    background: rgba(255, 255, 255, 0.1);
}