:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --text: #1f2937;
    --muted: #6b7280;
    --subtle: #9ca3af;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --line: #e5e7eb;
    --line-strong: #d1d5db;
    --danger: #b91c1c;
    --success: #047857;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 4px 12px rgba(79, 70, 229, 0.18);
    --radius: 8px;
}

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

html {
    min-width: 320px;
}

body {
    min-height: 100vh;
    padding: 20px;
    background: #ffffff;
    color: #333333;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

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

button,
select,
input[type="color"],
input[type="range"],
.drop-zone,
.link-button {
    touch-action: manipulation;
}

a {
    color: inherit;
}

.skip-link {
    position: absolute;
    top: -64px;
    left: 20px;
    z-index: 10;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--text);
    color: #ffffff;
    text-decoration: none;
}

.skip-link:focus {
    top: 20px;
}

.site-header,
.workspace,
.site-footer {
    max-width: 1000px;
    margin: 0 auto;
}

.site-header {
    padding: 20px 20px 0;
    margin-bottom: 30px;
    color: var(--text);
    text-align: center;
}

h1,
h2 {
    color: var(--text);
    line-height: 1.2;
    letter-spacing: 0;
}

h1 {
    margin-bottom: 16px;
    color: var(--primary);
    font-size: 36px;
    font-weight: 700;
}

h2 {
    font-size: 18px;
    font-weight: 600;
}

.header-note {
    color: var(--muted);
    font-size: 18px;
}

.workspace {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    align-items: start;
    margin-bottom: 40px;
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.tab-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
}

.tab-button {
    min-height: 46px;
    border: 1.5px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
}

.tab-button:hover {
    color: var(--primary);
    background: #ffffff;
}

.tab-button.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}

.tool-panel {
    min-width: 0;
}

.tab-panel[hidden] {
    display: none;
}

.converter-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    align-items: start;
}

.preview-section,
.options-section {
    min-width: 0;
}

.preview-section h2,
.options-section h2 {
    margin-bottom: 12px;
    font-size: 16px;
    color: var(--text);
    font-weight: 600;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-kicker {
    display: none;
}

.drop-zone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    padding: 18px;
    border: 2px dashed var(--line-strong);
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--muted);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.drop-zone:hover,
.drop-zone.drag-over,
.drop-zone:focus-within {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.drop-zone.drag-over {
    transform: scale(1.02);
}

.drop-zone input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.drop-icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin-bottom: 12px;
    color: var(--subtle);
}

.drop-icon svg {
    width: 48px;
    height: 48px;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.drop-title {
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
}

.drop-meta {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.scan-preview,
.qr-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    margin: 16px 0;
    padding: 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
}

.qr-preview {
    aspect-ratio: 1 / 1;
    min-height: 0;
    margin: 0 0 16px;
}

.scan-preview {
    min-height: 230px;
}

.drop-zone.scan-preview {
    min-height: 400px;
    margin: 0;
    padding: 24px;
    border: 2px dashed var(--line-strong);
}

.drop-zone.scan-preview:hover,
.drop-zone.scan-preview.drag-over,
.drop-zone.scan-preview:focus-within {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.drop-zone.scan-preview.has-image {
    background: var(--surface-soft);
}

.drop-zone.scan-preview.has-image .drop-icon,
.drop-zone.scan-preview.has-image .drop-title,
.drop-zone.scan-preview.has-image .drop-meta {
    display: none;
}

.drop-zone.scan-preview .empty-preview {
    display: none;
}

.scan-preview canvas {
    display: none;
    max-width: 100%;
    max-height: 330px;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.scan-preview.has-image canvas {
    display: block;
}

.empty-preview {
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
}

.scan-preview.has-image .empty-preview {
    display: none;
}

.qr-preview canvas {
    width: min(100%, 280px);
    height: auto;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.field-group {
    display: grid;
    gap: 8px;
}

label,
.color-row span {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

textarea,
select,
input[type="number"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    outline: none;
    background: #ffffff;
    color: #374151;
    transition: all 0.2s;
}

textarea {
    min-height: 88px;
    resize: vertical;
}

textarea[readonly] {
    background: var(--surface-soft);
}

textarea:focus,
select:focus,
input[type="number"]:focus,
button:focus-visible,
.link-button:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
    outline: none;
}

.native-control-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.options-stack {
    display: grid;
    gap: 16px;
    margin-top: 16px;
}

.option-section {
    display: grid;
    gap: 10px;
}

.option-title {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.option-grid,
.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.format-grid,
.size-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.compact-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.option-btn {
    display: flex;
    min-width: 0;
    min-height: 50px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 7px 6px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.option-btn span {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.option-btn small {
    max-width: 100%;
    color: var(--muted);
    font-size: 10px;
    font-weight: 400;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.option-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.option-btn.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.option-btn.is-active small {
    color: rgba(255, 255, 255, 0.82);
}

.custom-size-field {
    display: none;
}

.custom-size-field.is-visible {
    display: grid;
}

.quality-field.is-hidden {
    display: none;
}

.advanced-settings {
    display: grid;
    gap: 12px;
}

.advanced-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
}

.advanced-toggle:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.advanced-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    font-size: 0;
    transition: transform 0.2s;
}

.advanced-toggle-icon::before {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(-1px, -1px);
}

.advanced-toggle[aria-expanded="true"] .advanced-toggle-icon {
    transform: rotate(180deg);
}

.advanced-settings-body {
    display: grid;
    gap: 16px;
}

.advanced-settings-body[hidden] {
    display: none;
}

input[type="range"] {
    width: 100%;
    min-height: 44px;
    accent-color: var(--primary);
}

.color-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}

.color-row label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 8px 10px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

input[type="color"] {
    width: 40px;
    height: 30px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.action-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 16px;
}

button,
.link-button {
    min-height: 44px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

.primary-button,
.secondary-button,
.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 14px;
    border: 1.5px solid transparent;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
}

.primary-button {
    width: 100%;
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2);
}

.primary-button:hover:not(:disabled) {
    border-color: var(--primary-hover);
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.secondary-button,
.link-button {
    width: 100%;
    border-color: var(--line);
    background: var(--surface-soft);
    color: var(--primary);
}

.secondary-button:hover:not(:disabled),
.link-button:hover:not(.disabled) {
    border-color: var(--primary);
    background: var(--primary-soft);
}

button:disabled,
.link-button.disabled {
    cursor: not-allowed;
    opacity: 0.45;
    transform: none;
    box-shadow: none;
}

.status-text {
    min-height: 22px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

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

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

.site-footer {
    padding: 20px 20px 10px;
    color: var(--subtle);
    font-size: 14px;
    text-align: center;
}

.site-footer p {
    margin: 10px 0;
}

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

.site-footer a:hover {
    text-decoration: underline;
}

@media (min-width: 641px) {
    .reader-panel .action-row {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .generator-panel .action-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 968px) {
    .converter-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    h1 {
        font-size: 30px;
    }

    .scan-preview {
        min-height: 240px;
    }

    .drop-zone.scan-preview {
        min-height: 350px;
    }
}

@media (max-width: 640px) {
    body {
        padding: 16px;
    }

    .site-header {
        padding: 16px 10px 0;
    }

    h1 {
        font-size: 26px;
    }

    .header-note {
        font-size: 16px;
    }

    .workspace {
        padding: 20px;
    }

    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .controls-grid,
    .format-grid,
    .size-grid,
    .compact-grid,
    .color-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .drop-zone {
        min-height: 140px;
    }

    .scan-preview {
        min-height: 220px;
    }

    .drop-zone.scan-preview {
        min-height: 300px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
