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

/* ── Variables ── */
:root {
  --bg: #0e0f0e;
  --surface: #161714;
  --surface2: #1e1f1c;
  --border: rgba(255, 255, 255, 0.08);
  --border2: rgba(255, 255, 255, 0.15);
  --text: #f0efe8;
  --muted: #7a7a72;
  --accent: #c8f135;
  --accent-dim: rgba(200, 241, 53, 0.1);
  --protein: #5fa3e8;
  --carbs: #f0a040;
  --fat: #6ec97a;
  --danger: #f06060;
  --font-display: "Syne", sans-serif;
  --font-body: "DM Sans", sans-serif;
}

/* ── Base ── */
html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

/* ── Logo ── */
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 28px;
  letter-spacing: -1px;
  margin-bottom: 12px;
  display: block;
}

.logo span {
  color: var(--accent);
}

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 48px 24px 28px;
  background: radial-gradient(
    ellipse 55% 35% at 50% 0%,
    rgba(200, 241, 53, 0.08) 0%,
    transparent 70%
  );
}

.hero .logo {
  font-size: 32px;
  margin-bottom: 24px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(42px, 8vw, 80px);
  font-weight: 800;
  line-height: 0.93;
  letter-spacing: -2px;
  margin-bottom: 16px;
}

h1 em {
  font-style: normal;
  color: var(--accent);
}

.sub {
  font-size: 15px;
  color: var(--muted);
  max-width: 420px;
  margin: 0 auto 20px;
  line-height: 1.6;
  font-weight: 300;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
}

.btn-install {
  display: none;
  margin-top: 12px;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-install:hover {
  background: var(--accent);
  color: #0d0e0d;
}

.pill::before {
  content: "●";
  color: var(--accent);
  font-size: 8px;
}

/* ── Main ── */
.main {
  max-width: 840px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

/* ── Load banner ── */
#load-banner {
  display: none;
  margin-bottom: 14px;
  background: rgba(200, 241, 53, 0.07);
  border: 1px solid rgba(200, 241, 53, 0.22);
  border-radius: 14px;
  padding: 18px 22px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

#load-banner p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}

#load-banner strong {
  color: var(--accent);
}

#load-banner code {
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.btn-file-wrap {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 8px;
}

.btn-file-wrap input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.btn-file-inner {
  display: block;
  background: var(--accent);
  color: #0d0e0d;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  pointer-events: none;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  margin-bottom: 14px;
}

.card-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 18px;
}

/* ── Col header ── */
.col-head {
  display: grid;
  grid-template-columns: 1fr 90px 80px 36px;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

/* ── Rows ── */
#food-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row-group {
  animation: fadeIn 0.15s ease;
}

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

.food-row {
  display: grid;
  grid-template-columns: 1fr 90px 80px 36px;
  gap: 8px;
  align-items: start;
}

.iw {
  position: relative;
}

/* ── Form inputs ── */
input[type="text"],
input[type="number"],
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 12px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="text"]::placeholder {
  color: var(--muted);
}

select {
  cursor: pointer;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237a7a72'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-color: var(--surface2);
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

/* ── Delete button ── */
.del-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.del-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(240, 96, 96, 0.08);
}

/* ── Dropdown ── */
.dd {
  position: fixed;
  z-index: 999;
  background: #21221f;
  border: 1px solid var(--border2);
  border-radius: 10px;
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  width: min(480px, calc(100vw - 48px));
}

.dd.open {
  display: block;
}

.dd-item {
  padding: 10px 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.dd-item:last-child {
  border-bottom: none;
}
.dd-item:hover,
.dd-item.hi {
  background: var(--accent-dim);
}

.dd-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dd-cat {
  font-size: 10px;
  color: var(--muted);
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 5px;
}

.dd-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  display: block;
}

.dd-meta b {
  color: var(--text);
  font-weight: 400;
}
.dd-msg {
  padding: 12px 13px;
  font-size: 13px;
  color: var(--muted);
}

/* ── Selected badge ── */
.sel {
  margin-top: 4px;
  background: var(--accent-dim);
  border: 1px solid rgba(200, 241, 53, 0.18);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12px;
  display: none;
  align-items: center;
  gap: 8px;
}

.sel.on {
  display: flex;
}

.sel-name {
  color: var(--accent);
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sel-cat {
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.sel-info {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.sel-x {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.sel-x:hover {
  color: var(--danger);
}

/* ── Actions ── */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn-add {
  background: transparent;
  border: 1px dashed var(--border2);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 15px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s;
}

.btn-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.btn-clr {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 15px;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s;
}

.btn-clr:hover {
  border-color: var(--border2);
  color: var(--text);
}

.btn-calc {
  margin-top: 18px;
  width: 100%;
  background: var(--accent);
  color: #0d0e0d;
  border: none;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: all 0.15s;
}

.btn-calc:hover {
  background: #d6f548;
  transform: translateY(-1px);
}
.btn-calc:active {
  transform: none;
}

/* ── Messages ── */
.err,
.warn {
  display: none;
  margin-top: 12px;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
}

.err {
  background: rgba(240, 96, 96, 0.08);
  border: 1px solid rgba(240, 96, 96, 0.3);
  color: var(--danger);
}
.warn {
  background: rgba(240, 160, 64, 0.07);
  border: 1px solid rgba(240, 160, 64, 0.25);
  color: var(--carbs);
}

/* ── Results ── */
.results {
  display: none;
  animation: slideUp 0.3s ease;
}

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

/* ── Tiles ── */
.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 11px;
  margin-bottom: 18px;
}

.tile {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 13px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.tile::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.tile.kc::before {
  background: var(--accent);
}
.tile.pr::before {
  background: var(--protein);
}
.tile.cb::before {
  background: var(--carbs);
}
.tile.ft::before {
  background: var(--fat);
}

.tl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 5px;
}

.tv {
  font-family: var(--font-body);
  font-size: 27px;
  font-weight: 700;
  line-height: 1;
}

.tile.kc .tv {
  color: var(--accent);
}
.tile.pr .tv {
  color: var(--protein);
}
.tile.cb .tv {
  color: var(--carbs);
}
.tile.ft .tv {
  color: var(--fat);
}
.tu {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Macro bars ── */
.bar-row {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 9px;
}

.bar-lbl {
  font-size: 13px;
  color: var(--muted);
  width: 54px;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  background: var(--surface2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bar-fill.pr {
  background: var(--protein);
}
.bar-fill.cb {
  background: var(--carbs);
}
.bar-fill.ft {
  background: var(--fat);
}
.bar-pct {
  font-size: 12px;
  color: var(--muted);
  width: 30px;
  text-align: right;
  font-family: var(--font-body);
}

/* ── Breakdown table ── */
table.bt {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.bt thead tr {
  border-bottom: 1px solid var(--border);
}
table.bt th {
  text-align: left;
  padding: 7px 9px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 500;
}
table.bt th:not(:first-child) {
  text-align: right;
}
table.bt td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
table.bt td:not(:first-child) {
  text-align: right;
  color: var(--muted);
}
table.bt tbody tr:last-child td {
  border-bottom: none;
}
table.bt tfoot td {
  border-top: 1px solid var(--border2);
  font-family: var(--font-body);
  font-weight: 700;
  padding: 11px 9px;
}
table.bt tfoot td:not(:first-child) {
  color: var(--accent);
}

.fdot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 7px;
  vertical-align: middle;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 22px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

footer span {
  color: var(--accent);
}

footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

footer a:hover {
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .hero {
    padding: 46px 18px 34px;
  }
  .main {
    padding: 22px 14px 60px;
  }
  .card {
    padding: 18px 14px;
  }
  .col-head,
  .food-row {
    grid-template-columns: 1fr 72px 70px 36px;
  }
  .tiles {
    grid-template-columns: repeat(2, 1fr);
  }
}
