:root {
  --bg: #f4f1ea;
  --paper: #fffcf7;
  --ink: #2a241f;
  --muted: #7a7168;
  --line: #e4dcd0;
  --accent: #5c6b4a;
  --accent-soft: #e7eddf;
  --kcal: #3d5a6c;
  --nav: #fffcf7;
  --shadow: 0 8px 24px rgba(42, 36, 31, 0.06);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --head-h: 32px;
  --gutter: 12px;
  --row-pad: 8px;
  --tabbar-h: calc(56px + var(--safe-b));
  --cols: minmax(6.75rem, 1fr) 4.4rem 2.65rem 2.65rem 2.65rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    "Yu Gothic UI", sans-serif;
  line-height: 1.2;
}

body {
  min-height: 100dvh;
}

.app {
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
  overflow: hidden;
}

.col-head {
  position: sticky;
  top: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: var(--cols);
  gap: 4px;
  align-items: end;
  min-height: var(--head-h);
  padding: 6px var(--row-pad) 4px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, white);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  user-select: none;
}

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

.feed {
  flex: 1;
  min-height: 0;
  padding: 2px var(--gutter) var(--tabbar-h);
  overflow: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.status {
  margin: 0;
  padding: 48px 8px 24px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.session-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px var(--gutter);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

.session-bar button:disabled,
.login button:disabled,
.confirm button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.session-bar[hidden],
.login[hidden],
.feed[hidden],
.confirm[hidden] {
  display: none !important;
}

.confirm {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px var(--gutter);
  background: rgba(42, 36, 31, 0.35);
}

.confirm-card {
  width: min(100%, 20rem);
  padding: 20px 16px 16px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.confirm-card p {
  margin: 0 0 16px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
}

.confirm-actions {
  display: flex;
  gap: 8px;
}

.confirm-actions button {
  flex: 1;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.confirm-actions button.ghost {
  background: var(--accent-soft);
  color: var(--ink);
}

.session-bar .fetched {
  flex: 1;
  min-width: 0;
}

.session-bar button,
.login button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  min-height: 36px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.session-bar button.ghost {
  background: transparent;
  color: var(--muted);
}

.login {
  flex: 1;
  min-height: 0;
  padding: 28px var(--gutter) var(--tabbar-h);
  overflow: auto;
}

.login h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login .lead,
.login .hint,
.login .error {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login .error {
  color: #8a3b2b;
}

.month,
.slot {
  margin: 0;
}

.day {
  margin: 0;
  scroll-margin-bottom: calc(var(--tabbar-h) + 12px);
}

.month > summary,
.day > summary,
.slot > summary {
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

.month > summary::-webkit-details-marker,
.day > summary::-webkit-details-marker,
.slot > summary::-webkit-details-marker {
  display: none;
}

.month > summary {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 4px 2px;
  margin: 6px 0 2px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 750;
}

.month.archive > summary {
  color: var(--muted);
  font-weight: 700;
}

.day > summary {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 4px;
  align-items: center;
  min-height: 34px;
  padding: 4px var(--row-pad);
  margin: 2px 0;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: visible;
  font-size: 13px;
  font-weight: 700;
}

.day-head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

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

.day-sum {
  min-width: 0;
  text-align: right;
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: visible;
}

.slot > summary {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 1px 0 1px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.month > summary:hover,
.day > summary:hover,
.slot > summary:hover {
  background: var(--accent-soft);
}

.chev {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--accent);
  font-size: 9px;
  transition: transform 0.16s ease;
}

details:not([open]) > summary .chev {
  transform: rotate(-90deg);
}

.day-body {
  padding: 0 0 4px;
}

.meal {
  display: grid;
  grid-template-columns: var(--cols);
  gap: 4px;
  align-items: start;
  min-height: 0;
  padding: 3px var(--row-pad);
  border-bottom: 1px solid var(--line);
}

.meal:last-child {
  border-bottom: 0;
}

.meal-name {
  min-width: 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: break-word;
  word-break: keep-all;
}

.meal-kcal,
.meal-p,
.meal-f,
.meal-c {
  text-align: right;
  font-size: 12px;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  padding-top: 1px;
}

.meal-kcal {
  color: var(--kcal);
}

.meal-p,
.meal-f,
.meal-c {
  color: var(--ink);
}

.unit {
  margin-left: 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  padding: 4px 4px calc(6px + var(--safe-b));
  background: var(--nav);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.tabbar button {
  border: 0;
  background: transparent;
  min-height: 44px;
  padding: 2px 8px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tabbar button.on {
  color: var(--accent);
}

.tabbar .ico {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
}

@media (min-width: 720px) {
  .app {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: var(--bg);
  }

  .tabbar {
    left: 50%;
    right: auto;
    width: 480px;
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chev {
    transition: none;
  }
}
