* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: #f3f5f7;
    color: #222;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic", "Meiryo", sans-serif;
    line-height: 1.7;
}

body.is-processing {
    overflow: hidden;
}

.container {
    width: min(900px, calc(100% - 32px));
    margin: 0 auto;
    padding: 40px 0 80px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 0 0 8px;
    font-size: 32px;
}

.page-header p {
    margin: 0;
    color: #555;
}

.card {
    padding: 28px;
    margin-bottom: 24px;
    background-color: #fff;
    border: 1px solid #dfe3e8;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

.required,
.optional {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    color: #fff;
    border-radius: 4px;
    font-size: 12px;
}

.required {
    background-color: #c62828;
}

.optional {
    background-color: #667085;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #b8c0c8;
    border-radius: 8px;
    background-color: #fff;
    font: inherit;
}

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

input:focus,
textarea:focus,
button:focus-visible,
.file-select-button:focus-visible {
    border-color: #1769aa;
    outline: 3px solid rgba(23, 105, 170, 0.15);
}

.help-text {
    margin: 6px 0 0;
    color: #667085;
    font-size: 14px;
}

.input-actions,
.camera-actions,
.camera-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.speech-button,
.camera-button,
.file-select-button,
.take-photo-button,
.secondary-button,
.clear-image-button {
    min-height: 46px;
    padding: 10px 16px;
    border-radius: 8px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.speech-button,
.camera-button,
.file-select-button {
    border: 1px solid #1769aa;
    background-color: #fff;
    color: #1769aa;
}

.file-select-button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
}

.speech-button:hover,
.camera-button:hover,
.file-select-button:hover {
    background-color: #eef6fc;
}

.speech-button.is-listening {
    border-color: #c62828;
    background-color: #ffebee;
    color: #9b1c1c;
}

.camera-panel {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid #dfe3e8;
    border-radius: 10px;
    background-color: #111;
}

.camera-panel video {
    display: block;
    width: 100%;
    max-height: 540px;
    border-radius: 8px;
    background-color: #000;
    object-fit: contain;
}

.take-photo-button {
    flex: 1;
    border: 0;
    background-color: #c62828;
    color: #fff;
}

.secondary-button {
    border: 1px solid #c7cdd4;
    background-color: #fff;
    color: #333;
}

.image-preview {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid #dfe3e8;
    border-radius: 8px;
    background-color: #f8fafc;
}

.preview-title {
    margin: 0 0 8px;
    font-weight: 700;
}

.image-preview img {
    display: block;
    max-width: 100%;
    max-height: 440px;
    margin: 0 auto;
    border-radius: 6px;
    object-fit: contain;
}

.clear-image-button {
    display: block;
    margin-top: 10px;
    border: 1px solid #b8c0c8;
    background-color: #fff;
    color: #444;
}

.submit-button {
    width: 100%;
    padding: 14px 20px;
    border: 0;
    border-radius: 8px;
    background-color: #1769aa;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.submit-button:hover:not(:disabled) {
    background-color: #10558c;
}

.submit-button:active:not(:disabled) {
    transform: translateY(1px);
}

.submit-button:disabled {
    background-color: #6f8fa8;
    cursor: wait;
}

.message {
    margin-bottom: 24px;
    padding: 20px 24px;
    border-radius: 10px;
}

.message h2 {
    margin-top: 0;
}

.error-message {
    border: 1px solid #ef9a9a;
    background-color: #ffebee;
    color: #8e0000;
}

.error-message p {
    margin-bottom: 0;
    white-space: pre-wrap;
}

.result-card h2 {
    margin-top: 0;
    padding-bottom: 12px;
    border-bottom: 1px solid #dfe3e8;
}

.result-text {
    padding: 18px;
    background-color: #f8fafc;
    border-left: 5px solid #1769aa;
    border-radius: 6px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.uploaded-image {
    margin-top: 30px;
}

.uploaded-image h3 {
    margin-bottom: 12px;
}

.uploaded-image img {
    display: block;
    max-width: 100%;
    max-height: 500px;
    border: 1px solid #dfe3e8;
    border-radius: 8px;
    object-fit: contain;
}

.processing-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 20px;
    background-color: rgba(15, 23, 42, 0.58);
}

.processing-overlay[hidden] {
    display: none;
}

.processing-box {
    width: min(420px, 100%);
    padding: 28px 24px;
    border-radius: 14px;
    background-color: #fff;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto 18px;
    border: 5px solid #dce8f1;
    border-top-color: #1769aa;
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

.processing-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.processing-note {
    margin: 8px 0 0;
    color: #667085;
    font-size: 14px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

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

@media (max-width: 600px) {
    .container {
        width: min(100% - 20px, 900px);
        padding-top: 20px;
    }

    .page-header h1 {
        font-size: 25px;
    }

    .card {
        padding: 20px 16px;
    }

    .speech-button,
    .camera-button,
    .file-select-button,
    .take-photo-button,
    .secondary-button {
        width: 100%;
    }
}
