/* ===== CSS Variables ===== */
:root {
    /* Background & Surface - Silver/White Theme */
    --bg-main: #FAFBFC;
    --bg-surface: #FFFFFF;
    --bg-card: #F3F4F6;
    --bg-elevated: #E5E7EB;

    /* Yoghurt-Inspired Accents */
    --cream: #F5F0EB;
    --cream-dark: #E8DFD5;
    --pearl: #F8F9FA;

    /* Primary Colors - Cultured Silvers */
    --primary: #6B7280;
    --primary-light: #9CA3AF;
    --primary-dark: #4B5563;
    --accent: #D1D5DB;

    /* Semantic Colors */
    --positive: #14B8A6;
    --positive-light: #5EEAD4;
    --warning: #F59E0B;
    --danger: #EF4444;

    /* Score Gradient */
    --score-low: #F472B6;
    --score-mid: #9CA3AF;
    --score-high: #14B8A6;

    /* Text - Light Theme */
    --text-primary: #1F2937;
    --text-secondary: #4B5563;
    --text-muted: #6B7280;
    --text-light: #9CA3AF;

    /* Borders */
    --border-color: #E5E7EB;
    --border-light: #F3F4F6;

    /* Shadows - Soft & Glossy */
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-tub: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 40px rgba(255, 255, 255, 0.8);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== Background ===== */
.background {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse at 50% -20%, var(--cream) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 80%, rgba(212, 212, 216, 0.3) 0%, transparent 40%),
        radial-gradient(ellipse at 20% 60%, rgba(245, 240, 235, 0.5) 0%, transparent 40%),
        var(--bg-main);
}

/* Hide cloud elements */
.cloud {
    display: none;
}

/* ===== Container ===== */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: var(--spacing-xl) var(--spacing-lg);
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
    letter-spacing: -0.03em;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.02em;
}

/* ===== Card Container (Yoghurt Tub) ===== */
.yoghurt-tub {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-tub);
    overflow: hidden;
    margin-bottom: var(--spacing-xl);
    border: 1px solid var(--border-light);
    position: relative;
}

/* Glossy highlight effect */
.yoghurt-tub::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.9), transparent);
}

.yoghurt-tub::after {
    display: none;
}

.tub-lid {
    background: linear-gradient(180deg, var(--pearl) 0%, var(--bg-card) 100%);
    padding: var(--spacing-sm) var(--spacing-lg);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.lid-peel {
    display: none;
}

.lid-peel::after {
    display: none;
}

.settings-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    font-size: 0.75rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-md);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
}

.settings-btn:hover {
    color: var(--text-primary);
    border-color: var(--primary-light);
    box-shadow: var(--shadow-medium);
}

.tub-body {
    padding: var(--spacing-xl) var(--spacing-lg) var(--spacing-2xl);
    background: linear-gradient(180deg, var(--bg-surface) 0%, var(--cream) 100%);
}

/* ===== Score Section ===== */
.score-section {
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.score-dial {
    position: relative;
    width: 200px;
    margin: 0 auto var(--spacing-md);
}

.dial-svg {
    width: 100%;
    height: auto;
}

.dial-bg {
    fill: none;
    stroke: var(--bg-card);
    stroke-width: 14;
    stroke-linecap: round;
}

.dial-progress {
    fill: none;
    stroke: url(#dialGradient);
    stroke-width: 14;
    stroke-linecap: round;
    stroke-dasharray: 251;
    stroke-dashoffset: 125.5;
    transition: stroke-dashoffset 0.8s ease-out;
}

.dial-indicator {
    fill: var(--bg-surface);
    stroke: var(--primary);
    stroke-width: 2;
    filter: drop-shadow(0 2px 6px rgba(107, 114, 128, 0.3));
    transition: transform 0.8s ease-out;
}

.score-labels {
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    margin-top: -10px;
}

.score-labels span {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-light);
}

.score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-number {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: -0.03em;
}

.score-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ===== Verdict Section ===== */
.verdict-section {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    padding: var(--spacing-lg);
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
}

.verdict {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.verdict-quote {
    font-size: 0.85rem;
    font-style: italic;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    line-height: 1.5;
}

.verdict-author {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Quick Add ===== */
.quick-add {
    margin-bottom: var(--spacing-xl);
}

.quick-add-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-light);
    margin-bottom: var(--spacing-sm);
    text-align: center;
}

.yoghurt-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-sm);
}

.yoghurt-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

/* Glossy button highlight */
.yoghurt-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.6) 0%, transparent 100%);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    pointer-events: none;
}

.yoghurt-btn:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-medium);
    transform: translateY(-1px);
}

.yoghurt-btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-family);
    position: relative;
    z-index: 1;
}

/* ===== Macros Section ===== */
.macros-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-sm);
}

.macro-card {
    text-align: center;
    padding: var(--spacing-sm);
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.macro-value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.macro-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Log Section ===== */
.log-section {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-soft);
}

.log-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    background: none;
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font-family);
}

.toggle-icon {
    transition: transform 0.3s;
    color: var(--text-light);
}

.toggle-icon.open {
    transform: rotate(180deg);
}

.log-content {
    padding: 0 var(--spacing-lg) var(--spacing-lg);
}

.log-content.hidden {
    display: none;
}

.log-list {
    list-style: none;
    margin-bottom: var(--spacing-md);
}

.log-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-light);
}

.log-item:last-child {
    border-bottom: none;
}

.log-time {
    font-size: 0.75rem;
    color: var(--text-light);
}

.log-amount {
    font-weight: 600;
    color: var(--text-primary);
}

.log-type {
    font-size: 0.75rem;
    color: var(--primary);
    text-transform: capitalize;
}

.log-empty {
    text-align: center;
    color: var(--text-light);
    font-style: italic;
    padding: var(--spacing-md);
}

.clear-btn {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: transparent;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-weight: 600;
    font-size: 0.8rem;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s;
}

.clear-btn:hover {
    background: var(--danger);
    color: white;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(250, 251, 252, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--spacing-md);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-tub);
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.setting-row {
    margin-bottom: var(--spacing-lg);
}

.setting-row label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.setting-row input,
.setting-row select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.95rem;
    font-family: var(--font-family);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.setting-row input:focus,
.setting-row select:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.2);
}

.save-settings-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

/* Glossy button highlight */
.save-settings-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 100%);
    pointer-events: none;
}

.save-settings-btn:hover {
    box-shadow: var(--shadow-medium);
    transform: translateY(-1px);
}

.save-settings-btn:active {
    transform: translateY(0) scale(0.98);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: var(--spacing-lg);
    color: var(--text-light);
    font-size: 0.75rem;
}

/* ===== Responsive ===== */
/* ===== Username Section ===== */
.username-section {
    margin-bottom: var(--spacing-xl);
}

.username-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
    text-align: center;
}

.username-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.username-input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
}

.username-input {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.95rem;
    font-family: var(--font-family);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.username-input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.2);
}

.username-input:disabled {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.username-save-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.username-save-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 100%);
    pointer-events: none;
}

.username-save-btn:hover {
    box-shadow: var(--shadow-medium);
    transform: translateY(-1px);
}

.username-save-btn:disabled {
    background: var(--bg-elevated);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.username-status {
    margin-top: var(--spacing-sm);
    font-size: 0.75rem;
    color: var(--positive);
    min-height: 1.2em;
}

.username-status.error {
    color: var(--danger);
}

/* ===== Leaderboard Section ===== */
.leaderboard-section {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-tub);
    margin-bottom: var(--spacing-lg);
}

.leaderboard-title {
    text-align: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
    letter-spacing: -0.02em;
}

.leaderboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-md);
}

.leaderboard-column {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    border: 1px solid var(--border-light);
}

.column-title {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: leaderboard;
}

.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xs) 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}

.leaderboard-list li:last-child {
    border-bottom: none;
}

.leaderboard-list li::before {
    counter-increment: leaderboard;
    content: counter(leaderboard) ".";
    font-weight: 600;
    color: var(--text-muted);
    margin-right: var(--spacing-xs);
    min-width: 1.5em;
}

.leaderboard-list li:first-child::before {
    color: #FFD700;
}

.leaderboard-list li:nth-child(2)::before {
    color: #C0C0C0;
}

.leaderboard-list li:nth-child(3)::before {
    color: #CD7F32;
}

.leaderboard-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-grams {
    font-weight: 600;
    color: var(--text-primary);
    margin-left: var(--spacing-xs);
}

.leaderboard-list li.current-user {
    background: linear-gradient(90deg, rgba(20, 184, 166, 0.1) 0%, transparent 100%);
    border-radius: var(--radius-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    margin: 0 calc(-1 * var(--spacing-sm));
}

.leaderboard-list li.current-user .leaderboard-name {
    color: var(--positive);
    font-weight: 600;
}

.leaderboard-empty {
    text-align: center;
    color: var(--text-light);
    font-style: italic;
    padding: var(--spacing-md) 0;
}

.leaderboard-empty::before {
    display: none;
}

.leaderboard-updated {
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-light);
    margin-top: var(--spacing-md);
}

/* ===== Responsive ===== */
@media (max-width: 500px) {
    .leaderboard-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-sm);
    }

    .leaderboard-column {
        padding: var(--spacing-sm);
    }
}

@media (max-width: 400px) {
    .container {
        padding: var(--spacing-md);
    }

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

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

    .score-number {
        font-size: 2.75rem;
    }

    .username-input-wrapper {
        flex-direction: column;
    }

    .username-save-btn {
        width: 100%;
    }
}