/* 色やサイズの基本設定（明るい画面） */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --sub: #6e6e73;
  --faint: #aeaeb2;
  --sep: rgba(60, 60, 67, 0.12);
  --fill: rgba(118, 118, 128, 0.12);
  --purine: #5e5ce6;
  --protein: #0fa5bf;
  --over: #ff3b30;
  --warn: #f08a00;
  --met: #28b14c;
  --accent: #5e5ce6;
  --accent-2: #8e5cf6;
  --bar-glass: rgba(249, 249, 251, 0.78);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
  --radius: 22px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

/* 暗い画面（スマホの設定に合わせて自動で切り替え） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --sub: #98989f;
    --faint: #636366;
    --sep: rgba(84, 84, 88, 0.55);
    --fill: rgba(118, 118, 128, 0.24);
    --purine: #7d7aff;
    --protein: #40c8e0;
    --over: #ff453a;
    --warn: #ff9f0a;
    --met: #30d158;
    --accent: #7d7aff;
    --accent-2: #a77bff;
    --bar-glass: rgba(22, 22, 24, 0.72);
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* 画面ごとの共通の余白 */
.view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  animation: fade-in 0.35s ease both;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.large-title { padding: 18px 4px 14px; }
.large-title h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.eyebrow {
  margin: 0 0 2px;
  color: var(--sub);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section-label {
  margin: 22px 4px 8px;
  color: var(--sub);
  font-size: 13px;
  font-weight: 600;
}

/* ---- 7日間：リング ---- */
.rings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.ring-card { padding: 16px 12px 16px; text-align: center; }
.ring-label { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
#ring-purine .ring-label { color: var(--purine); }
#ring-protein .ring-label { color: var(--protein); }

.ring { position: relative; width: min(128px, 100%); margin: 0 auto; aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-track { stroke: var(--fill); }
.ring-bar {
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 1, 0.36, 1), stroke 0.3s;
}
#ring-purine .ring-bar { stroke: var(--purine); }
#ring-protein .ring-bar { stroke: var(--protein); }
#ring-purine.is-over .ring-bar { stroke: var(--over); }
#ring-protein.is-met .ring-bar { stroke: var(--met); }

.ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.num, .pv-num, .bar-val, .stepper output {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.ring-value .num { font-size: 25px; font-weight: 300; line-height: 1.1; }
.ring-value .u { font-size: 11px; color: var(--sub); }

/* 余裕・セーフ・アウトなどのひとこと */
.ring-badge {
  display: inline-block;
  margin: 10px 0 0;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 14%, transparent);
}
.ring-badge[data-tone="good"] { --tone: var(--met); }
.ring-badge[data-tone="ok"] { --tone: var(--accent); }
.ring-badge[data-tone="warn"] { --tone: var(--warn); }
.ring-badge[data-tone="bad"] { --tone: var(--over); }

.ring-goal, .ring-week { margin: 0; font-size: 12px; color: var(--sub); }
.ring-goal { margin-top: 8px; }
.ring-week { margin-top: 2px; font-weight: 600; color: var(--text); }
.ring-week.is-over { color: var(--over); }
.ring-week.is-met { color: var(--met); }
#ring-purine.is-over .ring-goal { color: var(--over); font-weight: 600; }
#ring-protein.is-met .ring-goal { color: var(--met); font-weight: 600; }

/* ---- 7日間：棒グラフ ---- */
.chart-card { margin-top: 12px; padding: 14px 14px 10px; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
}
.segmented button {
  border: 0;
  border-radius: 8px;
  padding: 6px 0;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--sub);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.segmented button[aria-selected="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.chart {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  height: 200px;
  margin-top: 14px;
  padding-bottom: 38px;
}
.goal-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1.5px dashed var(--faint);
  pointer-events: none;
  transition: bottom 0.5s;
}
.goal-line span {
  position: absolute;
  right: 0;
  top: -18px;
  font-size: 11px;
  color: var(--sub);
}
.col {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  border: 0;
  padding: 0;
  background: transparent;
  height: 100%;
}
.bar {
  width: 70%;
  max-width: 30px;
  min-height: 3px;
  border-radius: 8px 8px 4px 4px;
  background: var(--metric, var(--purine));
  opacity: 0.85;
  transition: height 0.7s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s, background 0.3s;
}
.col.is-empty .bar { background: var(--fill); opacity: 1; }
.col.is-over .bar { background: var(--over); }
.col.is-met .bar { background: var(--met); }
.col.is-selected .bar { opacity: 1; box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--metric, var(--purine)); }
.col.is-selected.is-over .bar { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--over); }
.col.is-selected.is-met .bar { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--met); }
.bar-val { margin-bottom: 4px; font-size: 11px; color: var(--sub); }
.col-label {
  position: absolute;
  bottom: -38px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.3;
  color: var(--sub);
}
.col-label b { display: block; font-size: 13px; font-weight: 600; color: var(--text); }
.col.is-selected .col-label b { color: var(--accent); }

/* ---- 7日間：お酒 ---- */
.alc-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 14px 16px;
}
.alc-label { margin: 0; font-size: 13px; font-weight: 600; color: var(--sub); }
.alc-value { margin: 2px 0 0; display: flex; align-items: baseline; gap: 3px; }
.alc-value .num { font-size: 30px; font-weight: 300; line-height: 1.1; }
.alc-value .u { font-size: 13px; color: var(--sub); }
.alc-side { text-align: right; }
.alc-side .ring-badge { margin: 0; }
.alc-avg { margin: 6px 0 0; font-size: 12px; color: var(--sub); }

/* ---- 7日間：プリン体が多かった食品 ---- */
.top-card { margin-top: 12px; padding: 16px 16px 12px; }
.card-title { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.top-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.top-list li { counter-increment: rank; padding: 7px 0; }
.top-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.top-name { font-size: 15px; }
.top-name::before {
  content: counter(rank);
  display: inline-block;
  width: 1.4em;
  color: var(--purine);
  font-weight: 700;
}
.top-val { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.top-val small { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--sub); }
.top-bar { height: 6px; margin: 6px 0 0 1.4em; border-radius: 3px; background: var(--fill); overflow: hidden; }
.top-bar span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--purine);
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---- 7日間：選んだ日の一覧 ---- */
.day-card { margin-top: 12px; padding: 16px 16px 8px; }
.day-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.day-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.day-sum { margin: 0; font-size: 13px; color: var(--sub); }
.day-list { list-style: none; margin: 8px 0 0; padding: 0; }
.day-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-top: 0.5px solid var(--sep);
}
.day-list li:first-child { border-top: 0; }
.item-name { font-size: 15px; }
.item-amount { display: block; font-size: 12px; color: var(--sub); }
.item-vals { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.item-vals .p { display: block; color: var(--purine); font-weight: 600; }
.item-vals .t { display: block; color: var(--protein); }
.del {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--sub);
  font-size: 15px;
  line-height: 1;
}
.empty { margin: 10px 0 12px; color: var(--faint); font-size: 14px; }
.mark { color: var(--faint); font-size: 11px; margin-left: 2px; }
.link-btn {
  display: block;
  width: 100%;
  margin: 2px 0 6px;
  padding: 12px 0 6px;
  border: 0;
  border-top: 0.5px solid var(--sep);
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}

/* ---- セットを作る画面（下から出るシート） ---- */
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--card);
  color: var(--text);
  overflow: auto;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet[open] { animation: sheet-in 0.3s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes sheet-in {
  from { transform: translateY(40px); opacity: 0; }
}
.sheet form { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
/* 開いたときに見出しへ入力位置を置き、キーボードや枠線が出ないようにする */
.sheet-title { margin: 0 0 12px; font-size: 20px; font-weight: 700; }
.sheet-title:focus { outline: none; }
.sheet .chips { margin: 0 -16px; }
.text-input {
  width: 100%;
  margin-top: 10px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--fill);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.text-input:focus { outline: 2px solid var(--accent); }
.check-list { list-style: none; margin: 12px 0 0; padding: 0; }
.check-list li { border-top: 0.5px solid var(--sep); }
.check-list li:first-child { border-top: 0; }
.check-list label { display: flex; align-items: center; gap: 12px; padding: 12px 2px; font-size: 15px; }
.check-list input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.sheet-sub { margin: -6px 0 4px; font-size: 13px; color: var(--sub); }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 14px; }

/* ---- 写真で記録 ---- */
.photo-card { margin-top: 14px; padding: 14px 14px 14px; }
.photo-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}
.photo-title svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linejoin: round;
}
.photo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 12px;
  background: var(--fill);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  line-height: 1.3;
  transition: transform 0.1s;
}
.photo-btn:active { transform: scale(0.97); }
.photo-btn b {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13px;
}
.photo-text { resize: vertical; min-height: 4.5em; font-size: 14px; line-height: 1.5; }
.photo-list { list-style: none; margin: 10px 0 0; padding: 0; }
.photo-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 12px 0;
  border-top: 0.5px solid var(--sep);
  transition: opacity 0.2s;
}
.photo-item:first-child { border-top: 0; }
.photo-item.is-off { opacity: 0.45; }
.pi-check { width: 20px; height: 20px; margin-top: 8px; accent-color: var(--accent); }
.pi-body { min-width: 0; }
.pi-body select {
  max-width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 7px 10px;
  background: var(--fill);
  font-size: 15px;
}
.pi-food { width: 100%; font-weight: 600; }
.pi-amount { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.pi-amount .pi-unit { flex: 1; min-width: 0; }
.pi-amount span { color: var(--sub); }
.pi-vals { margin: 6px 2px 0; font-size: 12px; color: var(--sub); }
.photo-item.is-guess .pi-vals { color: var(--warn); }
.photo-sum { margin: 10px 2px 0; font-size: 13px; font-weight: 600; color: var(--text); }
.sheet-actions .primary { margin-top: 0; }
.secondary {
  border: 0;
  border-radius: 16px;
  padding: 16px;
  background: var(--fill);
  font-size: 17px;
  font-weight: 600;
}

/* ---- 追加 ---- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--sep);
  border-radius: 999px;
  padding: 8px 14px;
  background: var(--card);
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s, transform 0.1s;
}
.chip:active { transform: scale(0.96); }
.chip[aria-checked="true"] {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.form-card { margin-top: 14px; padding: 0 16px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  border-top: 0.5px solid var(--sep);
}
.row:first-child { border-top: 0; }
.row > span { flex: none; color: var(--text); }
.row select {
  flex: 1;
  min-width: 0;
  max-width: 72%;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right center;
  padding: 12px 20px 12px 0;
  text-align: right;
  text-align-last: right;
  color: var(--sub);
  font-size: 16px;
  text-overflow: ellipsis;
}
.row select:focus { outline: none; color: var(--accent); }

/* 手入力の欄 */
.row-input {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 12px 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  text-align: right;
}
.row-input:focus { outline: none; }
.row-input::placeholder { color: var(--faint); }
.row-num { display: flex; flex: 1; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.row-num input { width: 100%; }
.row-num em { flex: none; font-style: normal; font-size: 14px; color: var(--sub); }

.preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.pv {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.pv-label { display: block; font-size: 13px; font-weight: 600; }
.pv-purine .pv-label { color: var(--purine); }
.pv-protein .pv-label { color: var(--protein); }
.pv-num { font-size: 34px; font-weight: 300; }
.pv-u { margin-left: 3px; font-size: 13px; color: var(--sub); }
.pv-note { grid-column: 1 / -1; margin: 0 4px; min-height: 1em; font-size: 12px; color: var(--sub); }

.primary {
  display: block;
  width: 100%;
  margin-top: 16px;
  border: 0;
  border-radius: 16px;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.1s, opacity 0.2s;
}
.primary:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.4; }
.primary.is-pulse { animation: pulse 0.6s ease; }
@keyframes pulse {
  50% { transform: scale(1.03); }
}

/* ---- 設定 ---- */
.list-card { padding: 0 16px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  font-size: 18px;
  line-height: 1;
}
.stepper output { min-width: 3.2em; text-align: right; font-size: 17px; }
.stepper-u { width: 1.8em; font-size: 13px; color: var(--sub); }

.sources { padding: 6px 16px; }
.sources p {
  margin: 0;
  padding: 10px 0;
  border-top: 0.5px solid var(--sep);
  font-size: 12.5px;
  color: var(--sub);
}
.sources p:first-child { border-top: 0; }
.sources b { display: block; margin-bottom: 2px; color: var(--text); font-size: 13px; }
.sources a { color: var(--accent); text-decoration: none; white-space: nowrap; }

.danger {
  width: 100%;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--over);
}
.list-card + .list-card { margin-top: 22px; }
.set-row { padding: 10px 0; }
.set-info { flex: 1; min-width: 0; }
.set-name { display: block; font-size: 15px; }
.set-sum {
  display: block;
  overflow: hidden;
  font-size: 12px;
  color: var(--sub);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.set-chip { font-weight: 600; color: var(--accent); }
.footnote { margin: 14px 4px 0; font-size: 12px; color: var(--faint); }

/* ---- 下のタブ ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar-glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 600;
}
.tabbar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar .tab-add svg {
  width: 30px;
  height: 30px;
  padding: 5px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  stroke: #fff;
}

/* ---- お知らせ ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 14px;
  background: rgba(28, 28, 30, 0.88);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  color: #fff;
  font-size: 14px;
  transform: translateX(-50%);
  animation: toast-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast button {
  border: 0;
  background: transparent;
  color: #a5a3ff;
  font-weight: 600;
  white-space: nowrap;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
