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

:root {
    --bg: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #6b7280;
    --text-highlight: #64D2FF;
    --border: #e5e7eb;
    --accent: #64D2FF;
    --success: #10b981;
    --error: #ef4444;
    --card: #fafafa;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #222222;
        --text: #e5e7eb;
        --text-secondary: #9ca3af;
        --text-highlight: #64D2FF;
        --border: #a7a2a2;
        --accent: #64D2FF;
        --card: #1a1a1a;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 60px 24px;
    animation: containerFadeIn 0.6s ease;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 80px;
    animation: headerFadeIn 0.8s ease 0.2s both;
}

header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
    color: var(--accent);
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Mode Switcher */
.mode-switcher {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 32px;
    animation: fadeIn 0.8s ease 0.3s both;
}

.mode-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.mode-btn:hover {
    background: var(--card);
    color: var(--text);
}

.mode-btn.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

/* Upload Section */
.upload-area {
    border: 1.5px dashed var(--border);
    border-radius: 16px;
    padding: 80px 40px;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
    background: var(--bg);
    animation: uploadFadeIn 0.8s ease 0.4s both;
}

/* URL Input Area */
.url-input-area {
    border: 1.5px dashed var(--border);
    border-radius: 16px;
    padding: 60px 40px;
    text-align: center;
    background: var(--bg);
    animation: fadeIn 0.3s ease;
}

#urlInput {
    width: 100%;
    max-width: 500px;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.9375rem;
    margin-bottom: 20px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    transition: all 0.2s ease;
}

#urlInput:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(100, 210, 255, 0.1);
}

#urlInput::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.upload-area:hover {
    border-color: var(--accent);
    background: var(--card);
}

.upload-area.drag-over {
    border-color: var(--accent);
    background: var(--card);
    transform: scale(0.99);
}

.upload-text {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 24px;
    font-weight: 500;
}

.browse-btn {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.browse-btn:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

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

/* Preview Section */
.preview-section {
    text-align: center;
    animation: fadeIn 0.3s ease;
}

#imagePreview {
    max-width: 100%;
    max-height: 500px;
    width: auto;
    height: auto;
    border-radius: 16px;
    margin-bottom: 32px;
    object-fit: contain;
    display: block;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid var(--border);
}

.analyze-btn {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 14px 32px;
    border-radius: 12px;
    font-size: 0.9375rem;
    cursor: pointer;
    margin-right: 12px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.analyze-btn:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

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

.clear-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.clear-btn:hover {
    background: var(--card);
    color: var(--text);
}

/* Loading Section */
.loading-section {
    text-align: center;
    padding: 100px 20px;
    animation: fadeIn 0.3s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  position: relative;
  animation: spin 1s ease-in-out infinite;
  margin: 0 auto 24px;
  box-shadow: 0 0 6px var(--accent);
}

.spinner::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0.6;
  animation: spin-reverse 1.5s linear infinite;
}

.spinner::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
  background: radial-gradient(circle at center, var(--accent) 0%, transparent 70%);
  opacity: 0.2;
}

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

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

@keyframes pulse {
  0%, 100% {
    transform: scale(0.9);
    opacity: 0.2;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.4;
  }
}


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

.loading-section p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* Results Section */
.results-section {
    animation: fadeIn 0.4s ease;
}

.results-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 32px;
    text-align: center;
}

.result-image-container {
    text-align: center;
    margin-bottom: 40px;
}

#resultImage {
    max-width: 100%;
    max-height: 400px;
    border-radius: 16px;
    object-fit: contain;
    border: 1px solid var(--border);
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.nutrition-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 24px;
}

.description {
    font-size: 1.125rem;
    color: var(--text);
    margin-bottom: 8px;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.serving-size {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.nutrition-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.nutrition-item {
    background: var(--bg);
    padding: 20px 16px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--border);
}

.nutrition-item.highlight {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.nutrition-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.nutrition-item.highlight .nutrition-label {
    color: rgba(255, 255, 255, 0.8);
}

.nutrition-value {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
}

.nutrition-item.highlight .nutrition-value {
    color: #ffffff;
}

.additional-info {
    margin-top: 32px;
    padding-top: 32px;
    border-top: 1px solid var(--border);
    display: grid;
    gap: 24px;
    margin-bottom: 12px;
    padding-bottom: 12px;
}

.info-section h3 {
    font-size: 0.875rem;
    color: var(--text);
    margin-bottom: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.info-section li {
    padding: 10px 0;
    font-size: 0.9375rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.info-section li:last-child {
    border-bottom: none;
}

.info-section li:before {
    content: "•";
    color: var(--text);
    font-weight: bold;
    margin-right: 12px;
}

.info-section p {
    padding: 16px 0;
    font-size: 0.9375rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.confidence {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 24px;
}

/* JSON Details */
.json-details {
    display: none;
    margin-bottom: 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    background: var(--card);
}

.json-details summary {

    display: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text);
    user-select: none;
    font-size: 0.9375rem;
}

.json-details summary:hover {

    display: none;
    color: var(--text-secondary);
}

#jsonOutput {

    display: none;
    margin-top: 16px;
    padding: 16px;
    background: var(--text);
    color: #ffffff;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.6;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.new-analysis-btn {
    width: 100%;
    background: transparent;
    color: var(--text);
    border: 1.5px solid var(--border);
    padding: 16px;
    border-radius: 12px;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.new-analysis-btn:hover {
    background: var(--card);
    border-color: var(--accent);
}

/* Error Section */
.error-section {
    text-align: center;
    padding: 80px 20px;
    animation: fadeIn 0.3s ease;
}

.error-section h3 {
    color: var(--error);
    margin-bottom: 12px;
    font-size: 1.25rem;
    font-weight: 600;
}

.error-message {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.9375rem;
}

.retry-btn {
    background: var(--error);
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: 12px;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.retry-btn:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 80px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

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

/* Responsive */
@media (min-width: 1024px) {
    .container {
        max-width: 900px;
        padding: 80px 40px;
    }

    .nutrition-grid {
        grid-template-columns: repeat(5, 1fr);
    }

    .additional-info {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .nutrition-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .additional-info {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767px) {
    .container {
        padding: 40px 20px;
    }

    header {
        margin-bottom: 48px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .upload-area {
        padding: 60px 24px;
    }

    .nutrition-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .nutrition-card {
        padding: 24px;
    }
}
