/* =====================================================================
   Physique (physique.js): Stats switch, body scan pane, scan flow,
   comparison, history, weight and measurements. Tokens only, see DESIGN.md.
   ===================================================================== */

/* ---------- Stats: Performances / Physique ---------- */

.stats-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    border-radius: 18px;
    background: var(--card-bg);
    border: 2px solid #ececfb;
    box-shadow: 0 3px 0 #e4e4f7;
}

.stats-switch button {
    height: 40px;
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.stats-switch button { position: relative; }

.stats-switch-crown {
    position: absolute;
    top: -12px;
    right: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border-radius: 8px;
    background: var(--gold);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 14px;
    white-space: nowrap;
    box-shadow: 0 2px 0 var(--gold-3d, #d97706), 0 0 0 2px var(--card-bg);
    pointer-events: none;
}

.stats-switch-crown svg { flex: 0 0 auto; }

.stats-switch button.active {
    background: var(--grad-primary);
    color: #fff;
    box-shadow: 0 3px 0 var(--primary-3d);
}

.stats-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stats-view[hidden] {
    display: none;
}

/* ---------- Shared bits ---------- */

.phy-cta {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.phy-note {
    margin: 10px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.phy-next {
    margin: 10px 0 0;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
}

.phy-note.is-warn {
    color: #b45309;
}

.phy-summary {
    margin: 12px 0 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text-primary);
}

.phy-more {
    width: 100%;
    margin-top: 14px;
}

.phy-delta {
    flex: none;
    min-width: 46px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--tint-primary);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 800;
    text-align: center;
    white-space: nowrap;
}

.phy-delta.is-stable {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.phy-icon-btn {
    flex: none;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 12px;
    background: var(--tint-primary);
    color: var(--primary-dark);
    cursor: pointer;
}

.phy-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 4px;
    border: 0;
    background: none;
    color: var(--primary-dark);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.phy-link.is-danger {
    width: 100%;
    margin-top: 10px;
    color: #dc2626;
}

/* ---------- State of a comparison ---------- */

.phy-state {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 12px 0 0;
    font-size: 13px;
    font-weight: 800;
}

.phy-state.is-ok { color: #15803d; }
.phy-state.is-caution { color: #b45309; }
.phy-state.is-different { color: #dc2626; }

.phy-reasons {
    margin: 4px 0 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

/* ---------- Gryno+ preview (not subscribed) ---------- */

.phy-plus-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #92400e;
    background: #fef3c7;
}

.phy-demo {
    position: relative;
    width: 100%;
    aspect-ratio: 170 / 118;
    border-radius: 18px;
    overflow: hidden;
    touch-action: pan-y;
    cursor: ew-resize;
    user-select: none;
    -webkit-user-select: none;
}

.phy-demo:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.phy-demo.is-dragging {
    touch-action: none;
}

.phy-demo svg {
    display: block;
    width: 100%;
    height: 100%;
}

.phy-demo-bg.is-before { fill: var(--bg-tertiary); }
.phy-demo-bg.is-after { fill: var(--tint-primary); }

.phy-demo-body {
    stroke-width: 0.9;
    stroke-linejoin: round;
}

.phy-demo-body.is-before {
    fill: var(--card-bg);
    stroke: var(--text-muted);
}

.phy-demo-body.is-after {
    fill: var(--tint-primary-strong);
    stroke: var(--primary);
}

.phy-demo-base {
    fill: var(--card-bg);
}

.phy-demo-ghost {
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 0.8;
    stroke-dasharray: 2.4 1.8;
}

.phy-demo.is-dragging .phy-split-handle i {
    transform: scale(1.12);
}

.phy-preview-pitch {
    margin: 4px 0 0;
    padding-top: 14px;
    border-top: 1px solid var(--border-light);
    font-size: 15px;
    font-weight: 800;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.phy-preview .phy-delta {
    background: var(--tint-success);
    color: #15803d;
}

.phy-preview-note {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0 14px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
}

.phy-preview-note svg {
    flex: none;
    color: var(--primary);
}

.phy-preview .phy-rows {
    margin-top: 8px;
}

/* ---------- Before the first scan ---------- */

.phy-first {
    border-style: dashed;
    box-shadow: none;
    text-align: center;
}

.phy-first-art {
    width: 100%;
    max-width: 260px;
    height: auto;
    margin: 0 auto;
    display: block;
}

.phy-first-art ellipse {
    fill: var(--primary);
    opacity: 0.1;
}

.phy-first-body {
    fill: var(--tint-primary);
    stroke: var(--primary);
    stroke-width: 1.6;
    stroke-linejoin: round;
}

.phy-first-detail {
    fill: none;
    stroke: var(--primary);
    stroke-width: 1.2;
    stroke-linecap: round;
    opacity: 0.45;
}

.phy-first p {
    margin: 12px 0 16px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-secondary);
}

/* ---------- Last scan ---------- */

.phy-trio {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.phy-thumb {
    position: relative;
    display: block;
    padding: 0;
    border: 0;
    border-radius: 16px;
    overflow: hidden;
    background: var(--bg-tertiary);
    aspect-ratio: 3 / 4;
    cursor: pointer;
}

.phy-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.phy-thumb > span {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(17, 14, 40, 0.62);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}

/* ---------- Since the previous scan ---------- */

.phy-evo-visual {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 18px;
    overflow: hidden;
    background: var(--bg-tertiary);
    touch-action: pan-y;
    cursor: ew-resize;
    user-select: none;
    -webkit-user-select: none;
}

.phy-evo-visual:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.phy-evo-visual canvas {
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.phy-evo-visual.is-ready canvas {
    opacity: 1;
}

.phy-evo-visual.is-dragging {
    touch-action: none;
}

.phy-split-handle,
.phy-stage-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    margin-left: -1.5px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(17, 14, 40, 0.14);
    pointer-events: none;
}

.phy-split-handle i {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 38px;
    height: 38px;
    margin: -19px 0 0 -19px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #fff;
    color: var(--primary-dark);
    box-shadow: 0 3px 0 #d6d4ea, 0 6px 16px rgba(30, 27, 75, 0.18);
    transition: transform 0.15s var(--ease-out);
}

.phy-evo-visual.is-dragging .phy-split-handle i {
    transform: scale(1.12);
}

.phy-evo-date,
.phy-stage-date {
    position: absolute;
    top: 10px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(17, 14, 40, 0.62);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    pointer-events: none;
}

.phy-evo-date.is-before,
.phy-stage-date.is-before { left: 8px; }

.phy-evo-date.is-after { left: auto; right: 10px; }

.phy-stage-date.is-after { left: calc(50% + 8px); }

.phy-stage-date.is-after.is-right { left: auto; right: 8px; }

.phy-rows {
    margin-top: 6px;
}

.phy-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.phy-row:last-child {
    border-bottom: 0;
}

.phy-row-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.phy-row-values {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.phy-row-values b {
    color: var(--text-primary);
    font-weight: 800;
}

/* ---------- Curves ---------- */

.phy-trend .pz-card-head,
.phy-metrics .pz-card-head {
    align-items: center;
}

.phy-chips {
    display: flex;
    gap: 6px;
    margin: -4px -16px 12px;
    padding: 0 16px 2px;
    overflow-x: auto;
    scrollbar-width: none;
}

.phy-chips::-webkit-scrollbar {
    display: none;
}

.phy-chips button {
    flex: none;
    padding: 7px 12px;
    border: 0;
    border-radius: 999px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}

.phy-chips button.active {
    background: var(--tint-primary-strong);
    color: var(--primary-dark);
    font-weight: 800;
}

.phy-hero {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
}

.phy-hero strong {
    font-family: 'Nunito', 'Inter', sans-serif;
    font-size: 34px;
    font-weight: 900;
    line-height: 1;
    color: var(--text-primary);
}

.phy-chart {
    position: relative;
}

.phy-chart .exo-chart {
    display: block;
    width: 100%;
    height: 110px;
}

.phy-chart .exo-chart-dots {
    height: 110px;
    margin-top: -110px;
}

/* ---------- Waiting for the second scan ---------- */

.phy-wait-visual {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    aspect-ratio: 4 / 3;
    border-radius: 18px;
    overflow: hidden;
    background: var(--bg-tertiary);
}

.phy-wait-visual img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.phy-wait-next {
    width: 100%;
    height: 100%;
    padding: 34px 0 12px;
    box-sizing: border-box;
    background: var(--tint-primary);
}

.phy-wait-next path {
    fill: none;
    stroke: var(--primary);
    stroke-opacity: 0.55;
    stroke-width: 1.4;
    stroke-dasharray: 3 3;
    vector-effect: non-scaling-stroke;
}

.phy-wait .phy-row-values b {
    color: var(--text-muted);
}

.phy-wait-chips span {
    flex: none;
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.phy-wait-chips span.active {
    background: var(--tint-primary);
    color: var(--primary-dark);
}

.phy-wait-curve {
    fill: none;
    stroke: var(--text-muted);
    stroke-opacity: 0.6;
    stroke-width: 2.5;
    stroke-dasharray: 6 6;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.phy-wait .exo-chart-dots i.phy-wait-dot {
    background: var(--card-bg);
    border: 2.5px dashed var(--text-muted);
}

.phy-wait-note {
    margin: 12px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.phy-history-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 18px;
    font-size: 15px;
    text-align: left;
}

.phy-history-btn span:first-of-type {
    flex: 1;
}

.phy-count {
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--tint-primary);
    font-size: 12px;
    font-weight: 800;
}

/* ---------- Weight and measurements ---------- */

.phy-metrics.is-empty {
    border-style: dashed;
    box-shadow: none;
}

.phy-metrics.is-empty h4 {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.phy-metrics.is-empty p {
    margin: 4px 0 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.phy-metrics.is-empty .btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.phy-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.phy-fields {
    display: flex;
    flex-direction: column;
}

.phy-field + .phy-field {
    border-top: 1px solid var(--border-light);
}

.phy-field-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-primary);
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.phy-field-head > span {
    flex: 1;
}

.phy-field-value {
    font-size: 15px;
    font-weight: 800;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.phy-field.is-set .phy-field-value {
    color: var(--primary-dark);
}

.phy-field-chevron {
    flex: none;
    color: var(--text-muted);
    transform: rotate(90deg);
    transition: transform 0.25s var(--ease-spring, ease);
}

.phy-field.is-open .phy-field-chevron {
    transform: rotate(-90deg);
}

.phy-ruler-panel {
    padding: 2px 0 14px;
    -webkit-user-select: none;
    user-select: none;
    animation: phyUnfold 0.3s var(--ease-spring, ease) both;
}

.phy-ruler-read {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
    color: var(--text-primary);
}

.phy-ruler-read strong {
    font-family: 'Nunito', 'Inter', sans-serif;
    font-size: 44px;
    font-weight: 900;
    line-height: 1.05;
    font-variant-numeric: tabular-nums;
}

.phy-ruler-read em {
    font-style: normal;
    font-size: 16px;
    font-weight: 800;
    color: var(--text-secondary);
}

/* Ticks are painted (no element per tick); the value sits under the
   fixed centre line. Half the width of padding on each side lets the
   ends reach the centre. */
.phy-ruler {
    position: relative;
    height: 64px;
    margin: 6px -4px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 50%;
    scrollbar-width: none;
    touch-action: pan-x;
    cursor: grab;
    -webkit-mask: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
    mask: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}

.phy-ruler::-webkit-scrollbar {
    display: none;
}

.phy-ruler:focus-visible {
    outline: none;
}

.phy-ruler-track {
    position: relative;
    height: 100%;
    box-sizing: content-box;
    padding-right: 2px;
    background:
        repeating-linear-gradient(90deg, var(--text-secondary) 0 2px, transparent 2px 100px) 0 0 / 100% 28px no-repeat,
        repeating-linear-gradient(90deg, var(--text-muted) 0 2px, transparent 2px 50px) 0 0 / 100% 20px no-repeat,
        repeating-linear-gradient(90deg, color-mix(in srgb, var(--text-muted) 55%, transparent) 0 2px, transparent 2px 10px) 0 0 / 100% 13px no-repeat;
}

.phy-ruler-track span {
    position: absolute;
    top: 32px;
    transform: translateX(-50%);
    margin-left: 1px;
    font-size: 12px;
    font-weight: 800;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.phy-ruler-wrap {
    position: relative;
}

.phy-ruler-wrap::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    width: 4px;
    height: 36px;
    margin-left: -2px;
    border-radius: 4px;
    background: var(--primary);
    pointer-events: none;
}

.phy-ruler-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 22px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.phy-ruler-foot .phy-link {
    padding: 2px 0;
    font-size: 13px;
}

@keyframes phyUnfold {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Sheets ---------- */

.phy-sheet-title {
    margin: 0 0 16px;
    text-align: left !important;
    font-size: 22px !important;
    font-weight: 800 !important;
    letter-spacing: -0.01em;
}

.phy-history {
    list-style: none;
    margin: 0;
    padding: 0;
}

.phy-history li + li {
    border-top: 1px solid var(--border-light);
}

.phy-history button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.phy-history img {
    width: 44px;
    height: 58px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--bg-tertiary);
}

.phy-history-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.phy-history-text strong {
    font-size: 15px;
    font-weight: 800;
    color: var(--text-primary);
}

.phy-history-text small {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.phy-chevron {
    color: var(--text-muted);
}

.phy-values {
    margin: 0;
}

.phy-values div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}

.phy-values div:last-child {
    border-bottom: 0;
}

.phy-values dt {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
}

.phy-values dd {
    margin: 0;
    font-family: 'Nunito', 'Inter', sans-serif;
    font-size: 18px;
    font-weight: 900;
    color: var(--text-primary);
}

.phy-issues {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
}

.phy-issues li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    font-weight: 600;
    color: #b45309;
}

/* Photo viewer */

.phy-viewer > .sheet-content {
    top: 0;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: calc(var(--safe-top, 0px) + 16px) 16px calc(var(--safe-bottom, 0px) + 18px);
    background: #0d0b1c;
}

.phy-viewer .sheet-close {
    align-self: flex-end;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.phy-viewer-date {
    margin: 0;
    color: rgba(255, 255, 255, 0.72);
    font-size: 14px;
    font-weight: 700;
}

.phy-viewer-img {
    flex: 1;
    min-height: 0;
    width: 100%;
    object-fit: contain;
    border-radius: 16px;
}

.phy-viewer-tabs {
    background: rgba(255, 255, 255, 0.1);
}

.phy-viewer-tabs button {
    color: rgba(255, 255, 255, 0.7);
    padding: 8px 14px;
    font-size: 13px;
}

/* Comparison */

.phy-pick {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 8px;
    margin-bottom: 12px;
}

.phy-pick label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
}

.phy-pick select {
    height: 42px;
    padding: 0 10px;
    border: 2px solid var(--border-light);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font: inherit;
    font-size: 15px;
    font-weight: 800;
}

.phy-pick-arrow {
    margin-bottom: 12px;
    color: var(--text-muted);
}

.phy-tabs {
    justify-content: center;
    margin-bottom: 12px;
}

.phy-tabs button {
    flex: 1;
    justify-content: center;
    padding: 8px 9px;
    font-size: 13px;
}

.phy-stage {
    position: relative;
    border-radius: 18px;
    overflow: hidden;
    background: var(--bg-tertiary);
    touch-action: pan-y;
}

.phy-stage canvas {
    display: block;
    width: 100%;
    height: auto;
}

.phy-stage.is-slider {
    touch-action: none;
    cursor: ew-resize;
}


.phy-stage-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 0 #d6d4ea;
}

.phy-modes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-top: 10px;
}

.phy-modes button {
    height: 36px;
    border: 0;
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.phy-modes button.active {
    background: var(--tint-primary-strong);
    color: var(--primary-dark);
}

.phy-range {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 12px;
    font-weight: 800;
    color: var(--text-muted);
}

.phy-range input {
    flex: 1;
    accent-color: var(--primary);
}

.phy-legend {
    display: flex;
    gap: 16px;
    margin: 12px 0 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
}

.phy-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.phy-legend i {
    width: 12px;
    height: 12px;
    border-radius: 4px;
}

.phy-legend i.is-wider { background: var(--primary); }
.phy-legend i.is-narrower { background: var(--gold); }

.phy-table {
    margin-top: 12px;
}

.phy-table-head,
.phy-table-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px 44px 58px;
    align-items: center;
    gap: 8px;
}

.phy-table-head {
    padding-bottom: 6px;
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    text-align: right;
}

.phy-table-row {
    padding: 10px 0;
    border-top: 1px solid var(--border-light);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
}

.phy-table-row span:first-child {
    text-align: left;
    font-weight: 700;
    color: var(--text-primary);
}

.phy-table-row b {
    color: var(--text-primary);
    font-weight: 800;
}

/* ---------- New scan: full screen ---------- */

.phy-scan {
    position: fixed;
    inset: 0;
    z-index: 160;
    display: flex;
    flex-direction: column;
}

.phy-scan.is-camera {
    background: #0d0b1c;
    color: #fff;
}

.phy-scan.is-page {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.phy-cam-top,
.phy-page-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(var(--safe-top, 0px) + 10px) 14px 10px;
}

.phy-cam-btn {
    flex: none;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
}

.phy-scan.is-page .phy-cam-btn {
    background: var(--card-bg);
    color: var(--text-primary);
    box-shadow: 0 3px 0 #e4e4f7;
}

.phy-cam-views {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.12);
}

.phy-cam-views button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 11px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: rgba(255, 255, 255, 0.75);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.phy-cam-views button.is-done {
    color: #86efac;
}

.phy-cam-views button.active {
    background: var(--grad-primary);
    color: #fff;
    box-shadow: 0 2px 0 var(--primary-3d);
}

.phy-cam-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
}

.phy-cam-frame {
    position: relative;
    flex: none;
    height: 100%;
    max-width: 100%;
    aspect-ratio: 3 / 4;
    border-radius: 22px;
    overflow: hidden;
    background: #1b1733;
}

.phy-cam-video {
    position: absolute;
    max-width: none;
}

.phy-cam-ghost {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.32;
    pointer-events: none;
}

.phy-cam-stage.is-mirrored .phy-cam-video,
.phy-cam-stage.is-mirrored .phy-cam-ghost,
.phy-cam-stage.is-mirrored .phy-cam-overlay {
    transform: scaleX(-1);
}

.phy-cam-guide {
    position: absolute;
    left: 50%;
    top: 7%;
    height: 86%;
    transform: translateX(-50%);
    pointer-events: none;
}

.phy-cam-guide path {
    fill: none;
    stroke: rgba(255, 255, 255, 0.55);
    stroke-width: 1.2;
    stroke-dasharray: 3 3;
    stroke-linejoin: round;
}

.phy-cam-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.phy-cam-count {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: 'Nunito', 'Inter', sans-serif;
    font-size: 120px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.phy-cam-count.is-tick {
    animation: phyTick 0.9s var(--ease-out) both;
}

@keyframes phyTick {
    from { transform: scale(1.35); opacity: 0; }
    20% { transform: scale(1); opacity: 1; }
    to { transform: scale(0.92); opacity: 0.85; }
}

.phy-cam-count[hidden] {
    display: none;
}

.phy-cam-frame.is-flash::after {
    content: '';
    position: absolute;
    inset: 0;
    background: #fff;
    animation: phyFlash 0.35s ease-out forwards;
    pointer-events: none;
}

@keyframes phyFlash {
    from { opacity: 0.9; }
    to { opacity: 0; }
}

.phy-cam-status {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 52px);
    margin: 0;
    padding: 9px 16px;
    border-radius: 18px;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.25;
    text-align: center;
    color: #fff;
    background: rgba(13, 11, 28, 0.7);
}

.phy-cam-status.is-ok { background: #16a34a; }
.phy-cam-status.is-warn { background: #d97706; }

.phy-cam-error {
    max-width: 280px;
    text-align: center;
}

.phy-cam-error p {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.85);
}

.phy-cam-error .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.phy-cam-panel {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: 'hint hint' 'tools shutter';
    align-items: center;
    gap: 12px 16px;
    padding: 14px 18px calc(var(--safe-bottom, 0px) + 16px);
}

.phy-cam-hint {
    grid-area: hint;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.78);
}

.phy-cam-hint b {
    color: #fff;
    font-weight: 800;
}

.phy-cam-tools {
    grid-area: tools;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.phy-tool {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.85);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.phy-tool.active {
    background: rgba(129, 140, 248, 0.3);
    color: #fff;
}

.phy-shutter {
    grid-area: shutter;
    width: 74px;
    height: 74px;
    padding: 6px;
    border: 4px solid #fff;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}

.phy-shutter span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--grad-primary);
    box-shadow: inset 0 -4px 0 var(--primary-3d);
    transition: transform 0.15s var(--ease-out);
}

.phy-shutter:active span,
.phy-shutter.is-counting span {
    transform: scale(0.86);
}

.phy-shutter:disabled {
    opacity: 0.4;
}

/* Review, data, result */

.phy-progress {
    flex: 1;
    display: flex;
    gap: 6px;
    max-width: 220px;
    margin-left: auto;
}

.phy-progress i {
    position: relative;
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}

.phy-progress i::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--grad-primary);
    transform: scaleX(0);
    transform-origin: left;
}

.phy-progress i.is-done::after,
.phy-progress i.is-current::after {
    transform: none;
}

.phy-progress.is-animated i.is-current::after {
    animation: phyFill 0.5s 0.1s var(--ease-spring, ease) both;
}

@keyframes phyFill {
    from { transform: scaleX(0); }
    to { transform: none; }
}

.phy-page-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 18px 18px;
}

.phy-page-body h2 {
    margin: 4px 0 16px;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.phy-page-bottom {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 18px calc(var(--safe-bottom, 0px) + 16px);
}

.phy-page-bottom .btn {
    width: 100%;
}

.phy-scan .phy-form.pz-card {
    padding: 4px 16px;
}

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

.phy-shot {
    position: relative;
    aspect-ratio: 3 / 4;
    padding: 0;
    border: 3px solid transparent;
    border-radius: 18px;
    overflow: hidden;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.phy-shot:active {
    transform: scale(0.97);
}

.phy-shot.is-warn {
    border-color: var(--gold);
}

.phy-shot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.phy-review-label {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(17, 14, 40, 0.62);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}

.phy-shot-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
}

.phy-shot-badge.is-ok { background: var(--success); box-shadow: 0 2px 0 var(--success-3d); }
.phy-shot-badge.is-warn { background: var(--gold); box-shadow: 0 2px 0 var(--gold-3d); }
.phy-shot-badge.is-busy { background: var(--card-bg); }
.phy-shot-badge.is-busy .phy-spinner { margin: 0; }
.phy-shot-badge.is-new { animation: phyBadge 0.45s var(--ease-spring, ease) both; }

@keyframes phyBadge {
    from { transform: scale(0) rotate(-30deg); }
    to { transform: none; }
}

.phy-review-busy {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
}

.phy-review-ok {
    margin-top: 16px;
}

.phy-review-issues {
    margin-top: 16px;
    padding: 4px 16px;
}

.phy-review-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
}

.phy-review-row + .phy-review-row {
    border-top: 1px solid var(--border-light);
}

.phy-review-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.phy-review-text b {
    font-size: 15px;
    font-weight: 800;
    color: var(--text-primary);
}

.phy-review-text span {
    font-size: 13px;
    font-weight: 700;
    color: #b45309;
}

.phy-review-row .phy-retake {
    flex: none;
    height: 38px;
    padding: 0 14px;
    border-radius: 12px;
    font-size: 14px;
}

.phy-review-issues + .phy-note {
    margin-top: 12px;
}

/* Screens come in from below, one block after the other. */
.phy-page-body.is-entering > *,
.phy-page-body.is-entering .phy-shot {
    animation: phyRise 0.45s var(--ease-spring, ease) both;
}

.phy-page-body.is-entering > :nth-child(2) { animation-delay: 60ms; }
.phy-page-body.is-entering > :nth-child(3) { animation-delay: 120ms; }
.phy-page-body.is-entering > :nth-child(n + 4) { animation-delay: 180ms; }
.phy-page-body.is-entering .phy-review { animation: none; }
.phy-page-body.is-entering .phy-shot { animation-delay: calc(80ms + var(--i) * 70ms); }

@keyframes phyRise {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
}

.phy-spinner {
    flex: none;
    width: 12px;
    height: 12px;
    margin-top: 1px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: phySpin 0.8s linear infinite;
}

@keyframes phySpin {
    to { transform: rotate(360deg); }
}

.phy-done {
    text-align: center;
}

.phy-done .phy-trio,
.phy-done .phy-values,
.phy-done .phy-rows {
    text-align: left;
}

.phy-done-hero {
    position: relative;
    width: 84px;
    height: 84px;
    margin: 28px auto 22px;
}

.phy-done-rays {
    position: absolute;
    inset: -70px;
    border-radius: 50%;
    background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--success) 22%, transparent) 0deg 9deg, transparent 9deg 24deg);
    -webkit-mask: radial-gradient(circle, #000 20%, transparent 66%);
    mask: radial-gradient(circle, #000 20%, transparent 66%);
    animation: phyRaysIn 0.6s 0.1s var(--ease-spring, ease) both, phySpin 30s linear infinite;
}

.phy-done-badge {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--grad-success);
    box-shadow: 0 6px 0 var(--success-3d);
    color: #fff;
    animation: phyBadge 0.6s 0.05s var(--ease-spring, ease) both;
}

.phy-done-badge svg {
    width: 44px;
    height: 44px;
}

.phy-done-badge path {
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    animation: phyDraw 0.35s 0.45s ease-out forwards;
}

.phy-done > h2 {
    position: relative;
    animation: phyRise 0.4s 0.3s var(--ease-spring, ease) both;
}

.phy-done .phy-thumb {
    cursor: default;
    animation: phyRise 0.45s var(--ease-spring, ease) both;
    animation-delay: calc(420ms + var(--i) * 80ms);
}

.phy-done > :nth-child(n + 4) {
    animation: phyRise 0.4s 0.7s var(--ease-spring, ease) both;
}

.phy-done .phy-state {
    justify-content: center;
}

@keyframes phyRaysIn {
    from { opacity: 0; scale: 0.4; }
    to { opacity: 1; scale: 1; }
}

@keyframes phyDraw {
    to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .phy-spinner,
    .phy-cam-count.is-tick,
    .phy-progress i::after,
    .phy-shot-badge,
    .phy-ruler-panel,
    .phy-page-body.is-entering > *,
    .phy-page-body.is-entering .phy-shot,
    .phy-done-rays,
    .phy-done-badge,
    .phy-done > *,
    .phy-done .phy-thumb { animation: none; }
    .phy-done-badge path { animation: none; stroke-dashoffset: 0; }
}

/* ---------- Dark mode ---------- */

html[data-theme="dark"] .stats-switch {
    border-color: #2e2850;
    box-shadow: 0 3px 0 #0b0918;
}

html[data-theme="dark"] .phy-state.is-ok { color: #4ade80; }

html[data-theme="dark"] .phy-state.is-caution,
html[data-theme="dark"] .phy-note.is-warn,
html[data-theme="dark"] .phy-issues li { color: #fbbf24; }

html[data-theme="dark"] .phy-state.is-different,
html[data-theme="dark"] .phy-link.is-danger { color: #f87171; }

html[data-theme="dark"] .phy-pick select {
    border-color: #2e2850;
}

html[data-theme="dark"] .phy-preview .phy-delta {
    color: #4ade80;
}

html[data-theme="dark"] .phy-plus-chip {
    color: #fcd34d;
    background: rgba(245, 158, 11, 0.16);
}

html[data-theme="dark"] .phy-scan.is-page .phy-cam-btn {
    box-shadow: 0 3px 0 #0b0918;
}

html[data-theme="dark"] .phy-stage-handle::after,
html[data-theme="dark"] .phy-split-handle i {
    box-shadow: 0 2px 0 #0b0918;
}

html[data-theme="dark"] .phy-review-text span { color: #fbbf24; }

html[data-theme="dark"] .phy-field.is-set .phy-field-value { color: #a5b4fc; }

/* The photo stays the main surface; controls wrap within a 375px viewport. */
.phy-compare-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.phy-compare-head .phy-sheet-title { margin: 0; }
.phy-compare-head .sheet-close { position: static; flex: none; }
.phy-pick label, .phy-pick select { min-width: 0; max-width: 100%; }
.phy-compare-sheet .phy-modes { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.phy-compare-sheet .phy-modes button { grid-column: span 2; }
.phy-compare-sheet .phy-modes button:nth-child(n + 4) { grid-column: span 3; }
.phy-compare-sheet .phy-modes button { min-height: 44px; height: auto; padding: 8px 4px; }
.phy-modes button:disabled { opacity: .4; cursor: default; }
.phy-focus { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.phy-focus button { flex: 1 1 auto; min-height: 44px; padding: 8px; border: 0; border-radius: 12px; background: transparent; color: var(--text-secondary); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.phy-focus button[aria-pressed="true"] { background: var(--tint-primary); color: var(--primary); }
.phy-stage:focus-visible, .phy-focus button:focus-visible, .phy-modes button:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.phy-stage-message { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; padding: 24px; text-align: center; background: var(--bg-tertiary); color: var(--text-secondary); font-size: 14px; font-weight: 700; }
.phy-stage-message[hidden] { display: none; }
.phy-stage-handle { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--card-bg); pointer-events: none; }
.phy-compare-sheet .phy-stage-handle::after { content: none; }
.phy-stage-handle i { position: absolute; top: 50%; left: 50%; display: grid; place-content: center; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; background: var(--card-bg); color: var(--primary); box-shadow: 0 2px 0 var(--border-light); }
.phy-legend i { width: 22px; height: 0; border-radius: 0; border-top: 3px solid var(--primary); }
.phy-legend i.is-before { border-color: var(--text-secondary); border-top-style: dashed; }
.phy-timeline { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; margin-top: 12px; }
.phy-timeline input { width: 100%; min-width: 0; min-height: 44px; accent-color: var(--primary); }
.phy-timeline-date, .phy-timeline .phy-note { grid-column: 1 / -1; margin: 0; text-align: center; color: var(--text-secondary); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.phy-timeline .phy-note { font-weight: 500; }
.phy-reasons:empty { display: none; }

.phy-table-row span:first-child { min-width: 0; overflow-wrap: anywhere; }
