:root {
    /* Colors */
    --bg-main: #0E0E0E;
    --bg-panel: #1C1C1E;
    --bg-panel-light: #2C2C2E;
    --text-main: #FFFFFF;
    --text-muted: #8E8E93;
    --accent-red: #FF3B30;
    --accent-red-dim: rgba(255, 59, 48, 0.2);
    
    /* Plate Colors */
    --plate-red: #FF3B30;
    --plate-blue: #0A84FF;
    --plate-yellow: #FFD60A;
    --plate-green: #30D158;
    --plate-white: #FFFFFF;
    --plate-black: #1C1C1E;
    --plate-silver: #E5E5EA;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    
    color-scheme: dark;
}

/* Themes */
html.theme-black {
    --bg-main: #000000;
    --bg-panel: #111111;
    --bg-panel-light: #222222;
}

html.theme-grey {
    --bg-main: #1C1C1E;
    --bg-panel: #2C2C2E;
    --bg-panel-light: #3A3A3C;
}

html.theme-white {
    --bg-main: #F2F2F7;
    --bg-panel: #FFFFFF;
    --bg-panel-light: #E5E5EA;
    --text-main: #000000;
    --text-muted: #666666;
    
    color-scheme: light;
}

html.theme-white .gradient-text {
    background: linear-gradient(90deg, #000000, var(--accent-red));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    height: 100dvh;
    overflow: hidden; /* Prevent body scroll, handle in main-content */
}

/* Loader Screen */
.loader-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out;
}
.loader-logo {
    width: 150px;
    height: 150px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    background-color: var(--bg-main);
    position: relative;
}

/* Utilities */
.text-red { color: var(--accent-red); }
.text-gray { color: var(--text-muted); }
.hidden { display: none !important; }
.spacer { flex: 1; }

.gradient-text {
    background: linear-gradient(90deg, #FFFFFF, var(--accent-red));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* Buttons */
button {
    background: none;
    border: none;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
    font-size: 1rem;
}
.icon-btn {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}
.small-icon { font-size: 1.2rem; }

/* Top Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 8px;
}
.header-title {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.header-btn {
    color: var(--accent-red);
    font-size: 0.9rem;
}

/* Sub Navigation */
.sub-nav {
    display: flex;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sub-nav-btn {
    flex: 1;
    padding: 12px 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}
.sub-nav-btn.active {
    color: var(--accent-red);
    border-bottom-color: var(--accent-red);
}

input, select, textarea, button {
    font-family: inherit;
    color: var(--text-main);
}

input::-webkit-input-placeholder {
    color: var(--text-muted);
}

/* Base Elements */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.tab-content {
    display: none;
    flex-direction: column;
    gap: 20px;
}
.tab-content.active {
    display: flex;
}

/* Actions Bar */
.actions-bar {
    display: flex;
    align-items: center;
    height: 40px;
}
.reset-btn {
    background-color: var(--accent-red);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Barbell Visualizer */
.barbell-visualizer {
    display: flex;
    align-items: center;
    height: 80px;
    position: relative;
    margin: 20px 0;
}
.bar-shaft {
    height: 30px;
    flex: 1;
    background-color: var(--text-muted);
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    padding-left: 10px;
}
.bar-weight-label {
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
}
.plates-container {
    display: flex;
    align-items: center;
    height: 100%;
}
.bar-end {
    width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Unit Toggle */
.unit-toggle-container {
    display: flex;
    justify-content: center;
}
.unit-toggle {
    display: flex;
    background-color: var(--bg-panel);
    border-radius: 20px;
    padding: 2px;
    width: 100%;
    max-width: 300px;
}
.toggle-btn {
    flex: 1;
    padding: 8px 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    border-radius: 18px;
    transition: background-color 0.2s;
}
.toggle-btn.active {
    background-color: var(--accent-red);
    color: white;
}

/* Weight Display */
.weight-display {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 2.5rem;
    font-weight: 700;
    margin: 10px 0;
}
.weight-divider {
    color: var(--text-muted);
    font-weight: 300;
}
.unit {
    font-size: 1rem;
    font-weight: 500;
}

/* Calculate Inputs */
.calculate-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}
.percent-btn {
    background-color: var(--accent-red);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 22px;
    font-weight: 700;
    font-size: 1.2rem;
}
.weight-input-wrapper {
    background-color: var(--bg-panel);
    border-radius: 22px;
    border: 1px solid var(--accent-red);
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    width: 120px;
}
.weight-input {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 600;
    width: 100%;
    outline: none;
    text-align: center;
}
.input-unit {
    font-weight: 600;
    font-size: 1.1rem;
}

/* Plates Needed Panel */
.plates-needed-panel {
    background-color: var(--bg-panel);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
}
.panel-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.plates-needed-result {
    font-size: 1.2rem;
    min-height: 30px;
}
.quick-maths {
    font-size: 0.9rem;
    color: var(--text-main);
}

/* Plate Grid (Reverse Mode) */
.plate-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-top: 10px;
}
.plate-control {
    aspect-ratio: 1;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.plate-control-label {
    font-weight: 800;
    font-size: 1.2rem;
    line-height: 1;
    margin-bottom: 4px;
    color: #FFFFFF;
}
.plate-control-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,0,0,0.4);
    padding: 2px 8px;
    border-radius: 12px;
}
.plate-btn {
    font-size: 1.2rem;
    font-weight: bold;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.plate-count {
    font-weight: bold;
    font-size: 1rem;
    background: white;
    color: black;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.plate-control-unit {
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 4px;
    color: rgba(255,255,255,0.8);
}
/* Specific Plate Colors */
.plate-control.p-25, .plate-control.p-50 { background-color: var(--plate-red); }
.plate-control.p-20 { background-color: var(--plate-blue); }
.plate-control.p-15 { background-color: var(--plate-yellow); .plate-control-label {color: black;} }
.plate-control.p-10 { background-color: var(--plate-green); }
.plate-control.p-5 { background-color: var(--plate-white); .plate-control-label, .plate-control-unit {color: black;} }
.plate-control.p-2-5 { background-color: var(--plate-black); border-color: var(--text-muted); }
.plate-control.p-2 { background-color: var(--plate-blue); }
.plate-control.p-1-5 { background-color: var(--plate-yellow); .plate-control-label {color: black;} }
.plate-control.p-1-25 { background-color: var(--plate-silver); .plate-control-label, .plate-control-unit {color: black;} }
.plate-control.p-1 { background-color: var(--plate-green); }
.plate-control.p-0-5, .plate-control.p-0-25, .plate-control.p-0-125 { background-color: var(--plate-silver); .plate-control-label, .plate-control-unit {color: black;} }

/* App Views (Bottom Nav Routing) */
.app-view {
    display: none;
    flex-direction: column;
    flex: 1 0 auto;
}
.app-view.active {
    display: flex;
}

/* Placeholder Content */
.placeholder-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}
.placeholder-content h3 {
    margin-bottom: 10px;
}

/* Settings Menu */
.settings-menu {
    background-color: var(--bg-panel);
    border-radius: 12px;
    overflow: hidden;
    margin-top: 10px;
    word-break: break-word;
    flex-shrink: 0;
}
.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid rgba(128,128,128,0.2);
    cursor: pointer;
    transition: background-color 0.2s;
}
.settings-item:hover {
    background-color: var(--bg-panel-light);
}

.theme-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid rgba(128,128,128,0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.theme-circle:hover {
    transform: scale(1.1);
}
.theme-circle.active {
    border: 2px solid var(--accent-red);
}
.settings-item:last-child {
    border-bottom: none;
}
.credits {
    text-align: center;
    margin-top: 40px;
    margin-bottom: 30px;
    font-size: 0.9rem;
}
.credits a {
    text-decoration: none;
    font-weight: 600;
}

/* Bottom Navigation */
.bottom-nav {
    display: flex;
    background-color: var(--bg-main);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 10px 0 20px;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
}
.nav-item i {
    font-size: 1.4rem;
}
.nav-item span {
    font-size: 0.65rem;
}
.nav-item.active {
    color: var(--accent-red);
}

/* Responsive constraints for larger screens */
@media (min-width: 600px) {
    .app-container {
        border-left: 1px solid rgba(255,255,255,0.1);
        border-right: 1px solid rgba(255,255,255,0.1);
    }
}

/* Toggles & Custom Controls */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #39393D;
    transition: .4s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--accent-red);
}
input:checked + .slider:before {
    transform: translateX(20px);
}

.minimal-input {
    background-color: transparent;
    border: 1px solid rgba(128,128,128,0.3);
    color: var(--text-main);
    border-radius: 12px;
    padding: 6px 12px;
    font-size: 1rem;
    text-align: center;
    width: 80px;
    font-family: inherit;
    outline: none;
    -webkit-text-fill-color: var(--text-main);
}
.minimal-input:disabled {
    opacity: 0.6;
    -webkit-text-fill-color: var(--text-muted);
    color: var(--text-muted);
}
/* Ensure calendar icon is clearly visible if color-scheme fails */
input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
    filter: invert(1);
}
html.theme-white input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0);
}
.rpe-input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.rpe-input-row:last-child {
    border-bottom: none;
}
.rpe-input {
    width: 100px;
}

.plate-style-options {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}
.style-circle {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid rgba(255,255,255,0.2);
}
.bg-red { background-color: var(--accent-red); }
.bg-gray { background-color: #8E8E93; }
.bg-dark { background-color: #1C1C1E; }

.bar-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    background-color: var(--bg-panel);
    cursor: pointer;
    transition: background-color 0.2s;
}
.bar-item:hover {
    background-color: var(--bg-panel-light);
}
.bar-item.selected {
    background-color: #4A1C1C; /* Dark red tint */
}

/* Mobile Responsiveness for Small Screens */
@media (max-width: 380px) {
    .main-content {
        padding: 12px;
    }
    .settings-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .settings-item > span:last-child {
        align-self: flex-end;
    }
    .unit-toggle {
        width: 100% !important;
        max-width: none;
    }
    .weight-display {
        font-size: 2rem;
    }
    .sub-nav-btn {
        font-size: 0.7rem;
        padding: 10px 0;
    }
    .plate-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Personal Records */
.pr-card {
    background-color: var(--bg-panel);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.pr-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.pr-card-title {
    font-weight: 700;
    font-size: 1.1rem;
}
.pr-card-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.pr-card-weight {
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--accent-red);
}
.pr-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.btn-outline {
    border: 1px solid var(--accent-red);
    color: var(--accent-red);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}
.btn-outline:hover {
    background-color: var(--accent-red-dim);
}

/* Warm Up Calculator */
.warmup-card {
    background-color: var(--bg-panel);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.warmup-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.warmup-weight {
    font-weight: 800;
    font-size: 1.2rem;
}
.warmup-reps {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* SSG Events Records */
.event-card {
    background-color: var(--bg-panel);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid rgba(128,128,128,0.2);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.event-header {
    background-color: var(--bg-panel-light);
    padding: 15px 20px;
    text-align: center;
    border-bottom: 2px solid var(--accent-red);
}

.event-header h3 {
    margin: 0;
    color: var(--text-main);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.event-records {
    display: flex;
    flex-direction: column;
    padding: 10px 20px;
}

.event-record-item {
    padding: 15px 0;
    border-bottom: 1px solid rgba(128,128,128,0.15);
}

.event-record-item:last-child {
    border-bottom: none;
}

.record-category {
    font-size: 0.8rem;
    color: var(--accent-red);
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.record-details {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 10px;
}

.record-lifter {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.record-style {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.record-weight {
    font-weight: 900;
    font-size: 1.3rem;
    color: var(--text-main);
    white-space: nowrap;
}

.record-weight span {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
}
