:root {
  color-scheme: light dark;
  --bg: #fbfaf7;
  --surface: #f1efe9;
  --text: #1f1e1b;
  --dim: #6f6c64;
  --line: #dcd9d0;
  --green: #2c7a4b;
  --yellow: #a06a00;
  --red: #c0392b;
  --accent: #1f1e1b;
  --on-accent: #fbfaf7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #24231f;
    --text: #ece9e1;
    --dim: #9a968b;
    --line: #36342e;
    --green: #5ec486;
    --yellow: #e0b04a;
    --red: #f0796b;
    --accent: #ece9e1;
    --on-accent: #141412;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  -webkit-text-size-adjust: 100%;
}

h1,
p {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

p:empty {
  display: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.dim {
  color: var(--dim);
}

.error,
.red {
  color: var(--red);
}

.warn,
.yellow {
  color: var(--yellow);
}

.ok,
.green {
  color: var(--green);
}

/* The app: fixed header and input, and the day scrolling between them. */

#app {
  display: flex;
  flex-direction: column;
  height: var(--app-height, 100dvh);
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  padding: 4px 0;
}

header h1 {
  font-weight: 600;
  text-align: center;
}

header button {
  width: 44px;
  height: 44px;
  font-size: 24px;
}

header button:disabled {
  opacity: 0.25;
  cursor: default;
}

/*
 * iOS 26 blurs about 40pt below the status bar in a Home Screen app, and
 * nothing turns that off, so the header sits below it. A phone on its side
 * has no status bar, and little height to spare.
 */
@media (display-mode: standalone) and (min-height: 500px) {
  header {
    padding-top: 28px;
  }
}

#log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

/* Progress */

.goal {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  margin-bottom: 12px;
}

.goal .name {
  grid-row: 1;
  grid-column: 1;
}

.goal .said {
  grid-row: 1;
  grid-column: 2;
  text-align: right;
}

.goal .bar {
  grid-row: 2;
  grid-column: 1 / -1;
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface);
}

.goal .amount {
  grid-row: 3;
  grid-column: 1 / -1;
  color: var(--dim);
  font-size: 13px;
}

.fill {
  height: 100%;
}

.fill.green {
  background: var(--green);
}

.fill.yellow {
  background: var(--yellow);
}

.fill.red {
  background: var(--red);
}

.mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
}

#other,
#burned {
  margin-bottom: 8px;
  font-size: 13px;
}

/* Meals */

#meals {
  margin-top: 8px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.5em 4.5em;
  gap: 8px;
  padding: 3px 0;
}

.row.head {
  padding: 0;
  font-size: 13px;
}

.row.meal {
  margin-top: 10px;
  font-weight: 600;
}

.row.meal .num {
  font-weight: 400;
}

.row.item .food {
  padding-left: 1em;
}

.food {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row.doomed {
  color: var(--red);
  text-decoration: line-through;
}

.why {
  padding-left: 1em;
  font-size: 13px;
}

#delete {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 14px;
}

.quiet {
  min-height: 44px;
  padding: 0 4px;
  color: var(--dim);
}

.danger {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
}

/* The input */

footer {
  flex: none;
  padding: 8px 0 max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

/* The keyboard covers the home indicator, so there's nothing to leave room for. */
.keyboard footer {
  padding-bottom: 8px;
}

#preview {
  padding-bottom: 8px;
  font-size: 14px;
}

#suggestions {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

#suggestions:not(:empty) {
  padding-bottom: 8px;
}

#suggestions::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  max-width: 70vw;
  min-height: 36px;
  padding: 0 12px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

#add {
  display: flex;
  gap: 8px;
}

/* Inputs are 16px, or iOS zooms the page when they're focused. */
input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 16px;
}

input:focus {
  border-color: var(--text);
  outline: none;
}

button[type="submit"] {
  flex: none;
  height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Logging in */

body.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.login h1 {
  margin-bottom: 8px;
  font-size: 24px;
  font-weight: 600;
}

.login input {
  flex: none;
  width: 100%;
}

.login input.hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
}
