/* ─── Variables ─── */
:root {
    --accent: #22c55e;
    --accent-dim: #16a34a;
    --protein: #3b82f6;
    --fat: #f59e0b;
    --carbs: #22c55e;
    --danger: #ef4444;
    --bg: #0a0f1a;
    --bg-card: #141c2e;
    --bg-hover: #1a2540;
    --border: #1e293b;
    --text: #e2e8f0;
    --text-dim: #64748b;
    --radius: 12px;
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: #fff;
    transition: opacity 0.2s;
}
button:hover { opacity: 0.85; }
button:disabled { opacity: 0.4; cursor: wait; }
button.outline { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
button.outline:hover { border-color: var(--text-dim); }
button.danger { border-color: var(--danger); color: var(--danger); }

input, textarea {
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}
input:focus, textarea:focus { border-color: var(--accent); }

label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}
label input { margin-top: 0.3rem; }

.container { max-width: 480px; margin: 0 auto; padding: 1rem; }
.hidden { display: none !important; }
.dim { color: var(--text-dim); }

/* ─── Onboarding ─── */
#onboarding {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
}

.onboarding-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    width: 100%;
}

.onboarding-card h1 {
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}

.onboarding-card p {
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.onboarding-card button {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.75rem;
    font-size: 1rem;
}

.macro-preview {
    background: var(--bg);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

/* ─── Header ─── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

header h1 { font-size: 1.4rem; }

.icon-btn {
    background: none;
    padding: 0.25rem;
    font-size: 1.3rem;
    color: var(--text-dim);
}

/* ─── Settings ─── */
#settings-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.settings-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.settings-actions button { flex: 1; font-size: 0.8rem; padding: 0.5rem; }

/* ─── Dashboard / Rings ─── */
.dashboard {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.cal-ring-wrap {
    position: relative;
    width: 120px;
    height: 120px;
    flex-shrink: 0;
}

.ring-svg { width: 100%; height: 100%; }

.ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 8;
}

.ring-fg {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease;
}

.ring-cal { stroke: var(--accent); }
.ring-protein { stroke: var(--protein); }
.ring-fat { stroke: var(--fat); }
.ring-carbs { stroke: var(--carbs); }

.ring-label-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.ring-label-center .ring-val {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.ring-label-center .ring-sub {
    font-size: 0.65rem;
    color: var(--text-dim);
    margin-top: 2px;
}

.ring-label-center.small .ring-val {
    font-size: 0.85rem;
}

.macro-rings {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
}

.macro-ring-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.macro-ring-wrap .ring-svg {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.macro-ring-wrap .ring-label-center {
    width: 44px;
    height: 44px;
}

.ring-caption {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.ring-caption span {
    color: var(--text);
    font-weight: 600;
}

/* ─── RPG Stats ─── */
.rpg-stats {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.rpg-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rpg-icon {
    font-size: 1rem;
    width: 1.2rem;
    text-align: center;
    flex-shrink: 0;
}

.rpg-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    width: 4.5rem;
    flex-shrink: 0;
}

.rpg-bar-bg {
    flex: 1;
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
}

.rpg-bar-fill {
    height: 100%;
    border-radius: 5px;
    width: 0%;
    transition: width 0.5s ease;
}

.rpg-str { background: linear-gradient(90deg, #ef4444, #f97316); }
.rpg-int { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.rpg-vit { background: linear-gradient(90deg, #16a34a, #22c55e); }

.rpg-bar-full {
    box-shadow: 0 0 8px currentColor;
}
.rpg-str.rpg-bar-full { box-shadow: 0 0 8px #f97316; }
.rpg-int.rpg-bar-full { box-shadow: 0 0 8px #8b5cf6; }
.rpg-vit.rpg-bar-full { box-shadow: 0 0 8px #22c55e; }

.rpg-val {
    font-size: 0.7rem;
    color: var(--text-dim);
    width: 2.5rem;
    text-align: right;
    flex-shrink: 0;
}

/* ─── Input section ─── */
.input-section { margin-bottom: 1.5rem; }

/* Photo buttons */
.photo-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.photo-buttons.compact {
    margin-bottom: 0.5rem;
}
.photo-buttons.compact .photo-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}
.photo-btn { flex: 1; }

/* Photo thumbnails */
.photo-thumbs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.photo-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.photo-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    padding: 0;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.7rem;
    line-height: 1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-thumb-remove:hover { background: var(--danger); }

.text-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    margin-bottom: 0.75rem;
}

#text-input {
    flex: 1;
    resize: vertical;
    min-height: 70px;
}

.mic-btn {
    width: 48px;
    min-width: 48px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: border-color 0.2s, background 0.2s;
}
.mic-btn:hover { border-color: var(--accent); }
.mic-btn.recording {
    background: var(--danger);
    border-color: var(--danger);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#audio-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.4rem 0.75rem;
    background: #111827;
    border-radius: 8px;
    font-size: 0.85rem;
}
.audio-badge { color: var(--accent); flex: 1; }
.audio-remove {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 0;
    margin: 0;
    font-size: 1rem;
    line-height: 1;
}
.audio-remove:hover { color: var(--danger); }

#analyze-btn {
    width: 100%;
    font-size: 1rem;
    padding: 0.75rem;
}

.error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* ─── Spinner ─── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner::after {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-left: 8px;
}

/* ─── Meals ─── */
#meals-section h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-dim);
    font-weight: 500;
}

.meal-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.meal-thumb {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.meal-info { flex: 1; min-width: 0; }

.meal-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.meal-macros {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 2px;
}

.meal-details {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 3px;
    line-height: 1.4;
}

.meal-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
}

.meal-kcal {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--accent);
}

.meal-time {
    font-size: 0.65rem;
    color: var(--text-dim);
}

.meal-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 0;
    margin: 0;
    font-size: 0.9rem;
    line-height: 1;
}
.meal-delete:hover { color: var(--danger); }

/* ─── History ─── */
#history-section { margin-top: 1rem; }

details summary {
    cursor: pointer;
    color: var(--text-dim);
    font-size: 0.9rem;
    padding: 0.5rem 0;
}

.history-day { margin-bottom: 1rem; }

.history-day-header {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
}

/* ─── Empty state ─── */
.empty {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.9rem;
    padding: 2rem 0;
}
