/* ===== iOS Design System Variables ===== */
:root {
    --ios-bg: #F2F2F7;
    --ios-card: #FFFFFF;
    --ios-text-primary: #1C1C1E;
    --ios-text-secondary: #8E8E93;
    --ios-text-tertiary: #AEAEB2;
    --ios-blue: #007AFF;
    --ios-blue-hover: #0056B3;
    --ios-blue-active: #004494;
    --ios-green: #34C759;
    --ios-red: #FF3B30;
    --ios-orange: #FF9500;
    --ios-separator: rgba(60, 60, 67, 0.12);
    --ios-separator-thin: rgba(60, 60, 67, 0.06);
    --ios-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --ios-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 44px;
    --bottom-nav-height: 64px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
    background-color: var(--ios-bg);
    color: var(--ios-text-primary);
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== App Container (Scrollable) ===== */
.app-container,
.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Navigation Bar ===== */
.nav-bar {
    flex-shrink: 0;
    height: calc(var(--nav-height) + var(--safe-top));
    padding-top: var(--safe-top);
    background: var(--ios-card);
    border-bottom: 0.5px solid var(--ios-separator);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 100;
}

.nav-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--ios-text-primary);
    letter-spacing: -0.3px;
}

/* ===== Main Content (Scrollable Area) ===== */
.main-scroll,
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px);
}

.main-scroll::-webkit-scrollbar,
.main-content::-webkit-scrollbar {
    display: none;
}

/* ===== Content Container ===== */
.content {
    max-width: 100%;
    margin: 0 auto;
    padding: 16px;
}

/* ===== Header Section ===== */
.header {
    text-align: center;
    margin-bottom: 24px;
    padding: 8px 0;
}

.chinese-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--ios-text-primary);
    letter-spacing: -0.5px;
    line-height: 1.3;
    display: block;
}

.english-title {
    font-size: 10px;
    font-weight: 500;
    color: var(--ios-text-secondary);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-top: 6px;
    display: block;
}

/* ===== Card Component ===== */
.card {
    background: var(--ios-card);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: var(--ios-shadow);
}

.card-header {
    padding: 16px 16px 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ios-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-body {
    padding: 12px 16px 16px;
}

/* ===== Text Input (Textarea) ===== */
.text-input-wrapper {
    position: relative;
}

.text-input {
    width: 100%;
    min-height: 180px;
    padding: 16px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    background: var(--ios-bg);
    color: var(--ios-text-primary);
    resize: vertical;
    line-height: 1.6;
    outline: none;
    -webkit-appearance: none;
}

.text-input::placeholder {
    color: var(--ios-text-tertiary);
}

.text-input:focus {
    background: #F5F5F7;
}

/* ===== Form Controls ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--ios-text-secondary);
    margin-bottom: 8px;
}

.form-select {
    width: 100%;
    padding: 14px 40px 14px 16px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    background: var(--ios-bg);
    color: var(--ios-text-primary);
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238E8E93' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}

.form-select:focus {
    background-color: #F5F5F7;
}

/* ===== Upload Button ===== */
.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border: 1.5px dashed var(--ios-separator);
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    color: var(--ios-blue);
    background: rgba(0, 122, 255, 0.04);
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-btn:active {
    background: rgba(0, 122, 255, 0.08);
    border-color: var(--ios-blue);
}

.upload-btn svg {
    width: 20px;
    height: 20px;
}

/* ===== Primary Button ===== */
.btn-primary {
    display: block;
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    color: #FFFFFF;
    background: var(--ios-blue);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.btn-primary:active {
    background: var(--ios-blue-active);
    transform: scale(0.98);
}

.btn-primary:disabled {
    background: #99C9FF;
    cursor: not-allowed;
    transform: none;
}

/* ===== Section Title ===== */
.section-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--ios-text-primary);
    text-align: center;
    margin: 32px 0 20px;
    letter-spacing: -0.3px;
}

/* ===== Question Cards ===== */
.question-type-card {
    background: var(--ios-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--ios-shadow);
}

.question-type-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--ios-text-primary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 0.5px solid var(--ios-separator-thin);
}

.question-item {
    padding: 16px 0;
    border-bottom: 0.5px solid var(--ios-separator-thin);
}

.question-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.question-header {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.question-number {
    font-weight: 700;
    color: var(--ios-blue);
    font-size: 15px;
    min-width: 24px;
    flex-shrink: 0;
}

.question-text {
    font-size: 15px;
    color: var(--ios-text-primary);
    line-height: 1.6;
    flex: 1;
}

/* ===== Options ===== */
.options-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 34px;
}

.option-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    background: var(--ios-bg);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.option-item:active {
    background: #E5E5EA;
}

.option-item input[type="radio"] {
    margin-top: 2px;
    accent-color: var(--ios-blue);
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.option-label {
    font-weight: 600;
    color: var(--ios-text-secondary);
    font-size: 14px;
    min-width: 20px;
}

.option-text {
    font-size: 14px;
    color: var(--ios-text-primary);
    line-height: 1.5;
    flex: 1;
}

/* True/False horizontal layout */
.true-false-options {
    flex-direction: row;
    gap: 12px;
}

.true-false-options .option-item {
    flex: 1;
    justify-content: center;
}

/* ===== Short Answer ===== */
.answer-input {
    padding-left: 34px;
}

.answer-input textarea {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    background: var(--ios-bg);
    color: var(--ios-text-primary);
    resize: vertical;
    min-height: 80px;
    outline: none;
    -webkit-appearance: none;
}

.answer-input textarea::placeholder {
    color: var(--ios-text-tertiary);
}

/* ===== Submit Section ===== */
.submit-section {
    margin: 24px 0 32px;
}

.submit-btn {
    display: block;
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    color: #FFFFFF;
    background: var(--ios-green);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.3);
}

.submit-btn:active {
    background: #2DB14A;
    transform: scale(0.98);
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding: 10px 16px calc(var(--safe-bottom) + 10px);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--ios-separator);
    display: flex;
    justify-content: center;
    gap: 12px;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    max-width: 160px;
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    color: var(--ios-blue);
    background: rgba(0, 122, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn.active {
    color: #FFFFFF;
    background: var(--ios-blue);
}

.nav-btn:active {
    transform: scale(0.96);
}

/* ===== Page Switching ===== */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Answers Page ===== */
.answer-item {
    background: var(--ios-card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--ios-shadow);
}

.correct-answer-display {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 122, 255, 0.06);
    border-radius: 8px;
    border-left: 3px solid var(--ios-blue);
}

.answer-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ios-text-secondary);
}

.answer-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--ios-blue);
    margin-top: 4px;
    display: block;
}

/* ===== QR Code Modal ===== */
.qrcode-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.qrcode-modal.show {
    display: flex;
}

.qrcode-modal-content {
    background: var(--ios-card);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 320px;
    text-align: center;
    box-shadow: var(--ios-shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.qrcode-modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}

#qrcode-container {
    margin: 20px auto;
    padding: 16px;
    background: var(--ios-bg);
    border-radius: 12px;
    display: inline-block;
}

.qrcode-modal-content p {
    font-size: 13px;
    color: var(--ios-text-secondary);
    margin-top: 16px;
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--ios-bg);
    color: var(--ios-text-secondary);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #FFFFFF;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

#loading-text {
    color: #FFFFFF;
    font-size: 15px;
    font-weight: 500;
    margin-top: 16px;
}

/* ===== Notice/Toast ===== */
.notice-area {
    display: none;
    margin-bottom: 16px;
}

.notice-area.show {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.notice-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--ios-card);
    border-radius: 12px;
    box-shadow: var(--ios-shadow);
}

.notice-icon {
    font-size: 18px;
}

#notice-text {
    flex: 1;
    font-size: 14px;
    color: var(--ios-text-primary);
}

.notice-close {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: var(--ios-bg);
    color: var(--ios-text-secondary);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notice-error .notice-content {
    background: #FFF0EF;
}

.notice-success .notice-content {
    background: #F0FFF4;
}

/* ===== Empty State ===== */
.no-questions {
    text-align: center;
    padding: 40px 20px;
    color: var(--ios-text-tertiary);
    font-size: 14px;
}

/* ===== Mobile: small-screen overrides only ===== */
@media (max-width: 767px) {
    html, body {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .app-container,
    .container {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .main-scroll,
    .main-content {
        overflow-y: visible;
        padding-bottom: 80px;
    }

    .page-nav-container {
        padding: 12px 0 calc(env(safe-area-inset-bottom, 0px) + 16px);
    }

    .content {
        max-width: 100%;
        padding: 12px;
    }

    .card,
    .question-type-card,
    .answer-item {
        border-radius: 10px;
        margin-bottom: 12px;
    }

    .text-input {
        min-height: 150px;
        font-size: 16px;
    }

    .bottom-nav {
        position: relative;
        margin-top: auto;
    }

    .nav-btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Mobile: stack model selector vertically */
    .model-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .model-selector > label {
        margin-bottom: 0;
    }

    .model-selector select,
    .model-selector #model-select,
    .file-upload-section,
    .file-icon-section,
    .file-upload-section .file-input {
        width: 100%;
    }

    .file-icon-section {
        justify-content: center;
        margin-left: 0;
    }

    .header {
        margin-bottom: 14px;
        padding: 6px 0;
    }

    .chinese-title {
        font-size: 18px;
    }

    .english-title {
        font-size: 9px;
        margin-top: 4px;
    }

    .input-section {
        padding: 14px;
        margin: 0 12px 14px;
        max-width: none;
    }

    .questions-section {
        padding: 0 12px 18px;
        max-width: none;
    }

    #model-select {
        padding: 14px 40px 14px 16px;
        border-radius: 10px;
        font-size: 16px;
        min-width: 0;
    }

    .file-upload-section .file-input {
        padding: 14px 16px;
        border-radius: 10px;
    }

    .file-icon-section {
        padding: 10px 0 0;
    }

    .file-icon-section .file-icon {
        width: 54px;
        height: 54px;
        border-radius: 14px;
    }

    .question-type-section {
        padding: 16px;
        margin-bottom: 12px;
    }

    .question-type-section .question-type-title {
        margin-bottom: 12px;
        padding-bottom: 10px;
        border-bottom: 0.5px solid var(--ios-separator-thin);
    }

    .page-btn {
        flex: 1;
        max-width: 180px;
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* ===== Tablet & Desktop (keep original fixed App-style layout) ===== */
@media (min-width: 768px) {
    html, body {
        height: 100%;
        overflow: hidden;
    }

    .app-container,
    .container {
        height: 100%;
        overflow: hidden;
    }

    .main-scroll,
    .main-content {
        overflow-y: auto;
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px);
    }

    .content {
        max-width: 680px;
        padding: 24px;
    }

    .chinese-title {
        font-size: 28px;
    }

    .english-title {
        font-size: 11px;
    }

    .text-input {
        min-height: 220px;
    }

    .question-type-card {
        padding: 24px;
    }

    .bottom-nav {
        justify-content: center;
        gap: 16px;
    }

    .nav-btn {
        max-width: 200px;
    }
}

/* ===== Landscape Mode ===== */
@media (orientation: landscape) and (max-height: 500px) {
    .text-input {
        min-height: 100px;
    }

    .section-title {
        margin: 20px 0 16px;
    }
}
