:root {
    color-scheme: dark;
    --bg: #140c1c;
    --surface: #24142c;
    --raised: #302039;
    --gold: #ffd54f;
    --text: #f7f2f8;
    --muted: #b9aebf;
    --line: #49364f;
    --t1: #ff5252;
    --t2: #ffab40;
    --t3: #00e676;
    --t4: #40c4ff;
    --t5: #b0bec5;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "PingFang SC",
        "Microsoft YaHei",
        sans-serif;
}
* {
    box-sizing: border-box;
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
}
button,
input,
select {
    font: inherit;
}
button,
a,
input,
select {
    -webkit-tap-highlight-color: transparent;
}
button,
a {
    touch-action: manipulation;
}
button {
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--raised);
    color: var(--text);
    padding: 12px 16px;
    min-height: 46px;
    cursor: pointer;
}
button:hover {
    filter: brightness(1.12);
}
button:disabled {
    opacity: 0.45;
    cursor: default;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
}
.primary {
    background: var(--gold);
    color: #24142c;
    border-color: var(--gold);
    font-weight: 650;
}
.quiet {
    background: transparent;
    border-color: transparent;
    padding: 9px 11px;
}
.wide {
    width: 100%;
}
[hidden] {
    display: none !important;
}
.studio {
    max-width: 1040px;
    margin: auto;
    padding: calc(22px + env(safe-area-inset-top))
        max(
            clamp(16px, 4vw, 40px),
            env(safe-area-inset-left),
            env(safe-area-inset-right)
        )
        calc(22px + env(safe-area-inset-bottom));
}
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding-bottom: 30px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    text-decoration: none;
    font-weight: 650;
    white-space: nowrap;
}
.brand small {
    display: block;
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--muted);
    font-weight: 400;
    margin-top: 4px;
}
.brand-mark {
    display: block;
    flex: none;
    object-fit: contain;
    width: 45px;
    height: 45px;
    border-radius: 12px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}
.header-actions select {
    width: 70px;
}
.header-actions button {
    font-size: 12px;
    padding: 8px;
}
.header-actions form {
    margin: 0;
}
h1 {
    font-size: clamp(29px, 5vw, 44px);
    line-height: 1.16;
    letter-spacing: -1px;
    white-space: pre-line;
    margin: 14px 0 16px;
}
h2 {
    font-size: 19px;
    line-height: 1.3;
    margin: 0 0 16px;
}
p {
    color: var(--muted);
    margin: 10px 0 18px;
}
.eyebrow {
    display: block;
    color: var(--gold);
    font-size: 12px;
    letter-spacing: 1.3px;
    margin-top: 12px;
}
.section-title {
    max-width: 560px;
}
.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 24px 0;
}
.fine {
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
}
.card,
.record-card,
.word-card,
.candidate {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 20px;
    margin: 18px 0;
}
.library {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr));
    gap: 14px;
}
.word-card {
    margin: 0;
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
}
.word-glyph {
    font-size: 34px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.word-content {
    flex: 1;
    min-width: 100px;
}
.word-content strong {
    display: block;
    font-size: 15px;
}
.word-content p {
    font-size: 13px;
    margin: 3px 0;
}
.badge,
.tone-tag {
    border-radius: 18px;
    background: var(--raised);
    padding: 5px 9px;
    color: var(--muted);
    font-size: 11px;
}
.word-card button {
    font-size: 12px;
    padding: 7px 10px;
    min-height: 40px;
}
.record-card {
    text-align: center;
    padding: 26px 18px;
}
.record-button {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    min-width: 155px;
    min-height: 80px;
    margin: 10px auto;
    border: 1px solid var(--gold);
    background: #392739;
    color: var(--gold);
    border-radius: 28px;
}
.record-button > span:first-child {
    font-size: 25px;
}
.record-button.recording {
    background: #5c203b;
    color: #ffb4b4;
    border-color: var(--t1);
}
.file-label {
    font-size: 14px;
    cursor: pointer;
    margin: 18px 0;
}
.file-label input {
    display: block;
    margin: 12px auto;
    max-width: 100%;
    font-size: 12px;
}
label {
    display: block;
    margin: 12px 0;
    color: var(--muted);
    font-size: 13px;
}
input:not([type="checkbox"]):not([type="range"]):not([type="file"]),
select {
    display: block;
    width: 100%;
    min-height: 48px;
    background: #1a1023;
    border: 1px solid var(--line);
    border-radius: 13px;
    color: var(--text);
    padding: 10px 12px;
    font-size: 16px;
    margin-top: 7px;
}
input[type="checkbox"] {
    accent-color: var(--gold);
    width: 21px;
    height: 21px;
    flex: none;
}
input[type="range"] {
    accent-color: var(--gold);
    width: 100%;
    min-height: 34px;
}
.range-grid,
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.row h2 {
    margin: 0;
}
.compact {
    display: flex;
    gap: 3px;
}
.compact button {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 38px;
}
#waveform {
    margin: 20px 0;
    background: #1a1023;
    border-radius: 13px;
    overflow: hidden;
    min-height: 80px;
}
#waveform::part(region-handle-left),
#waveform::part(region-handle-right) {
    min-width: 12px;
}
#range-label {
    font-variant-numeric: tabular-nums;
}
.notice {
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 16px;
    margin: 12px 0;
    padding: 13px 16px;
    color: var(--text);
    font-size: 14px;
    overflow-wrap: anywhere;
}
.notice.error {
    border-color: #a84767;
    color: #ffd2db;
}
.candidate-head {
    display: flex;
    align-items: center;
    gap: 10px;
}
.candidate-head button {
    flex: 1;
    text-align: left;
    padding: 7px 11px;
    background: transparent;
    border: 0;
}
.candidate-head span {
    display: block;
}
.candidate-head .candidate-meaning {
    font-size: 13px;
    color: var(--muted);
}
.candidate.active {
    border-color: var(--gold);
}
.candidate .raw {
    margin: 5px 0 8px;
    font-size: 11px;
    color: var(--muted);
    overflow-wrap: anywhere;
}
.alternatives {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
}
.alternative {
    min-width: 88px;
    max-width: 180px;
    flex: 1;
    padding: 10px;
}
.alternative strong {
    display: block;
    font-size: 28px;
    font-weight: 500;
}
.alternative small {
    display: block;
    font-size: 12px;
    overflow-wrap: anywhere;
}
.alternative[aria-pressed="true"] {
    border-color: var(--gold);
    background: #3c2c30;
}
.mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin: 15px 0;
}
.mode-tabs button {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    min-height: 80px;
    font-size: 12px;
    padding: 9px 5px;
    background: #190f22;
}
.mode-tabs button > svg {
    flex: none;
}
.mode-tabs button > span {
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.25;
}
.mode-tabs [aria-pressed="true"] {
    border-color: var(--gold);
    color: var(--gold);
    background: #3b2c30;
}
.save-actions {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
}
audio {
    display: block;
    width: 100%;
    margin: 12px 0;
}
.studio-footer {
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    padding: 32px 0 5px;
}
.login-card {
    max-width: 430px;
    margin: 7vh auto;
    padding: 26px 22px;
}
.login-card h1 {
    font-size: 34px;
    margin-top: 36px;
}
.login-card .primary {
    margin-top: 20px;
}
.empty {
    padding: 40px 15px;
    text-align: center;
    color: var(--muted);
    grid-column: 1/-1;
}
.status-text {
    font-size: 12px;
    color: var(--gold);
    margin: 8px 0 0;
}
.candidate-status {
    font-size: 11px;
    color: var(--muted);
}
#editor input[lang="zh"] {
    font-size: 25px;
}
.saved-word {
    border-color: #327850;
}
.busy {
    opacity: 0.7;
    pointer-events: none;
}
@media (min-width: 760px) {
    #capture-view {
        max-width: 670px;
        margin: auto;
    }
    .login-card {
        border: 1px solid var(--line);
        border-radius: 28px;
        background: var(--surface);
        margin-top: 8vh;
        padding: 34px;
    }
    .studio {
        padding-top: 28px;
    }
}
@media (max-width: 360px) {
    .brand small {
        font-size: 9px;
        letter-spacing: 1px;
    }
    .brand {
        font-size: 14px;
        gap: 8px;
    }
    .brand-mark {
        width: 37px;
        height: 37px;
    }
    .header-actions {
        gap: 0;
    }
    .header-actions select {
        width: 58px;
    }
    .header-actions button {
        font-size: 10px;
        padding: 4px;
    }
    .card,
    .candidate {
        padding: 15px;
    }
    .form-grid {
        gap: 9px;
    }
    .mode-tabs {
        gap: 4px;
    }
}

.translation-control {
    position: relative;
}
.translation-control
    input:not([type="checkbox"]):not([type="range"]):not([type="file"]) {
    min-width: 0;
    margin-top: 0;
    padding-right: 48px;
}
.translation-control button {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #8bd7b0;
}
.translation-icon {
    position: relative;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #8bd7b012;
    border: 1px solid #8bd7b045;
}
.translation-control button:hover .translation-icon {
    background: #8bd7b025;
    border-color: #8bd7b080;
}
.translation-control button[aria-busy="true"] .translation-icon svg {
    visibility: hidden;
}
.translation-control button[aria-busy="true"] .translation-icon::after {
    content: "";
    position: absolute;
    width: 11px;
    height: 11px;
    border: 1.5px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: translation-spin 0.8s linear infinite;
}
@keyframes translation-spin {
    to {
        transform: rotate(360deg);
    }
}
@media (prefers-reduced-motion: reduce) {
    .translation-control button[aria-busy="true"] .translation-icon::after {
        animation: none;
    }
}
.translation-field label {
    margin-bottom: 7px;
}
/* Compact lists and one focused editor, independent of list length. */
.library {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.list-toolbar {
    display: flex;
    gap: 10px;
    align-items: end;
}
.search-field {
    flex: 1;
    min-width: 0;
}
.page-size {
    width: 94px;
    flex: none;
}
.list-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 12px 0;
}
.list-summary p {
    margin: 0;
}
.pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.pagination button {
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 24px;
    border-radius: 10px;
}
.compact-word {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    min-height: 76px;
}
.drag-handle {
    display: grid;
    place-items: center;
    align-self: stretch;
    flex: 0 0 24px;
    color: var(--muted);
    cursor: grab;
    touch-action: none;
    user-select: none;
    font-size: 23px;
    border-radius: 8px;
}
.drag-handle:hover {
    color: var(--gold);
    background: #ffd54f12;
}
.drag-handle.disabled {
    opacity: 0.35;
    cursor: default;
}
.word-drag-chosen .drag-handle {
    cursor: grabbing;
}
.word-drop-slot {
    opacity: 0.3;
    border: 1px dashed var(--gold);
}
.word-drag-preview {
    opacity: 0.95;
    box-shadow: 0 12px 32px #0006;
}
@media (pointer: coarse) {
    .drag-handle {
        flex-basis: 28px;
    }
}
.compact-word.active {
    border-color: var(--gold);
}
.compact-word.saved-word {
    border-color: #327850;
}
.word-open {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    text-align: left;
    padding: 5px;
    border: 0;
    background: transparent;
    border-radius: 10px;
}
.word-open .word-glyph {
    font-size: 25px;
    max-width: 76px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: none;
}
.compact-text {
    font-size: 12px;
    line-height: 1.25;
    flex: 1;
    min-width: 0;
}
.compact-text strong,
.compact-text .meaning {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.compact-text strong {
    font-size: 12px;
}
.compact-text .meaning {
    font-size: 12px;
    color: var(--muted);
    margin: 3px 0;
}
.compact-text .badge {
    display: inline-block;
    padding: 1px 5px;
    font-size: 9px;
}
.row-actions,
.order-buttons {
    display: flex;
    gap: 0;
    align-items: center;
    flex: none;
}
.row-actions button,
.order-buttons button {
    width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 17px;
    border-radius: 10px;
}
.row-actions button {
    width: 44px;
}
#candidate-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.compact-word input[type="checkbox"] {
    margin: 0 2px 0 5px;
    flex: none;
}
.selection-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 0;
    background: var(--bg);
    border-top: 1px solid var(--line);
    margin-top: 14px;
}
.preview-bar {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 10px 14px;
    margin-top: 14px;
}
.preview-bar > span {
    font-size: 12px;
}
.preview-bar audio {
    margin: 8px 0 0;
}
#word-sheet {
    width: min(100%, 740px);
    max-width: 100vw;
    max-height: min(94dvh, var(--sheet-height, 94dvh));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 24px 24px 0 0;
    background: var(--bg);
    color: var(--text);
    position: fixed;
    inset: auto 0 0;
    margin: 0 auto;
}
#word-sheet[open] {
    display: flex;
    flex-direction: column;
}
#word-sheet::backdrop {
    background: #08040db3;
    backdrop-filter: blur(4px);
}
.sheet-header {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    gap: 10px;
}
.sheet-header .eyebrow {
    margin: 0 0 5px;
}
.sheet-header h2 {
    margin: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.sheet-header button {
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 25px;
    flex: none;
}
.sheet-scroll {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 18px;
}
#word-sheet .save-actions {
    flex: none;
    position: static;
    padding: 12px 18px max(12px, env(safe-area-inset-bottom));
    margin: 0;
}
#word-sheet .card {
    margin: 14px 0;
    padding: 16px;
    border-radius: 18px;
}
#word-sheet #wave-card {
    padding: 12px;
}
#word-sheet #editor {
    background: transparent;
    border: 0;
    padding: 0;
}
#sheet-source {
    margin: 18px 0;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
}
#sheet-source > summary {
    cursor: pointer;
    font-size: 14px;
}
#sheet-source-label {
    margin-top: 16px;
}
#sheet-alternatives:empty {
    display: none;
}
#sheet-selection {
    margin-bottom: 16px;
}
body.sheet-open {
    overflow: hidden;
}
@media (min-width: 760px) {
    #word-sheet {
        inset: 0;
        margin: auto;
        border-radius: 24px;
    }
}
@media (max-width: 360px) {
    .word-open {
        gap: 5px;
    }
    .word-open .word-glyph {
        max-width: 55px;
        font-size: 23px;
    }
    .row-actions button,
    .order-buttons button {
        width: 44px;
    }
    .compact-text strong,
    .compact-text .meaning {
        font-size: 11px;
    }
    .sheet-scroll {
        padding: 0 14px;
    }
}

.sheet-heading {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sheet-heading .tone-tag {
    flex: none;
}

.pagination-bottom {
    justify-content: center;
    margin: 18px 0;
}

.email-login { margin-top: 24px; }
.email-login summary { cursor: pointer; color: var(--gold); padding: 10px 0; }
