:root {
    --primary: #16a34a;
    --primary-hover: #15803d;
    --primary-light: #f0fdf4;
    --primary-subtle: rgba(22, 163, 74, 0.08);
    --bg: #f8fafc;
    --bg-pattern: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-lg: 0 20px 40px rgba(0,0,0,0.08);
    --radius: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-pattern);
    color: var(--text);
    margin: 0;
    padding: 24px 16px;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 460px;
    margin: 0 auto;
    padding: 32px 28px;
    background: var(--card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    position: relative;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-light);
}

.logo-title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

h1 {
    margin: 0;
    color: var(--text);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.tagline {
    margin: 6px 0 0 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 400;
    letter-spacing: 0.01em;
}

.tagline::before,
.tagline::after {
    display: none;
}

/* Form */
form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
    text-transform: uppercase;
}

input, select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
    cursor: pointer;
}

.search-container {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.search-container input {
    flex: 1;
}

.quantity-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* Icon Button */
.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    min-width: 48px;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
}

.icon-button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.icon-button:active {
    transform: scale(0.96);
}

.icon-button svg {
    width: 20px;
    height: 20px;
}

/* Submit Button */
.submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary);
    color: white;
    padding: 13px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-top: 4px;
    letter-spacing: 0.01em;
}

.submit-btn::before {
    display: none;
}

.submit-btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
    transform: translateY(-1px);
}

.submit-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    padding: 16px;
    overflow-y: auto;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    background-color: var(--card);
    margin: 40px auto;
    padding: 28px 24px;
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    animation: slideUp 0.2s ease;
}

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

.modal h2 {
    margin: 0 0 4px 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    padding-right: 40px;
    letter-spacing: -0.01em;
}

.modal-subtitle {
    margin: 0 0 20px 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.close {
    position: absolute;
    right: 16px;
    top: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: normal;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: var(--border-light);
    border-radius: 50%;
    transition: all 0.15s ease;
    line-height: 1;
}

.close:hover {
    background: var(--border);
    color: var(--text);
}

/* Upload Options */
.upload-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.upload-option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text);
    font-family: inherit;
}

.upload-option-btn span {
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    color: var(--text-secondary);
}

.upload-option-btn svg {
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
}

.upload-option-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-option-btn:hover svg {
    color: var(--primary);
}

.upload-option-btn:active {
    transform: scale(0.98);
}

.camera-btn {
    border-color: var(--primary);
    background: var(--primary-light);
}

.camera-btn svg {
    color: var(--primary);
}

/* Drop Zone */
.upload-container {
    margin-bottom: 14px;
}

.drop-zone {
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--border-light);
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.drop-zone-content svg {
    color: var(--text-muted);
    width: 36px;
    height: 36px;
}

.drop-zone-text {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin: 0;
}

#previewImage {
    display: none;
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    object-fit: contain;
}

.drop-zone.has-image {
    padding: 12px;
    border-style: solid;
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone.has-image .drop-zone-content {
    display: none;
}

.drop-zone.has-image #previewImage {
    display: block;
}

/* Analyze Button */
.analyze-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 13px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.analyze-btn:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
}

.analyze-btn:not(:disabled):hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

/* Loader */
.loader {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    gap: 16px;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    position: relative;
}

.loader-spinner::before {
    display: none;
}

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

.loader-text {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0;
    font-weight: 500;
}

/* Results */
#results-container {
    display: none;
    animation: slideIn 0.3s ease-out;
}

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

#result {
    margin-top: 24px;
}

#result > div {
    animation: fadeInUp 0.3s ease-out;
}

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

/* Nutrition Table */
.nutrition-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.875rem;
}

.nutrition-table th {
    background: var(--text);
    color: white;
    text-align: left;
    padding: 11px 16px;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nutrition-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}

.nutrition-table tr:last-child td {
    border-bottom: none;
}

.nutrition-table tr:hover {
    background: var(--border-light);
}

/* Error Message */
.error-message {
    color: var(--error);
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 14px 16px;
    border-radius: var(--radius);
    margin-top: 16px;
    font-size: 0.875rem;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px 16px;
    margin-top: 24px;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.footer p {
    margin: 0;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
    transition: color 0.15s ease;
}

.footer a:hover {
    color: var(--primary);
}

.github-icon {
    width: 14px;
    height: 14px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    body {
        padding: 12px;
    }

    .container {
        padding: 24px 20px;
        border-radius: var(--radius-lg);
    }

    h1 {
        font-size: 1.375rem;
    }

    .quantity-container {
        grid-template-columns: 1fr 1fr;
    }

    .upload-options {
        grid-template-columns: 1fr 1fr;
    }

    .upload-option-btn {
        padding: 14px 8px;
    }

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

    .upload-option-btn span {
        font-size: 0.7rem;
    }

    .icon-button {
        width: 46px;
        min-width: 46px;
    }

    input, select {
        font-size: 16px;
        padding: 11px 14px;
    }

    .modal-content {
        margin: 16px auto;
        padding: 24px 20px;
    }
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0c0f17;
        --bg-pattern: #0c0f17;
        --card: #161b26;
        --text: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-muted: #64748b;
        --border: #1e293b;
        --border-light: #1e293b;
        --primary-light: rgba(22, 163, 74, 0.1);
        --primary-subtle: rgba(22, 163, 74, 0.12);
        --shadow-xs: none;
        --shadow-sm: none;
        --shadow: none;
        --shadow-md: 0 0 0 1px var(--border);
        --shadow-lg: 0 0 0 1px var(--border);
    }

    h1 {
        color: var(--text);
    }

    input, select {
        background: var(--bg);
        color: var(--text);
        border-color: var(--border);
    }

    .modal-content {
        background: var(--card);
        border-color: var(--border);
    }

    .upload-option-btn {
        background: var(--bg);
        border-color: var(--border);
    }

    .camera-btn {
        border-color: var(--primary);
        background: var(--primary-light);
    }

    .drop-zone {
        background: var(--bg);
        border-color: var(--border);
    }

    .close {
        background: var(--border);
        color: var(--text-muted);
    }

    .close:hover {
        background: var(--text-muted);
        color: var(--card);
    }

    .nutrition-table {
        border-color: var(--border);
    }

    .nutrition-table th {
        background: var(--border);
        color: var(--text);
    }

    .nutrition-table tr:hover {
        background: rgba(255, 255, 255, 0.02);
    }

    .loader-spinner {
        border-color: var(--border);
        border-top-color: var(--primary);
    }

    .icon-button {
        background: var(--bg);
        border-color: var(--border);
    }

    .container {
        border-color: var(--border);
    }
}

/* Safe Area Support */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .modal {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-top: max(16px, env(safe-area-inset-top));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

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

/* Touch Device Optimizations */
@media (hover: none) {
    .icon-button:hover {
        background: var(--card);
        color: var(--text-secondary);
        border-color: var(--border);
    }

    .submit-btn:hover {
        transform: none;
        box-shadow: none;
    }

    .drop-zone {
        border-style: solid;
    }
}
