:root {
  --bg: #0a0d11;
  --panel: #11151b;
  --panel-raised: #161b22;
  --line: #253039;
  --line-bright: #3a4a56;
  --ink: #dce6ea;
  --dim: #7d919c;
  --cyan: #4fe0c8;
  --cyan-dim: rgba(79, 224, 200, 0.14);
  --amber: #ffb020;
  --red: #ff5f56;

  --font-display: "Orbitron", "IBM Plex Mono", monospace;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: 3rem;
  background-image:
    radial-gradient(ellipse at top, rgba(79,224,200,0.05), transparent 60%);
}

button { font-family: inherit; }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-mark {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(79,224,200,0.5);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
}
.icon-btn:active { color: var(--cyan); }

/* ---------- layout ---------- */

.wrap {
  max-width: 440px;
  margin: 0 auto;
  padding: 1.1rem 1rem 2rem;
}

.banner {
  background: rgba(255,176,32,0.08);
  border: 1px solid var(--amber);
  color: var(--amber);
  padding: 0.7rem 0.9rem;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.banner .link-btn {
  color: var(--amber);
  text-decoration: underline;
  font-weight: 600;
}

.hidden { display: none !important; }

.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.date-nav .icon-btn {
  color: var(--ink);
  font-size: 1.6rem;
}

.date-label {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--dim);
}

/* ---------- scan panel (nutrition readout) ---------- */

.label-panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.1rem;
  margin-bottom: 1.1rem;
  box-shadow: 0 0 0 1px rgba(79,224,200,0.04), 0 20px 40px -20px rgba(0,0,0,0.6);
}

/* corner reticle marks — the signature element */
.label-panel::before,
.label-panel::after,
.label-panel .corner-tl,
.label-panel .corner-br {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--cyan);
  border-style: solid;
  opacity: 0.7;
}
.label-panel::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; border-radius: 6px 0 0 0; }
.label-panel::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; border-radius: 0 0 6px 0; }

.label-title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 0.5rem;
}

.rule {
  background: var(--line);
  height: 1px;
  margin: 0.4rem 0;
}
.rule.thin { height: 1px; }
.rule.thick { height: 1px; background: var(--line-bright); }
.rule.thick.double {
  height: 1px;
  background: var(--cyan);
  opacity: 0.4;
  box-shadow: 0 0 8px rgba(79,224,200,0.6);
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.92rem;
  padding: 0.35rem 0;
  color: var(--ink);
}

.label-row.small {
  font-size: 0.78rem;
  color: var(--dim);
  font-family: var(--font-mono);
}

.label-row.remaining span:last-child {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--cyan);
}

.calories-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.5rem 0 0.3rem;
}

.calories-label {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.calories-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 3rem;
  line-height: 1;
  color: var(--cyan);
  text-shadow: 0 0 18px rgba(79,224,200,0.55), 0 0 2px rgba(79,224,200,0.8);
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink);
}

/* ---------- add button ---------- */

.add-btn {
  width: 100%;
  background: var(--cyan);
  color: #06110f;
  border: none;
  padding: 0.95rem;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 1.3rem;
  box-shadow: 0 0 24px -6px rgba(79,224,200,0.6);
}

.add-btn:active { opacity: 0.85; }

/* ---------- log list ---------- */

.log-list {
  display: flex;
  flex-direction: column;
}

.log-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.log-entry-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.log-entry-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-entry-meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--dim);
}

.log-entry-cals {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--cyan);
  white-space: nowrap;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--red);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  opacity: 0.7;
}
.delete-btn:active { opacity: 1; }

.empty-state {
  text-align: center;
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 2rem 0.5rem;
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4,6,8,0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: none;
  width: 100%;
  max-width: 460px;
  border-radius: 14px 14px 0 0;
  padding: 1.1rem 1.2rem calc(1.4rem + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.9rem;
}

/* photo picker styled like a scan viewfinder */
.photo-picker {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px dashed var(--line-bright);
  border-radius: 10px;
  padding: 2.4rem 1rem;
  cursor: pointer;
  color: var(--dim);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.85rem;
  background:
    linear-gradient(var(--cyan), var(--cyan)) top left,
    linear-gradient(var(--cyan), var(--cyan)) top left,
    linear-gradient(var(--cyan), var(--cyan)) top right,
    linear-gradient(var(--cyan), var(--cyan)) top right,
    linear-gradient(var(--cyan), var(--cyan)) bottom left,
    linear-gradient(var(--cyan), var(--cyan)) bottom left,
    linear-gradient(var(--cyan), var(--cyan)) bottom right,
    linear-gradient(var(--cyan), var(--cyan)) bottom right;
  background-repeat: no-repeat;
  background-size: 2px 16px, 16px 2px;
}

.photo-picker-icon { font-size: 1.8rem; filter: grayscale(1) brightness(1.6); }

#previewImg {
  width: 100%;
  border-radius: 10px;
  margin-bottom: 0.8rem;
  max-height: 300px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.primary-btn {
  width: 100%;
  background: var(--cyan);
  color: #06110f;
  border: none;
  padding: 0.85rem;
  font-size: 0.92rem;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0.4rem;
  box-shadow: 0 0 20px -6px rgba(79,224,200,0.6);
}

.link-btn {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: none;
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.7rem 0;
  cursor: pointer;
  text-decoration: underline;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--cyan);
  border-radius: 50%;
  margin: 1.5rem auto 0.8rem;
  animation: spin 0.8s linear infinite;
  box-shadow: 0 0 16px rgba(79,224,200,0.3);
}

@keyframes spin { to { transform: rotate(360deg); } }

#loadingStage, #captureStage { text-align: center; }
#loadingStage p {
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.error-text {
  color: var(--red);
  font-size: 0.88rem;
  text-align: center;
  margin: 1rem 0 0.2rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--dim);
  margin: 0 0 0.8rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.7rem;
}

.field input {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--cyan);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.6rem;
  background: var(--panel-raised);
}
.field input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(79,224,200,0.15);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.7rem;
}

.notes {
  font-size: 0.78rem;
  color: var(--dim);
  font-style: italic;
  margin: -0.2rem 0 0.6rem;
}

@media (min-width: 480px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 14px; border-bottom: 1px solid var(--line); }
}
