:root {
    --bg: #0b0d12;
    --bg-elevated: #12151c;
    --card: #1a1e28;
    --border: rgba(255, 255, 255, 0.08);
    --text: #f2f4f8;
    --text-muted: #8b92a3;
    --accent: #c6ff3d;
    --accent-ink: #10130a;
    --accent-soft: rgba(198, 255, 61, 0.12);
    --danger: #ff5d5d;
    --danger-soft: rgba(255, 93, 93, 0.12);
    --info: #3ddcff;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --nav-height: 68px;
    --header-height: 60px;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: radial-gradient(circle at top, #161b26 0%, var(--bg) 55%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

a {
    color: inherit;
    text-decoration: none;
}

h1, h2, h3, h4 {
    margin: 0 0 4px;
    letter-spacing: -0.02em;
}

p {
    margin: 0;
}

button, input, select, textarea {
    font-family: inherit;
    color: inherit;
}

/* ---------- Header ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    background: rgba(11, 13, 18, 0.85);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.app-header .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.05rem;
}

.app-header .brand .logo {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--accent);
    display: grid;
    place-items: center;
    font-size: 1.1rem;
}

.profile-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.82rem;
    color: var(--text-muted);
    max-width: 140px;
}

.profile-pill strong {
    color: var(--text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Layout ---------- */
.app-main {
    max-width: 640px;
    margin: 0 auto;
    padding: 18px 16px 32px;
}

.page-title {
    margin-bottom: 18px;
}

.page-title h1 {
    font-size: 1.5rem;
    font-weight: 800;
}

.page-title p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: var(--nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(18, 21, 28, 0.92);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease;
}

.bottom-nav a .icon {
    font-size: 1.25rem;
    line-height: 1;
}

.bottom-nav a.active {
    color: var(--accent);
}

.bottom-nav a.active .icon {
    filter: drop-shadow(0 0 8px var(--accent-soft));
}

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow);
}

.card + .card {
    margin-top: 12px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

/* ---------- Exercise / workout cards ---------- */
.exercise-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
}

.exercise-card + .exercise-card {
    margin-top: 10px;
}

.exercise-card .info h3 {
    font-size: 1rem;
    font-weight: 700;
}

.exercise-card .info .meta {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 2px;
}

.exercise-card .meta .tag {
    display: inline-block;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 0.72rem;
    font-weight: 700;
    margin-right: 6px;
}

.exercise-card .actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    display: grid;
    place-items: center;
    font-size: 1rem;
    cursor: pointer;
}

.icon-btn.danger {
    color: var(--danger);
    border-color: var(--danger-soft);
}

/* ---------- Forms ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.field label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 1rem;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--accent);
}

.field .row {
    display: flex;
    gap: 10px;
}

.field .row > * {
    flex: 1;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s ease, opacity 0.15s ease;
}

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

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

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

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

.btn-sm {
    width: auto;
    padding: 9px 14px;
    font-size: 0.85rem;
}

.fab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--nav-height) + 16px + env(safe-area-inset-bottom, 0px));
    z-index: 25;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 1.6rem;
    display: grid;
    place-items: center;
    border: none;
    box-shadow: 0 10px 28px rgba(198, 255, 61, 0.35);
    cursor: pointer;
}

/* ---------- Set logger (workout execution) ---------- */
.set-row {
    display: grid;
    grid-template-columns: 32px 1fr 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.set-row:last-child {
    border-bottom: none;
}

.set-row .set-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-elevated);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--accent);
}

.set-row input {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
}

.set-row input:focus {
    outline: none;
    border-color: var(--accent);
}

.field-suffix {
    position: relative;
}

.field-hint {
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 2px;
}

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

.empty-state .icon {
    font-size: 2.4rem;
    margin-bottom: 10px;
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 4px;
}

/* ---------- Stat tiles ---------- */
.stat-tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    text-align: center;
}

.stat-tile .value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--accent);
}

.stat-tile .label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---------- Chart card ---------- */
.chart-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.chart-card canvas {
    width: 100% !important;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--nav-height) + 20px);
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
    opacity: 1;
}

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(5, 6, 9, 0.72);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 40;
}

.modal-backdrop.open {
    display: flex;
}

.modal-sheet {
    width: 100%;
    max-width: 640px;
    background: var(--bg-elevated);
    border-radius: 22px 22px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
    max-height: 88vh;
    overflow-y: auto;
    animation: slide-up 0.2s ease;
}

@keyframes slide-up {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-sheet .modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 0 auto 16px;
}

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
    body {
        padding-bottom: 0;
    }

    .bottom-nav {
        position: static;
        margin: 0 auto;
        max-width: 640px;
        border-radius: var(--radius-lg);
        border: 1px solid var(--border);
        margin-top: 24px;
        margin-bottom: 24px;
    }

    .fab {
        bottom: 24px;
    }
}
