:root {
    --bg: #0b1a14;
    --bg-elevated: rgba(18, 42, 33, 0.78);
    --bg-elevated-solid: #122a21;
    --ink: #eef7f1;
    --muted: #9bb5a8;
    --accent: #9be15d;
    --accent-2: #2bbbad;
    --warn: #ffb454;
    --danger: #ff6b6b;
    --line: rgba(238, 247, 241, 0.1);
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
    --radius: 22px;
    --font-display: "Syne", sans-serif;
    --font-body: "Figtree", sans-serif;
    --ring-c: 552.92; /* 2πr with r=88 */
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    font-family: var(--font-body);
    background:
        radial-gradient(1200px 700px at 10% -10%, rgba(155, 225, 93, 0.16), transparent 55%),
        radial-gradient(900px 600px at 100% 100%, rgba(43, 187, 173, 0.14), transparent 50%),
        linear-gradient(165deg, #08140f 0%, #0f241c 45%, #0b1a14 100%);
}

body {
    position: relative;
    overflow-x: hidden;
}

.bg-orbit {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.9;
    animation: drift 28s ease-in-out infinite alternate;
}

.bg-orbit svg {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes drift {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to { transform: translate3d(-1.5%, 1%, 0) scale(1.03); }
}

.topbar,
.layout,
.site-footer {
    position: relative;
    z-index: 1;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem clamp(1rem, 3vw, 2.5rem) 0.5rem;
}

.brand {
    display: flex;
    gap: 0.85rem;
    align-items: center;
}

.brand-mark {
    width: 48px;
    height: 48px;
    color: var(--accent);
    animation: spin-soft 10s linear infinite;
}

@keyframes spin-soft {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.brand-name {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.7rem, 3vw, 2.2rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
}

.brand-tag {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.date-field input,
.goal-controls input,
.search-shell input,
.add-dialog select,
.add-dialog input[type="number"] {
    appearance: none;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
    border-radius: 14px;
    padding: 0.7rem 0.9rem;
    font: inherit;
}

.date-field input { min-width: 10.5rem; }

.icon-btn,
.ghost-btn,
.primary-btn,
.meal-chip {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.icon-btn {
    width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    padding: 0;
}

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

.ghost-btn,
.primary-btn {
    padding: 0.65rem 1.1rem;
    font-weight: 600;
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #08140f;
    border-color: transparent;
}

.icon-btn:hover,
.ghost-btn:hover,
.primary-btn:hover,
.meal-chip:hover {
    transform: translateY(-1px);
    border-color: rgba(155, 225, 93, 0.45);
}

.layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    grid-template-areas:
        "ring search"
        "ring diary";
    gap: 1.1rem;
    padding: 1rem clamp(1rem, 3vw, 2.5rem) 2rem;
}

.ring-panel { grid-area: ring; }
.search-panel { grid-area: search; }
.diary-panel { grid-area: diary; }

.panel {
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.35rem 1.4rem;
    animation: rise 520ms ease both;
}

.search-panel { animation-delay: 80ms; }
.diary-panel { animation-delay: 140ms; }

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

h2, h3 {
    margin: 0;
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

.lede, .muted {
    color: var(--muted);
    margin: 0.35rem 0 1rem;
    line-height: 1.45;
}

.ring-wrap {
    display: grid;
    place-items: center;
}

#calorie-ring {
    width: min(100%, 260px);
    height: auto;
    overflow: visible;
}

.ring-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 14;
}

.ring-progress {
    fill: none;
    stroke-width: 14;
    stroke-linecap: round;
    stroke-dasharray: var(--ring-c);
    stroke-dashoffset: var(--ring-c);
    transition: stroke-dashoffset 700ms cubic-bezier(0.22, 1, 0.36, 1);
    filter: drop-shadow(0 0 10px rgba(155, 225, 93, 0.35));
}

.ring-kcal {
    fill: var(--ink);
    font-family: var(--font-display);
    font-size: 42px;
    font-weight: 800;
}

.ring-label {
    fill: var(--muted);
    font-size: 13px;
}

.goal-row {
    margin-top: 0.4rem;
    display: grid;
    gap: 0.55rem;
}

.goal-row label {
    color: var(--muted);
    font-size: 0.9rem;
}

.goal-controls {
    display: flex;
    gap: 0.5rem;
}

.goal-controls input { width: 100%; }

.remaining {
    margin: 0;
    font-weight: 600;
    color: var(--accent);
}

.macro-bars {
    margin-top: 1.2rem;
    display: grid;
    gap: 0.85rem;
}

.macro-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.macro-head strong { color: var(--ink); }

.macro svg { width: 100%; height: 6px; display: block; }
.bar-bg { fill: rgba(255, 255, 255, 0.08); }
.bar-fill { fill: var(--accent-2); transition: width 500ms ease; }
.macro[data-macro="protein"] .bar-fill { fill: #9be15d; }
.macro[data-macro="carbs"] .bar-fill { fill: #2bbbad; }
.macro[data-macro="fat"] .bar-fill { fill: #ffb454; }

.weight-block {
    margin-top: 1.35rem;
    padding-top: 1.15rem;
    border-top: 1px solid var(--line);
}

.weight-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.7rem;
}

.weight-head h3 {
    margin: 0;
    font-size: 1.05rem;
}

.weight-head .lede {
    margin: 0;
    font-size: 0.88rem;
    text-align: right;
}

.weight-form {
    display: grid;
    gap: 0.55rem;
}

.weight-form select {
    appearance: none;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
    border-radius: 14px;
    padding: 0.7rem 0.85rem;
    font: inherit;
    min-width: 4.5rem;
}

.weight-form .goal-controls {
    grid-template-columns: 1fr auto auto;
    display: grid;
}

.weight-clear {
    justify-self: start;
    padding: 0.4rem 0.85rem;
    font-size: 0.88rem;
}

.weight-chart {
    width: 100%;
    height: auto;
    margin-top: 0.85rem;
    display: block;
    overflow: visible;
}

.weight-area {
    fill: rgba(43, 187, 173, 0.16);
    stroke: none;
}

.weight-line {
    fill: none;
    stroke: url(#weightGrad);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 6px rgba(43, 187, 173, 0.35));
}

.weight-dot {
    fill: var(--accent);
    stroke: #0b1a14;
    stroke-width: 2;
}

.weight-empty {
    fill: var(--muted);
    font-size: 12px;
    font-family: var(--font-body);
}

.search-form { margin-bottom: 0.85rem; }

.search-shell {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.55rem;
    align-items: center;
    padding: 0.35rem 0.35rem 0.35rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(0, 0, 0, 0.18);
}

.search-shell svg {
    width: 20px;
    height: 20px;
    color: var(--muted);
}

.search-shell input {
    border: 0;
    background: transparent;
    padding-left: 0;
    width: 100%;
    outline: none;
}

.meal-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.9rem;
}

.meal-chip {
    padding: 0.45rem 0.85rem;
    font-size: 0.92rem;
}

.meal-chip.active {
    background: rgba(155, 225, 93, 0.16);
    border-color: rgba(155, 225, 93, 0.55);
    color: var(--accent);
}

.status {
    margin: 0 0 0.85rem;
    padding: 0.75rem 0.9rem;
    border-radius: 14px;
    background: rgba(255, 180, 84, 0.12);
    border: 1px solid rgba(255, 180, 84, 0.35);
    color: #ffd9a8;
}

.status.error {
    background: rgba(255, 107, 107, 0.12);
    border-color: rgba(255, 107, 107, 0.35);
    color: #ffc9c9;
}

.results {
    display: grid;
    gap: 0.65rem;
    max-height: 360px;
    overflow: auto;
    padding-right: 0.2rem;
}

.result-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.85rem 0.95rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
}

.result-row h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 650;
}

.result-row p {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.4rem;
}

.panel-head .lede { margin: 0; }

.diary-list {
    display: grid;
    gap: 1rem;
}

.meal-block h3 {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.05rem;
    margin-bottom: 0.55rem;
}

.meal-block h3 svg {
    width: 22px;
    height: 22px;
    color: var(--accent-2);
}

.entry {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.8rem 0;
    border-top: 1px solid var(--line);
}

.entry:first-of-type { border-top: 0; }

.entry strong { display: block; }
.entry span { color: var(--muted); font-size: 0.88rem; }
.entry .cals { font-weight: 700; min-width: 4.5rem; text-align: right; }

.empty {
    color: var(--muted);
    padding: 1.4rem 0.2rem;
}

.add-dialog {
    width: min(92vw, 420px);
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--bg-elevated-solid);
    color: var(--ink);
    padding: 0;
    box-shadow: var(--shadow);
}

.add-dialog::backdrop {
    background: rgba(4, 12, 9, 0.72);
    backdrop-filter: blur(4px);
}

.add-dialog form {
    display: grid;
    gap: 0.85rem;
    padding: 1.2rem 1.25rem 1.3rem;
}

.add-dialog header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 0.75rem;
}

.add-dialog label {
    display: grid;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.preview {
    padding: 0.8rem 0.9rem;
    border-radius: 14px;
    background: rgba(155, 225, 93, 0.08);
    border: 1px solid rgba(155, 225, 93, 0.22);
    font-weight: 600;
}

.add-dialog menu {
    display: flex;
    justify-content: end;
    gap: 0.5rem;
    margin: 0.2rem 0 0;
    padding: 0;
}

.site-footer {
    padding: 0 1.5rem 2rem;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
}

.site-footer a { color: var(--accent-2); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "ring"
            "search"
            "diary";
    }
}

@media (max-width: 640px) {
    .search-shell {
        grid-template-columns: auto 1fr;
    }
    .search-shell .primary-btn {
        grid-column: 1 / -1;
    }
    .entry {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "info cals"
            "info del";
    }
    .entry .info { grid-area: info; }
    .entry .cals { grid-area: cals; }
    .entry .icon-btn { grid-area: del; justify-self: end; }
}
