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

:root {
    --bg:        #0b0f1a;
    --surface:   #141926;
    --surface2:  #1c2436;
    --border:    rgba(255,255,255,0.08);
    --text:      #e8edf5;
    --muted:     rgba(255,255,255,0.38);
    --accent:    #38bdf8;
    --green:     #4ade80;
    --yellow:    #fbbf24;
    --red:       #f87171;
    --orange:    #fb923c;
    --purple:    #a78bfa;
    --teal:      #2dd4bf;
    --radius:    14px;

    /* Direction-specific */
    --col-right:  #38bdf8;   /* sağ rotasyon - cyan */
    --col-left:   #fb923c;   /* sol rotasyon - orange */
    --col-flex:   #4ade80;   /* fleksiyon - green */
    --col-ext:    #a78bfa;   /* ekstansiyon - purple */
    --col-roll-r: #fbbf24;   /* sağ yana - yellow */
    --col-roll-l: #f87171;   /* sol yana - red */
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Nunito', sans-serif;
    height: 100vh; width: 100vw;
    overflow: hidden;
    user-select: none;
}
.mono { font-family: 'JetBrains Mono', monospace; }

#input-video { position: fixed; left: -9999px; }

/* ─── MODALS ──────────────────────────────────────────────── */
.overlay-modal {
    position: fixed; inset: 0; z-index: 500;
    display: flex; align-items: center; justify-content: center;
    background: rgba(5,8,20,0.94);
    backdrop-filter: blur(4px);
}
.overlay-modal.hidden { display: none; }

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2.2rem 2.6rem;
    max-width: 480px; width: 94%;
    box-shadow: 0 32px 80px rgba(0,0,0,0.7);
    animation: fadeUp 0.4s cubic-bezier(0.22,1,0.36,1);
    max-height: 92vh; overflow-y: auto;
}
.modal-box.wide { max-width: 640px; }

@keyframes fadeUp {
    from { opacity:0; transform: translateY(20px) scale(0.97); }
    to   { opacity:1; transform: translateY(0)    scale(1);    }
}

.modal-logo {
    font-size: 3.2rem; text-align: center; margin-bottom: 0.6rem;
    animation: spin 4s ease-in-out infinite;
}
@keyframes spin {
    0%   { transform: rotate(-15deg); }
    25%  { transform: rotate(15deg); }
    50%  { transform: rotate(15deg); }
    75%  { transform: rotate(-15deg); }
    100% { transform: rotate(-15deg); }
}

h1 {
    text-align: center; font-size: 1.8rem; font-weight: 900;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #fff 40%, var(--teal));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 0.5rem;
}
.modal-sub {
    text-align: center; font-size: 0.88rem; color: var(--muted);
    line-height: 1.7; margin-bottom: 1.4rem;
}

.info-grid {
    display: grid; grid-template-columns: repeat(3,1fr); gap: 0.6rem;
    margin-bottom: 1rem;
}
.info-item {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; padding: 0.75rem 0.5rem;
    text-align: center; font-size: 0.75rem; color: var(--muted);
    line-height: 1.5;
}
.info-icon { display: block; font-size: 1.4rem; margin-bottom: 0.3rem; }

.calib-hint {
    background: rgba(56,189,248,0.07);
    border: 1px solid rgba(56,189,248,0.2);
    border-radius: 10px; padding: 0.7rem 0.9rem;
    display: flex; align-items: flex-start; gap: 0.6rem;
    font-size: 0.78rem; color: var(--muted); line-height: 1.6;
    margin-bottom: 1.2rem;
}
.calib-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.05rem; }
.calib-hint strong { color: var(--accent); }

.primary-btn {
    width: 100%; padding: 0.9rem;
    background: linear-gradient(135deg, #0d6c80, #2dd4bf);
    border: none; border-radius: 12px; color: white;
    font-family: 'Nunito',sans-serif; font-size: 1.05rem;
    font-weight: 900; letter-spacing: 2px; cursor: pointer;
    box-shadow: 0 4px 20px rgba(45,212,191,0.3);
    transition: transform 0.15s, box-shadow 0.15s;
}
.primary-btn:hover { transform: scale(1.02); box-shadow: 0 0 28px rgba(45,212,191,0.5); }

.secondary-btn {
    padding: 0.9rem 1.6rem;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 12px; color: var(--text);
    font-family: 'Nunito',sans-serif; font-size: 1rem;
    font-weight: 700; cursor: pointer; transition: all 0.15s;
}
.secondary-btn:hover { background: var(--surface); border-color: rgba(255,255,255,0.2); }

.danger-btn {
    padding: 0.55rem 1.2rem;
    background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.3);
    border-radius: 10px; color: var(--red);
    font-family: 'Nunito',sans-serif; font-size: 0.82rem;
    font-weight: 900; letter-spacing: 1px; cursor: pointer;
    transition: all 0.15s;
}
.danger-btn:hover:not(:disabled) { background: rgba(248,113,113,0.25); }
.danger-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.calib-btn {
    padding: 0.55rem 1rem;
    background: rgba(45,212,191,0.1); border: 1px solid rgba(45,212,191,0.3);
    border-radius: 10px; color: var(--teal);
    font-family: 'Nunito',sans-serif; font-size: 0.82rem;
    font-weight: 900; letter-spacing: 1px; cursor: pointer;
    transition: all 0.15s;
}
.calib-btn:hover:not(:disabled) { background: rgba(45,212,191,0.22); }
.calib-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.calib-btn.done {
    background: rgba(45,212,191,0.22);
    border-color: rgba(45,212,191,0.6);
    animation: calibPulse 0.4s ease-out;
}
@keyframes calibPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.privacy {
    text-align: center; font-size: 0.66rem;
    color: rgba(255,255,255,0.22); margin-top: 0.7rem;
}

/* ─── TOP BAR ──────────────────────────────────────────────── */
#top-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: 52px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.2rem;
    padding-right: 210px;
    background: rgba(11,15,26,0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

#cn-active-badge { top: 10px !important; }

.bar-left { display: flex; align-items: center; gap: 1rem; }
#session-timer { font-size: 1.3rem; color: var(--yellow); letter-spacing: 3px; }

.bar-center { display: flex; align-items: center; gap: 0.5rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-wait   { background: var(--muted); }
.dot-active { background: var(--teal); box-shadow: 0 0 8px var(--teal); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
#status-text { font-size: 0.82rem; color: var(--muted); font-weight: 700; }

.bar-right { display: flex; align-items: center; gap: 0.6rem; }

/* ─── APP LAYOUT ───────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }
#app.hidden { display: none; }

#main-content {
    display: flex;
    margin-top: 52px;
    height: calc(100vh - 52px);
    overflow: hidden;
}

/* ─── CAM PANEL ────────────────────────────────────────────── */
#cam-panel {
    position: relative;
    flex: 0 0 auto;
    width: 50%;
    background: #080c16;
    border-right: 1px solid var(--border);
}
#skeleton-canvas {
    width: 100%; height: 100%;
    display: block;
}
#cam-label {
    position: absolute; bottom: 10px; left: 50%;
    transform: translateX(-50%);
    font-size: 0.62rem; letter-spacing: 2px;
    color: var(--muted); font-weight: 700;
}

/* ─── METRICS PANEL ────────────────────────────────────────── */
#metrics-panel {
    flex: 1;
    display: flex; flex-direction: column;
    gap: 0.7rem; padding: 0.9rem 1rem;
    overflow-y: auto;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
}
.metric-title {
    font-size: 0.58rem; letter-spacing: 3px; font-weight: 900;
    color: var(--muted); margin-bottom: 0.65rem;
}

/* ─── ANGLE DISPLAY ────────────────────────────────────────── */
.angle-display {
    display: flex; align-items: baseline; gap: 0.8rem;
    margin-bottom: 0.65rem;
}
.angle-big {
    font-size: 2rem; font-weight: 900; color: var(--accent);
    line-height: 1;
}
.angle-dir {
    font-size: 0.78rem; font-weight: 900; letter-spacing: 2px;
    color: var(--muted); padding: 0.2rem 0.55rem;
    background: var(--surface2); border-radius: 6px;
    border: 1px solid var(--border);
}
.angle-dir.dir-right  { color: var(--col-right);  border-color: rgba(56,189,248,0.3);  background: rgba(56,189,248,0.08); }
.angle-dir.dir-left   { color: var(--col-left);   border-color: rgba(251,146,60,0.3);  background: rgba(251,146,60,0.08); }
.angle-dir.dir-flex   { color: var(--col-flex);   border-color: rgba(74,222,128,0.3);  background: rgba(74,222,128,0.08); }
.angle-dir.dir-ext    { color: var(--col-ext);    border-color: rgba(167,139,250,0.3); background: rgba(167,139,250,0.08); }
.angle-dir.dir-roll-r { color: var(--col-roll-r); border-color: rgba(251,191,36,0.3);  background: rgba(251,191,36,0.08); }
.angle-dir.dir-roll-l { color: var(--col-roll-l); border-color: rgba(248,113,113,0.3); background: rgba(248,113,113,0.08); }

/* ─── DUAL BARS ────────────────────────────────────────────── */
.dual-bars { display: flex; flex-direction: column; gap: 0.35rem; }

.dual-bar-row {
    display: flex; align-items: center; gap: 0.5rem;
}
.bar-label-left, .bar-label-right {
    font-size: 0.6rem; font-weight: 900; letter-spacing: 1px;
    color: var(--muted); width: 46px; flex-shrink: 0;
}
.bar-label-right { text-align: right; }

.half-track {
    flex: 1; height: 8px;
    background: rgba(255,255,255,0.06);
    border-radius: 4px; overflow: hidden;
}
.left-track { border-radius: 4px 0 0 4px; }
.right-track { border-radius: 0 4px 4px 0; }

.half-fill {
    height: 100%; width: 0%;
    border-radius: inherit;
    transition: width 0.18s;
}
/* right fill grows left-to-right from center */
.right-fill { background: linear-gradient(90deg, #0369a1, var(--col-right)); }
/* left fill grows right-to-left */
.left-fill  { background: linear-gradient(270deg, #9a3412, var(--col-left)); float: right; }

.flex-fill  { background: linear-gradient(90deg, #166534, var(--col-flex)); }
.ext-fill   { background: linear-gradient(270deg, #4c1d95, var(--col-ext)); float: right; }

.roll-r-fill { background: linear-gradient(90deg, #92400e, var(--col-roll-r)); }
.roll-l-fill { background: linear-gradient(270deg, #991b1b, var(--col-roll-l)); float: right; }

.dual-bar-maxes {
    display: flex; justify-content: space-between;
    font-size: 0.62rem; font-weight: 700;
}
.max-label { color: var(--muted); }
.left-max, .ext-max, .roll-l-max { color: var(--col-left); }
.right-max, .flex-max { }
.right-max  { color: var(--col-right); }
.flex-max   { color: var(--col-flex); }
.ext-max    { color: var(--col-ext); }
.roll-r-max { color: var(--col-roll-r); }
.roll-l-max { color: var(--col-roll-l); }

/* ─── SESSION MAX CHIPS ────────────────────────────────────── */
.session-max {
    display: flex; gap: 0.4rem; flex-wrap: wrap;
}
.max-chip {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; padding: 0.35rem 0.65rem;
    display: flex; flex-direction: column; align-items: center;
}
.max-chip-name { font-size: 0.55rem; color: var(--muted); letter-spacing: 1px; }
.max-chip-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem; font-weight: 700; color: var(--yellow);
}

/* ─── REPORT ───────────────────────────────────────────────── */
.report-title { font-size: 1.4rem; font-weight: 900; margin-bottom: 0.8rem; text-align: center; }

.report-meta {
    display: flex; gap: 1rem; justify-content: center;
    font-size: 0.8rem; color: var(--muted); margin-bottom: 1.2rem;
}

.report-section { margin-bottom: 1.2rem; }
.report-section h3 {
    font-size: 0.68rem; letter-spacing: 2px; color: var(--muted);
    font-weight: 900; margin-bottom: 0.7rem;
}

.report-angles {
    display: grid; grid-template-columns: repeat(3,1fr); gap: 0.5rem;
}
.ra-cell {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; padding: 0.6rem 0.4rem; text-align: center;
}
.ra-name  { font-size: 0.6rem; color: var(--muted); margin-bottom: 0.3rem; }
.ra-val   { font-family: 'JetBrains Mono',monospace; font-size: 1.3rem; font-weight: 700; }
.ra-sub   { font-size: 0.6rem; color: var(--muted); }

.report-compare {
    display: grid; grid-template-columns: repeat(3,1fr); gap: 0.5rem;
}
.cmp-cell {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; padding: 0.5rem 0.4rem; text-align: center;
}
.cmp-name   { font-size: 0.58rem; color: var(--muted); margin-bottom: 0.25rem; }
.cmp-delta  { font-size: 1rem; font-weight: 900; }
.cmp-delta.pos { color: var(--green); }
.cmp-delta.neg { color: var(--red); }
.cmp-delta.neu { color: var(--muted); }

.modal-actions { display: flex; gap: 0.7rem; margin-top: 0.5rem; }
.modal-actions .primary-btn { flex: 1; }

#report-chart { border-radius: 8px; background: var(--surface2); display: block; width: 100%; }

/* ─── CALIBRATION OVERLAY ──────────────────────────────────── */
#calib-overlay {
    position: absolute; inset: 0; z-index: 50;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
}
#calib-overlay.hidden { display: none; }
#calib-counter {
    font-family: 'JetBrains Mono', monospace;
    font-size: 6rem; font-weight: 900; color: var(--teal);
    text-shadow: 0 0 40px rgba(45,212,191,0.8);
}
