/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== TOKENS ===== */
:root {
    --bg:          #0d0d18;
    --surface:     #161625;
    --surface2:    #1e1e32;
    --border:      rgba(255,255,255,0.07);
    --border-hi:   rgba(255,255,255,0.14);
    --accent:      #00e5d4;
    --accent-dim:  rgba(0,229,212,0.1);
    --accent-mid:  rgba(0,229,212,0.25);
    --green:       #4ade80;
    --green-dim:   rgba(74,222,128,0.18);
    --red:         #f87171;
    --red-dim:     rgba(248,113,113,0.18);
    --text:        #e2e2f0;
    --text-mid:    #9898b8;
    --text-dim:    #55556a;
    --radius:      14px;
    --radius-sm:   10px;
    --shadow:      0 6px 32px rgba(0,0,0,0.5);
}

html { scroll-behavior: smooth; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}
.header-inner {
    max-width: 1160px;
    margin: 0 auto;
    padding: 0 20px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-left  { display: flex; align-items: center; gap: 8px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.logo-icon { font-size: 22px; }
.logo-text {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text);
}
.logo-badge {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(0,229,212,0.3);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 2px 6px;
    border-radius: 4px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px 12px 5px 6px;
    border-radius: 24px;
    border: 1px solid var(--border);
    transition: background 0.15s, border-color 0.15s;
}
.header-user:hover { background: var(--surface2); border-color: var(--border-hi); }
.header-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.header-username { font-size: 0.85rem; color: var(--text-mid); }

.btn-login-header {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(0,229,212,0.28);
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-login-header:hover { background: var(--accent-mid); }

/* ===== MAIN ===== */
.main {
    max-width: 1160px;
    margin: 0 auto;
    padding: 28px 20px 80px;
}

/* ===== WORKOUT LAYOUT ===== */
.workout-layout {
    display: grid;
    grid-template-columns: 1fr 310px;
    gap: 24px;
    align-items: start;
}
@media (max-width: 780px) {
    .workout-layout { grid-template-columns: 1fr; }
}

/* ===== CAMERA ===== */
.camera-section { display: flex; flex-direction: column; gap: 8px; }

.camera-wrap {
    position: relative;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16/9;
    border: 1px solid var(--border);
}

#inputVideo {
    /* kept in DOM for MediaPipe but invisible */
    position: absolute;
    width: 0; height: 0; opacity: 0; pointer-events: none;
}

#outputCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    padding: 24px;
    background: linear-gradient(160deg, #161625 0%, #0d0d18 100%);
}
.cam-icon   { font-size: 52px; opacity: 0.35; }
.cam-title  { font-size: 1.05rem; color: var(--text-mid); font-weight: 600; }
.cam-sub    { font-size: 0.84rem; color: var(--text-dim); max-width: 260px; line-height: 1.6; }
.cam-sub strong { color: var(--accent); }

.pose-status {
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(0,0,0,0.55);
    border-radius: 20px;
    padding: 5px 11px;
    font-size: 0.78rem;
    color: var(--text-mid);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
}
.pose-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: background 0.3s, box-shadow 0.3s;
}
.pose-dot.active {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

.phase-overlay {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 900;
    backdrop-filter: blur(8px);
    transition: all 0.25s;
}
.phase-overlay.phase-down {
    background: rgba(248,113,113,0.25);
    border: 2px solid rgba(248,113,113,0.55);
    color: var(--red);
}
.phase-overlay.phase-up {
    background: rgba(74,222,128,0.25);
    border: 2px solid rgba(74,222,128,0.55);
    color: var(--green);
}

.rep-flash {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 5rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 50px var(--accent), 0 0 20px var(--accent);
    pointer-events: none;
    opacity: 0;
}
.rep-flash.pop {
    animation: repPop 0.75s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes repPop {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
    45%  { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
    100% { opacity: 0; transform: translate(-50%, -65%) scale(1); }
}

.camera-tip-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-mid);
}
.tip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

/* ===== WORKOUT PANEL ===== */
.workout-panel { display: flex; flex-direction: column; gap: 14px; }

.counter-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 20px 22px;
    text-align: center;
}
.counter-label {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.counter-value {
    font-size: 5.5rem;
    font-weight: 900;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.05em;
    transition: transform 0.08s;
}
.counter-value.bump {
    animation: counterBump 0.2s ease-out;
}
@keyframes counterBump {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}
.counter-phase {
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-mid);
    min-height: 1.5em;
    transition: color 0.3s;
}
.counter-phase.phase-down { color: var(--red); }
.counter-phase.phase-up   { color: var(--green); }

.timer-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    color: var(--text-mid);
    font-size: 1.35rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    letter-spacing: 0.08em;
}

.controls-block { display: flex; flex-direction: column; gap: 10px; }

.btn-start, .btn-stop {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-start {
    background: var(--accent);
    color: #0d0d18;
}
.btn-start:hover { background: #00f5e3; transform: translateY(-1px); }
.btn-start:active { transform: translateY(0); }
.btn-stop {
    background: var(--red);
    color: #fff;
}
.btn-stop:hover { background: #ff5a5a; transform: translateY(-1px); }

.instructions-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.inst-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-mid);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}
.inst-list {
    list-style: none;
    counter-reset: inst;
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.inst-list li {
    display: flex;
    gap: 10px;
    font-size: 0.84rem;
    color: var(--text-dim);
    line-height: 1.45;
    counter-increment: inst;
    align-items: flex-start;
}
.inst-list li::before {
    content: counter(inst);
    background: var(--surface2);
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 800;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.inst-list li strong { color: var(--text-mid); }

/* ===== HISTORY ===== */
.history-section { margin-top: 36px; }
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.history-title { font-size: 1.05rem; font-weight: 700; }
.history-count { font-size: 0.82rem; color: var(--text-dim); }

.history-empty {
    text-align: center;
    padding: 56px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
}
.empty-icon { font-size: 40px; opacity: 0.3; margin-bottom: 12px; }
.history-empty p { font-size: 0.95rem; }
.empty-sub { font-size: 0.82rem; margin-top: 5px; }

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}

.session-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: border-color 0.15s, background 0.15s;
}
.session-card:hover {
    border-color: rgba(0,229,212,0.25);
    background: var(--surface2);
}

.session-reps-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--accent-dim);
    border: 1px solid rgba(0,229,212,0.2);
    border-radius: 10px;
    padding: 10px 14px;
    min-width: 60px;
}
.session-reps-num   { font-size: 1.9rem; font-weight: 900; color: var(--accent); line-height: 1; }
.session-reps-label { font-size: 0.68rem; color: var(--text-dim); margin-top: 2px; letter-spacing: 0.04em; }

.session-meta { flex: 1; min-width: 0; }
.session-date {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-dur {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 4px;
}
.session-rate {
    font-size: 0.78rem;
    color: var(--text-dim);
    text-align: right;
    white-space: nowrap;
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border-hi);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-desc {
    font-size: 0.88rem;
    color: var(--text-mid);
    line-height: 1.55;
    margin-bottom: 20px;
}

.google-btn-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 14px;
}

.btn-text-muted {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.84rem;
    padding: 8px;
    text-decoration: underline;
    text-align: center;
    transition: color 0.15s;
}
.btn-text-muted:hover { color: var(--text-mid); }

/* Save modal */
.save-result {
    text-align: center;
    padding: 16px 0 20px;
}
.save-big {
    font-size: 4.5rem;
    font-weight: 900;
    color: var(--accent);
    line-height: 1;
}
.save-big-label { font-size: 1rem; color: var(--text-dim); margin-top: 4px; }
.save-duration  { font-size: 1.6rem; font-weight: 700; color: var(--text); margin-top: 14px; }
.save-duration-label { font-size: 0.82rem; color: var(--text-dim); margin-top: 2px; }

/* Profile */
.profile-info {
    text-align: center;
    padding: 14px 0 18px;
}
.profile-avatar {
    width: 64px; height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 12px;
    display: block;
    border: 2px solid var(--border-hi);
}
.profile-name  { font-size: 1.05rem; font-weight: 700; }
.profile-email { font-size: 0.84rem; color: var(--text-dim); margin-top: 4px; }

/* Modal buttons */
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}
.btn-accent, .btn-muted, .btn-danger {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-accent  { background: var(--accent); color: #0d0d18; }
.btn-accent:hover { background: #00f5e3; }
.btn-muted   { background: var(--surface2); color: var(--text-mid); border: 1px solid var(--border); }
.btn-muted:hover { background: #252540; }
.btn-danger  { background: var(--red-dim); color: var(--red); border: 1px solid rgba(248,113,113,0.25); }
.btn-danger:hover { background: rgba(248,113,113,0.28); }

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(70px);
    background: rgba(22,22,37,0.95);
    color: var(--text);
    border: 1px solid var(--border-hi);
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 0.88rem;
    z-index: 200;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(10px);
    white-space: nowrap;
    max-width: 90vw;
    pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== AI SECTION ===== */
.ai-section { margin-top: 36px; }
.ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.ai-title { font-size: 1.05rem; font-weight: 700; }

.btn-ai-analyze {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #0d0d18;
    border: none;
    border-radius: 8px;
    padding: 7px 16px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    letter-spacing: 0.01em;
}
.btn-ai-analyze:hover { background: #00f5e3; transform: translateY(-1px); }
.btn-ai-analyze:active { transform: translateY(0); }
.btn-ai-analyze:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.ai-body {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
}

.ai-idle {
    font-size: 0.88rem;
    color: var(--text-dim);
    text-align: center;
    padding: 20px 0;
    line-height: 1.6;
}
.ai-idle strong { color: var(--accent); font-weight: 600; }

.ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px 0;
    color: var(--text-dim);
    font-size: 0.9rem;
}
.ai-spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border-hi);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ai-summary-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
}
.ai-trend-badge {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 5px 10px;
    border-radius: 6px;
    text-transform: uppercase;
    margin-top: 2px;
}
.ai-trend-badge.improving { background: var(--green-dim); color: var(--green); }
.ai-trend-badge.declining { background: var(--red-dim);   color: var(--red); }
.ai-trend-badge.stable    { background: var(--accent-dim); color: var(--accent); }

.ai-summary-text {
    font-size: 0.92rem;
    color: var(--text-mid);
    line-height: 1.6;
}

/* Weekly bar chart */
.ai-chart-block { margin-bottom: 20px; }
.ai-chart-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}
.ai-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 80px;
}
.ai-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    height: 100%;
    justify-content: flex-end;
}
.ai-bar-fill {
    width: 100%;
    background: var(--accent-dim);
    border: 1px solid rgba(0,229,212,0.2);
    border-radius: 4px 4px 0 0;
    transition: height 0.4s ease;
    min-height: 3px;
}
.ai-bar-fill.best { background: var(--accent-mid); border-color: rgba(0,229,212,0.5); }
.ai-bar-label {
    font-size: 0.68rem;
    color: var(--text-dim);
    white-space: nowrap;
}
.ai-bar-label.best { color: var(--accent); font-weight: 700; }

/* Recommendations */
.ai-recs {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.ai-rec-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.86rem;
    color: var(--text-mid);
    line-height: 1.5;
}
.ai-rec-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    margin-top: 6px;
}

/* Next goal */
.ai-goal {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.88rem;
    color: var(--text-mid);
}
.ai-goal-num {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--accent);
    line-height: 1;
}
