:root {
    --ink: #182230;
    --muted: #667085;
    --line: #d0d5dd;
    --surface: #ffffff;
    --canvas: #eef1f4;
    --red: #b4232c;
    --red-dark: #8f1d24;
    --blue: #175cd3;
    --navy: #172b4d;
    --green: #137a4a;
    --amber: #b54708;
    --danger: #b42318;
    --focus: #84adff;
    --shadow: 0 10px 28px rgba(24, 34, 48, 0.12);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--ink);
    background: var(--canvas);
    letter-spacing: 0;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--canvas);
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--canvas);
}

button,
input {
    font: inherit;
    letter-spacing: 0;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

[hidden] {
    display: none !important;
}

.site-header {
    position: sticky;
    z-index: 30;
    top: 0;
    display: flex;
    min-height: 72px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px clamp(16px, 3vw, 40px);
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border-radius: 6px;
    background: var(--red);
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
}

.brand h1,
.brand p,
.section-heading h2,
.name-dialog h2,
.login-form h2,
.inspector h2,
.history-dialog h2 {
    margin: 0;
}

.brand h1 {
    overflow: hidden;
    max-width: min(68vw, 760px);
    font-size: clamp(17px, 2vw, 22px);
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand p {
    margin-top: 3px;
    font-size: 13px;
}

.muted {
    color: var(--muted);
}

.save-status,
.publish-state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.save-status::before,
.publish-state::before {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    content: "";
}

.save-status.is-error,
.publish-state.is-draft {
    color: var(--amber);
}

main {
    width: 100%;
}

.waiting-state {
    display: flex;
    min-height: calc(100vh - 132px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    padding: 32px;
    text-align: center;
}

.waiting-state strong {
    font-size: 26px;
}

.waiting-state span {
    color: var(--muted);
}

.photo-section {
    border-bottom: 1px solid var(--line);
    background: #111820;
}

.viewer-toolbar,
.admin-toolbar {
    display: flex;
    min-height: 54px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px clamp(12px, 3vw, 40px);
}

.viewer-toolbar {
    color: #fff;
    background: #111820;
}

.progress-copy {
    display: flex;
    align-items: baseline;
    gap: 7px;
}

.progress-copy strong {
    font-size: 18px;
}

.progress-copy span {
    color: #b8c0cc;
    font-size: 13px;
}

.viewer-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.marker-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #d0d5dd;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.marker-toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.toggle-track {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
    border: 1px solid #667085;
    border-radius: 10px;
    background: #344054;
}

.toggle-track span {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    transition: transform 160ms ease;
}

.marker-toggle input:checked + .toggle-track {
    border-color: #67e0a3;
    background: #137a4a;
}

.marker-toggle input:checked + .toggle-track span {
    transform: translateX(14px);
}

.marker-toggle input:focus-visible + .toggle-track {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.zoom-controls {
    display: inline-grid;
    grid-template-columns: 38px 58px 38px;
    align-items: center;
    overflow: hidden;
    border: 1px solid #475467;
    border-radius: 6px;
}

.icon-button,
.zoom-value {
    display: grid;
    height: 36px;
    place-items: center;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.icon-button {
    width: 38px;
    font-size: 22px;
    line-height: 1;
}

.zoom-value {
    width: 58px;
    border-right: 1px solid #475467;
    border-left: 1px solid #475467;
    font-size: 12px;
    font-weight: 700;
}

.photo-viewport {
    position: relative;
    overflow: auto;
    width: 100%;
    max-height: min(76vh, 900px);
    overscroll-behavior: contain;
    scrollbar-color: #667085 #111820;
}

.photo-canvas {
    position: relative;
    min-width: 100%;
    margin: 0 auto;
    line-height: 0;
    user-select: none;
}

.photo-canvas > img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

.marker-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    transition: opacity 140ms ease;
}

.marker-layer.is-hidden {
    visibility: hidden;
    opacity: 0;
}

.person-marker {
    --marker-color: #f6d44a;
    position: absolute;
    z-index: 2;
    display: grid;
    width: 4.8%;
    min-width: 34px;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    place-items: center;
    border: 2px solid var(--marker-color);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: 0 0 0 1px rgba(17, 24, 32, 0.72), inset 0 0 0 1px rgba(255, 255, 255, 0.72);
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    pointer-events: auto;
    touch-action: none;
}

.person-marker::before {
    position: absolute;
    right: -7px;
    bottom: -7px;
    display: grid;
    width: 20px;
    height: 20px;
    place-items: center;
    border-radius: 50%;
    background: var(--marker-color);
    box-shadow: 0 1px 4px rgba(17, 24, 32, 0.45);
    color: #182230;
    content: attr(data-order);
    font-size: 10px;
}

.person-marker.has-name {
    --marker-color: #67e0a3;
}

.person-marker.is-selected {
    --marker-color: #ff7a59;
    z-index: 5;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 5px 16px rgba(0, 0, 0, 0.3);
}

.person-marker:hover {
    background: rgba(246, 212, 74, 0.1);
}

.marker-name {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    max-width: 150px;
    transform: translateX(-50%);
    padding: 5px 7px;
    border-radius: 4px;
    background: rgba(17, 24, 32, 0.9);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    opacity: 0;
    overflow-wrap: anywhere;
    pointer-events: none;
    visibility: hidden;
    white-space: nowrap;
}

.person-marker:hover .marker-name,
.person-marker:focus-visible .marker-name,
.person-marker.is-selected .marker-name {
    visibility: visible;
    opacity: 1;
}

.name-section {
    padding: 32px clamp(16px, 4vw, 64px) 48px;
    background: var(--surface);
}

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 20px;
    max-width: 1280px;
    margin: 0 auto 18px;
}

.section-heading h2 {
    font-size: 20px;
}

.section-heading span {
    font-size: 12px;
}

.name-list {
    display: grid;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
    list-style: none;
}

.name-list li {
    display: flex;
    min-height: 52px;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.list-number {
    width: 26px;
    flex: 0 0 26px;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.list-name {
    overflow: hidden;
    font-size: 14px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-name.is-empty {
    color: #98a2b3;
    font-weight: 500;
}

.site-footer {
    display: flex;
    min-height: 60px;
    align-items: center;
    justify-content: space-between;
    padding: 14px clamp(16px, 4vw, 64px);
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
}

.site-footer a {
    color: var(--muted);
    text-decoration: none;
}

dialog {
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--ink);
}

dialog::backdrop {
    background: rgba(17, 24, 32, 0.68);
    backdrop-filter: blur(3px);
}

.name-dialog {
    width: min(92vw, 460px);
}

.name-dialog form {
    padding: 24px;
}

.dialog-head,
.dialog-title-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.dialog-head {
    margin-bottom: 22px;
}

.dialog-head .close-button {
    margin-left: auto;
    align-self: flex-start;
    color: var(--muted);
}

.face-preview {
    width: 76px;
    height: 76px;
    flex: 0 0 76px;
    overflow: hidden;
    border: 3px solid #f6d44a;
    border-radius: 50%;
    background-color: var(--canvas);
    background-repeat: no-repeat;
}

.eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--red);
    font-size: 12px;
    font-weight: 800;
}

.name-dialog h2,
.login-form h2,
.inspector h2,
.history-dialog h2 {
    font-size: 20px;
}

.field-label,
.range-label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    height: 46px;
    padding: 0 12px;
    border: 1px solid #98a2b3;
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-size: 16px;
}

input[type="text"]:focus,
input[type="password"]:focus {
    border-color: var(--blue);
}

.form-error {
    min-height: 20px;
    margin: 7px 0 0;
    color: var(--danger);
    font-size: 13px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 750;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

.button-primary {
    border-color: var(--red);
    background: var(--red);
    color: #fff;
}

.button-primary:hover {
    border-color: var(--red-dark);
    background: var(--red-dark);
}

.button-secondary {
    border-color: #98a2b3;
    background: #fff;
    color: var(--ink);
}

.button-quiet {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
}

.button-danger {
    border-color: #fecdca;
    background: #fff;
    color: var(--danger);
}

.button-block {
    width: 100%;
}

.toast {
    position: fixed;
    z-index: 100;
    right: 20px;
    bottom: 20px;
    max-width: min(390px, calc(100vw - 32px));
    padding: 12px 16px;
    border-radius: 6px;
    background: #182230;
    box-shadow: var(--shadow);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.toast.is-error {
    background: #7a271a;
}

/* Admin */
.admin-page {
    background: #e8edf3;
}

.admin-header {
    position: relative;
}

.admin-header .brand-mark {
    background: var(--navy);
}

.header-actions,
.toolbar-actions,
.stats-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-main {
    min-height: calc(100vh - 72px);
}

.login-panel {
    display: grid;
    min-height: calc(100vh - 72px);
    place-items: center;
    padding: 30px 16px;
}

.login-form {
    width: min(100%, 390px);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(23, 43, 77, 0.1);
}

.login-form h2 {
    margin-bottom: 24px;
}

.admin-workspace {
    min-height: calc(100vh - 72px);
}

.admin-toolbar {
    border-bottom: 1px solid #344054;
    background: var(--navy);
    color: #fff;
}

.stats-row {
    gap: 18px;
    font-size: 13px;
}

.stats-row strong {
    font-size: 17px;
}

.segmented {
    display: grid;
    overflow: hidden;
    grid-template-columns: repeat(2, 1fr);
    border: 1px solid #667085;
    border-radius: 6px;
}

.segmented button {
    min-width: 62px;
    height: 36px;
    border: 0;
    border-right: 1px solid #667085;
    background: transparent;
    color: #d0d5dd;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

.segmented button:last-child {
    border-right: 0;
}

.segmented button.is-active {
    background: #fff;
    color: var(--navy);
}

.workbench {
    display: grid;
    min-height: calc(100vh - 126px);
    grid-template-columns: minmax(0, 1fr) 290px;
}

.admin-photo-viewport {
    max-height: calc(100vh - 126px);
    background: #111820;
}

.admin-photo-canvas.is-adding {
    cursor: crosshair;
}

.admin-photo-canvas.is-locked .person-marker {
    cursor: default;
}

.inspector {
    position: relative;
    z-index: 6;
    padding: 24px 20px;
    border-left: 1px solid var(--line);
    background: var(--surface);
}

.inspector-top {
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
}

#selectionControls {
    padding: 20px 0;
    border-bottom: 1px solid var(--line);
}

.range-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.range-label output {
    color: var(--blue);
    font-variant-numeric: tabular-nums;
}

input[type="range"] {
    width: 100%;
    margin: 2px 0 18px;
    accent-color: var(--blue);
}

.state-details {
    margin: 20px 0;
}

.state-details div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #eaecf0;
}

.state-details dt,
.state-details dd {
    margin: 0;
    font-size: 13px;
}

.state-details dt {
    color: var(--muted);
}

.state-details dd {
    max-width: 150px;
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.publish-button {
    margin-bottom: 10px;
}

.history-dialog {
    width: min(94vw, 720px);
    max-height: min(82vh, 760px);
}

.dialog-title-row {
    position: sticky;
    z-index: 2;
    top: 0;
    justify-content: space-between;
    padding: 20px 22px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.history-list {
    min-height: 160px;
    padding: 0 22px 22px;
}

.history-entry {
    display: grid;
    align-items: center;
    gap: 14px;
    padding: 14px 0;
    grid-template-columns: 54px minmax(0, 1fr) auto;
    border-bottom: 1px solid var(--line);
}

.history-revision {
    color: var(--blue);
    font-size: 13px;
    font-weight: 800;
}

.history-summary {
    min-width: 0;
}

.history-summary strong,
.history-summary span {
    display: block;
}

.history-summary strong {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-summary span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.empty-history {
    padding: 48px 0;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 820px) {
    .workbench {
        display: flex;
        min-height: auto;
        flex-direction: column;
    }

    .admin-photo-viewport {
        max-height: 64vh;
    }

    .inspector {
        border-top: 1px solid var(--line);
        border-left: 0;
    }
}

@media (max-width: 640px) {
    .site-header {
        min-height: 64px;
        padding: 9px 12px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
        font-size: 18px;
    }

    .brand h1 {
        max-width: 62vw;
        font-size: 16px;
    }

    .brand p {
        font-size: 11px;
    }

    .save-status {
        font-size: 0;
    }

    .viewer-toolbar,
    .admin-toolbar {
        padding: 7px 10px;
    }

    .photo-viewport {
        max-height: 68vh;
    }

    .marker-name {
        max-width: 110px;
        font-size: 12px;
    }

    .name-section {
        padding: 24px 12px 36px;
    }

    .name-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .name-dialog form {
        padding: 18px;
    }

    .face-preview {
        width: 64px;
        height: 64px;
        flex-basis: 64px;
    }

    .header-actions .button-quiet {
        display: none;
    }

    .admin-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-actions {
        justify-content: space-between;
    }

    .stats-row {
        justify-content: space-between;
    }

    .history-entry {
        grid-template-columns: 48px minmax(0, 1fr);
    }

    .history-entry .button {
        grid-column: 1 / -1;
    }
}
