:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #eef4fb;
    --text: #172033;
    --muted: #667085;
    --line: #d9e3ef;
    --primary: #1463ff;
    --primary-dark: #0f4dcc;
    --green: #05a660;
    --green-dark: #05834e;
    --danger: #dc2626;
    --shadow: 0 18px 48px rgba(15, 23, 42, .12);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 0, rgba(20, 99, 255, .18), transparent 30%),
        radial-gradient(circle at 92% 8%, rgba(5, 166, 96, .13), transparent 26%),
        var(--bg);
    font-family: Arial, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

.app-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(16px, 4vw, 42px);
    border-bottom: 1px solid rgba(15, 23, 42, .08);
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(16px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    text-decoration: none;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #1ec88a);
    box-shadow: 0 12px 24px rgba(20, 99, 255, .24);
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 17px;
    font-weight: 900;
}

.brand small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.tool-home {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    background: #fff;
    font-weight: 900;
    text-decoration: none;
}

.tool-home:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.app-shell {
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto;
    padding: 34px 0 72px;
}

.hero-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 22px;
    align-items: end;
    margin-bottom: 22px;
    padding: clamp(26px, 4vw, 42px);
    border: 1px solid rgba(255, 255, 255, .9);
    border-radius: 28px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, .94), rgba(241, 247, 255, .84)),
        linear-gradient(135deg, rgba(20, 99, 255, .12), rgba(5, 166, 96, .08));
    box-shadow: var(--shadow);
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 950;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.hero-copy h1 {
    max-width: 900px;
    margin: 0;
    color: var(--text);
    font-size: clamp(32px, 5vw, 62px);
    line-height: 1.06;
    font-weight: 950;
    letter-spacing: 0;
}

.hero-copy p:not(.eyebrow) {
    max-width: 760px;
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.8;
}

.hero-badges {
    display: grid;
    gap: 9px;
    min-width: 210px;
}

.hero-badges span {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
    font-weight: 900;
}

.hero-badges i {
    color: var(--primary);
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(360px, .98fr) minmax(330px, .82fr) minmax(360px, .9fr);
    gap: 18px;
    align-items: start;
}

.tool-panel,
.support-panel {
    border: 1px solid rgba(217, 227, 239, .9);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .94);
    box-shadow: var(--shadow);
}

.tool-panel {
    padding: 20px;
}

.panel-title {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: start;
    margin-bottom: 16px;
}

.panel-title > i,
.support-panel i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #1ec88a);
}

.panel-title h2,
.support-panel h2 {
    margin: 0 0 4px;
    color: var(--text);
    font-size: 20px;
    font-weight: 950;
}

.panel-title p,
.support-panel p {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
}

.scanner-stage {
    position: relative;
    overflow: hidden;
    min-height: 330px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #07111f;
}

#reader {
    position: relative;
    z-index: 2;
    min-height: 330px;
}

#reader video {
    display: block;
    width: 100%;
    min-height: 330px;
    object-fit: cover;
}

.scan-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.scan-overlay span {
    width: min(68%, 280px);
    aspect-ratio: 1;
    border: 2px solid rgba(255, 255, 255, .78);
    border-radius: 22px;
    box-shadow: 0 0 0 999px rgba(7, 17, 31, .34);
}

.camera-empty {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    padding: 24px;
    color: #cfe2ff;
    text-align: center;
}

.camera-empty i {
    font-size: 42px;
    color: #88b7ff;
}

.camera-empty strong {
    color: #fff;
    font-size: 20px;
}

.camera-empty span {
    color: #adc4df;
}

.scanner-stage.is-running .camera-empty {
    display: none;
}

.control-grid {
    display: grid;
    grid-template-columns: 1fr 180px;
    gap: 12px;
    margin-top: 14px;
}

.field {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.field select,
.field input,
.result-box textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    padding: 11px 12px;
    outline: 0;
}

.field select:focus,
.field input:focus,
.result-box textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(20, 99, 255, .12);
}

.action-row,
.upload-actions,
.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.btn,
.mini-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 950;
    text-decoration: none;
    transition: transform .18s, box-shadow .18s, background .18s, border-color .18s;
}

.btn {
    min-height: 44px;
    padding: 10px 15px;
}

.btn:hover,
.mini-btn:hover {
    transform: translateY(-1px);
}

.btn:disabled,
.btn.disabled {
    opacity: .45;
    pointer-events: none;
}

.btn.primary {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 12px 24px rgba(20, 99, 255, .22);
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn.line {
    color: #fff;
    background: var(--green);
    box-shadow: 0 12px 24px rgba(5, 166, 96, .18);
}

.btn.line:hover {
    background: var(--green-dark);
}

.btn.ghost,
.mini-btn {
    color: var(--text);
    background: #fff;
    border-color: var(--line);
}

.btn.ghost:hover,
.mini-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.status-text {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.status-text.is-ok {
    color: var(--green);
}

.status-text.is-error {
    color: var(--danger);
}

.drop-zone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 230px;
    padding: 24px;
    border: 2px dashed #b9c8da;
    border-radius: 18px;
    background: linear-gradient(180deg, #f9fbff, #eef5ff);
    color: var(--muted);
    text-align: center;
    cursor: pointer;
    transition: border-color .18s, background .18s, transform .18s;
}

.drop-zone input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.drop-zone i {
    color: var(--primary);
    font-size: 42px;
}

.drop-zone strong {
    margin-top: 12px;
    color: var(--text);
    font-size: 18px;
}

.drop-zone span {
    margin-top: 4px;
}

.drop-zone.is-dragover {
    border-color: var(--primary);
    background: #eaf2ff;
    transform: translateY(-2px);
}

.file-list,
.history-list {
    display: grid;
    gap: 9px;
    margin-top: 14px;
}

.file-item,
.history-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: start;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.file-item i,
.history-item i {
    color: var(--primary);
    margin-top: 3px;
}

.file-item strong,
.history-item strong {
    display: block;
    color: var(--text);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.file-item span,
.history-item span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.file-item.is-error i {
    color: var(--danger);
}

.empty-state {
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: 14px;
    color: var(--muted);
    text-align: center;
}

.result-box {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel-soft);
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.result-meta span {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.result-box textarea {
    min-height: 150px;
    resize: vertical;
    line-height: 1.65;
    font-family: Consolas, "Courier New", monospace;
}

.history-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-top: 18px;
}

.history-head h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 950;
}

.history-head div {
    display: flex;
    gap: 8px;
}

.mini-btn {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
}

.mini-btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.support-panel {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    align-items: center;
    margin-top: 18px;
    padding: 20px;
}

.support-panel div {
    display: flex;
    align-items: center;
    gap: 12px;
}

#file-reader {
    position: fixed;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

@media (max-width: 1200px) {
    .workspace-grid {
        grid-template-columns: 1fr 1fr;
    }

    .result-panel {
        grid-column: 1 / -1;
    }
}

@media (max-width: 860px) {
    .app-nav,
    .hero-panel,
    .workspace-grid,
    .support-panel {
        grid-template-columns: 1fr;
    }

    .app-nav {
        position: static;
    }

    .hero-badges {
        min-width: 0;
    }

    .control-grid {
        grid-template-columns: 1fr;
    }

    .scanner-stage,
    #reader,
    #reader video {
        min-height: 280px;
    }
}

@media (max-width: 560px) {
    .app-shell {
        width: min(100% - 22px, 1440px);
        padding-top: 22px;
    }

    .hero-copy h1 {
        font-size: clamp(30px, 12vw, 42px);
    }

    .tool-panel {
        padding: 16px;
    }

    .action-row .btn,
    .result-actions .btn,
    .upload-actions .btn {
        width: 100%;
    }
}
