@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #090b10;
  --surface: #0f1219;
  --surface-2: #141923;
  --line: rgba(255,255,255,.09);
  --text: #f4f5f7;
  --muted: #969eac;
  --accent: #ff8e74;
  --blue: #79b8ff;
  --purple: #b89cff;
  --orange: #ffb86b;
  --red: #ff6b6b;
  --radius: 20px;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 75% -10%, rgba(121,184,255,.08), transparent 30%),
    radial-gradient(circle at 5% 20%, rgba(255,142,116,.055), transparent 25%),
    var(--bg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
::selection { background: var(--accent); color: #1c0e09; }
.hidden { display: none !important; }

.noise {
  position: fixed; inset: 0; pointer-events: none; z-index: 20; opacity: .027;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E");
}

.shell { width: min(560px, calc(100% - 32px)); margin-inline: auto; }

/* ---------- header ---------- */
.site-header {
  width: min(560px, calc(100% - 32px)); height: 68px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); position: relative; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 11px; font-family: var(--mono); font-size: 14px; color: #c9ced6; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: var(--accent); background: rgba(255,142,116,.08); border: 1px solid rgba(255,142,116,.18); }
.header-right { display: flex; gap: 8px; }

.icon-button {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.018);
  color: var(--muted); cursor: pointer; transition: color .2s, border-color .2s;
}
.icon-button:hover { color: var(--text); border-color: rgba(255,255,255,.2); }
.icon-button svg { width: 18px; height: 18px; }
.icon-button.big { width: 54px; height: 54px; border-radius: 14px; flex: none; }
.icon-button.big svg { width: 22px; height: 22px; }

/* ---------- shared type ---------- */
.eyebrow { font-family: var(--mono); text-transform: uppercase; letter-spacing: .11em; font-size: 11px; color: var(--muted); }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px rgba(255,142,116,.08); margin-right: 10px; }
h1 { margin: 18px 0; font-size: clamp(38px, 11vw, 54px); letter-spacing: -.055em; line-height: 1.04; }
h2 { margin: 14px 0 20px; font-size: clamp(30px, 8.5vw, 42px); letter-spacing: -.05em; line-height: 1.08; }
.accent-text { color: var(--accent); }
.intro { font-size: 16px; line-height: 1.7; color: var(--muted); margin: 0 0 30px; }
.hint { font-size: 13px; line-height: 1.7; color: var(--muted); }

.view { padding-block: 44px 60px; }

/* ---------- buttons ---------- */
.button {
  min-height: 52px; padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  border-radius: 14px; font-weight: 700; font-size: 14px; border: 0; cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, background .2s ease, opacity .2s;
}
.button:hover { transform: translateY(-2px); }
.button:disabled { opacity: .5; pointer-events: none; }
.button-primary { color: #1c0e09; background: var(--accent); box-shadow: 0 14px 45px rgba(255,142,116,.12); }
.button-ghost { border: 1px solid var(--line); color: #dce0e7; background: rgba(255,255,255,.018); }
.button-ghost:hover { border-color: rgba(255,255,255,.2); }
.grow { flex: 1; }

/* ---------- auth ---------- */
.auth-actions { display: flex; flex-direction: column; gap: 18px; margin-bottom: 46px; }
.auth-actions .button-primary { width: 100%; }
.divider { display: flex; align-items: center; gap: 14px; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; letter-spacing: .1em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-row { display: flex; gap: 10px; }
.login-row input {
  flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  color: var(--text); font: 500 18px var(--mono); letter-spacing: .35em; text-align: center; text-transform: uppercase;
  padding: 0 14px; min-height: 52px; outline: none; transition: border-color .2s;
}
.login-row input:focus { border-color: rgba(255,142,116,.4); }

/* ---------- new id ---------- */
.id-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border: 1px solid rgba(255,142,116,.25); border-radius: var(--radius); padding: 26px 22px;
  background: radial-gradient(circle at 85% 20%, rgba(255,142,116,.08), transparent 45%), var(--surface);
  margin: 26px 0 14px;
}
.id-chars { font: 500 34px var(--mono); letter-spacing: .3em; color: var(--accent); }
#view-newid .button-primary { width: 100%; margin-top: 26px; }

/* ---------- setup form ---------- */
.setup-form { display: flex; flex-direction: column; gap: 22px; margin-top: 28px; }
.field-group { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field-label { font: 10px var(--mono); text-transform: uppercase; letter-spacing: .11em; color: var(--muted); }
.setup-form input {
  background: var(--surface); border: 1px solid var(--line); border-radius: 13px; color: var(--text);
  font: 600 16px var(--sans); padding: 14px; width: 100%; outline: none; transition: border-color .2s;
}
.setup-form input:focus { border-color: rgba(255,142,116,.4); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg-wrap { display: flex; flex-wrap: wrap; }
.seg button {
  border: 1px solid var(--line); border-radius: 100px; background: rgba(255,255,255,.018); color: var(--muted);
  font: 600 13px var(--sans); padding: 11px 15px; cursor: pointer; transition: all .2s; flex: 1 0 auto;
}
.seg button.selected { background: rgba(255,142,116,.1); border-color: rgba(255,142,116,.45); color: var(--accent); }
.form-error { color: var(--red); font: 12px var(--mono); margin: 0; }
#btn-setup-submit { width: 100%; }

/* ---------- day view ---------- */
.day-switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 20px; }
.day-arrow {
  width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.018);
  color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; transition: color .2s, border-color .2s;
}
.day-arrow:hover { color: var(--text); border-color: rgba(255,255,255,.2); }
.day-arrow:disabled { opacity: .3; pointer-events: none; }
.day-label { flex: 1; background: none; border: 0; cursor: pointer; font: 500 15px var(--mono); color: var(--text); letter-spacing: .02em; padding: 12px 0; }
#day-picker { position: absolute; inset: 0; opacity: 0; pointer-events: none; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(150deg, rgba(255,255,255,.025), rgba(255,255,255,.009)); padding: 18px; }
.mini-label { font: 10px var(--mono); text-transform: uppercase; letter-spacing: .11em; color: var(--muted); }

.kcal-card { margin-bottom: 10px; }
.kcal-top { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 14px; }
.kcal-nums { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.kcal-nums strong { font: 500 34px var(--mono); letter-spacing: -.03em; }
.kcal-nums span { font: 12px var(--mono); color: var(--muted); }
.kcal-left { font: 11px var(--mono); color: var(--muted); padding-bottom: 6px; text-align: right; }
.kcal-left b { color: var(--accent); font-weight: 500; }
.kcal-left.over b { color: var(--red); }

.bar { height: 7px; border-radius: 100px; background: rgba(255,255,255,.06); overflow: hidden; }
.bar-fill { height: 100%; width: 0%; border-radius: 100px; background: var(--accent); box-shadow: 0 0 14px rgba(255,142,116,.35); transition: width .5s ease; }
.bar-fill.over { background: var(--red); box-shadow: 0 0 14px rgba(255,107,107,.35); }
.fill-protein { background: var(--accent); }
.fill-carbs { background: var(--blue); box-shadow: 0 0 14px rgba(121,184,255,.35); }
.fill-fat { background: var(--purple); box-shadow: 0 0 14px rgba(184,156,255,.35); }

.macro-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.macro-card { padding: 14px; display: flex; flex-direction: column; gap: 9px; }
.macro-nums { display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; }
.macro-nums strong { font: 500 19px var(--mono); }
.macro-nums span { font: 10px var(--mono); color: var(--muted); }

/* ---------- log list ---------- */
.log-section { margin-top: 34px; }
.log-heading { margin-bottom: 14px; }
.entry-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 16px;
  background: linear-gradient(150deg, rgba(255,255,255,.02), rgba(255,255,255,.006)); padding: 13px 15px;
}
.entry-main { flex: 1; min-width: 0; }
.entry-label { font-weight: 600; font-size: 14px; margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-macros { font: 10px var(--mono); color: var(--muted); letter-spacing: .04em; }
.entry-macros b { color: var(--text); font-weight: 500; }
.entry-kcal { font: 500 15px var(--mono); color: var(--accent); white-space: nowrap; }
.entry-delete {
  width: 32px; height: 32px; border: 0; border-radius: 10px; background: none; color: #5d6673;
  font-size: 17px; cursor: pointer; transition: color .2s, background .2s; flex: none;
}
.entry-delete:hover { color: var(--red); background: rgba(255,107,107,.08); }
.empty-log { font-size: 14px; line-height: 1.7; color: var(--muted); border: 1px dashed var(--line); border-radius: 16px; padding: 20px; margin: 0; text-align: center; }

.fab-space { height: 90px; }
.fab {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  min-height: 56px; padding: 0 34px; border: 0; border-radius: 100px; cursor: pointer;
  background: var(--accent); color: #1c0e09; font: 800 15px var(--sans);
  box-shadow: 0 14px 45px rgba(255,142,116,.22), 0 4px 18px rgba(0,0,0,.5); z-index: 30;
  transition: transform .2s;
}
.fab:hover { transform: translateX(-50%) translateY(-2px); }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5,7,10,.72); backdrop-filter: blur(3px); z-index: 40; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(560px, 100%);
  background: var(--surface-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; padding: 14px 20px calc(24px + env(safe-area-inset-bottom)); z-index: 41;
  animation: sheet-up .28s ease;
}
@keyframes sheet-up { from { transform: translateX(-50%) translateY(40px); opacity: 0; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 100px; background: rgba(255,255,255,.14); margin: 0 auto 16px; }
.sheet-hint { font-size: 13px; color: var(--muted); line-height: 1.6; margin: 10px 0 12px; }
.sheet textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; color: var(--text);
  font: 500 16px/1.5 var(--sans); padding: 14px; outline: none; resize: none; transition: border-color .2s;
}
.sheet textarea:focus { border-color: rgba(255,142,116,.4); }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }

/* ---------- toast / loading ---------- */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 100px;
  padding: 12px 22px; font: 12px var(--mono); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.5);
  max-width: calc(100% - 40px); text-align: center;
}
.toast.error { border-color: rgba(255,107,107,.4); color: #ffb1b1; }
.loading { position: fixed; inset: 0; background: rgba(5,7,10,.6); backdrop-filter: blur(2px); z-index: 50; display: grid; place-items: center; }
.loading-box {
  display: flex; align-items: center; gap: 12px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px 26px; font: 13px var(--mono); color: #d7dce5;
}
.loading-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse .9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.8); } }

/* ---------- footer ---------- */
footer { margin-top: 30px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; color: #68717f; font: 10px var(--mono); padding-block: 26px calc(26px + env(safe-area-inset-bottom)); }
footer a:hover { color: var(--text); }

@media (min-width: 561px) {
  .view { padding-block: 60px 70px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
