:root {
  color-scheme: dark;
  --accent: #ffc46b;
  --glass: rgba(12, 20, 36, 0.54);
  --line: rgba(255, 255, 255, 0.14);
  /* 設定で変えられる色（main.js が上書きする） */
  --primary-top: #ffc46b;
  --primary-bottom: #ff9a4d;
  --primary-text: #2a1806;
  --primary-shadow: rgba(255, 154, 77, 0.3);
  --ghost-bg: rgba(255, 255, 255, 0.14);
  --ghost-border: rgba(255, 255, 255, 0.18);
  --sheet-color: rgba(16, 26, 44, 0.95);
  --sheet-img: none;
  --sheet-dim: 0;
  --sheet-text: #fff;
  --sheet-fg: 255, 255, 255;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #16243a; color: #fff; }
body { font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
#app { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; }

/* 上の表示 */
.top, .hero { text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }
.top { display: flex; justify-content: space-between; align-items: flex-start; padding: calc(env(safe-area-inset-top) + 12px) 16px 0; gap: 12px; }
.today { font-size: 15px; font-weight: 600; }
.sub { display: block; font-size: 12px; opacity: 0.85; }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#wxLabel:empty { display: none; }
.moon { display: flex; align-items: center; gap: 8px; text-align: right; }
.moon canvas { width: 36px; height: 36px; flex: none; }
.moon-text span { display: block; }
#moonAge { font-size: 13px; font-weight: 600; }

.hero { position: relative; padding: 10px 20px 0; margin-bottom: auto; }
.hero-label { font-size: 13px; opacity: 0.9; }
.hero-value { font-size: 68px; font-weight: 700; line-height: 1.05; color: var(--accent); letter-spacing: -1px; text-shadow: 0 2px 16px rgba(0, 0, 0, 0.5); }
.hero-value small { font-size: 22px; font-weight: 600; margin-left: 4px; color: #fff; opacity: 0.9; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { font-size: 13px; padding: 5px 11px; border-radius: 999px; background: rgba(10, 18, 32, 0.4); backdrop-filter: blur(8px); border: 1px solid var(--line); }
.chip:empty { display: none; }
/* 体重の表示を畳む */
.fold { position: absolute; right: 14px; top: 12px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--ghost-border); background: var(--ghost-bg); color: #fff; font-size: 12px; cursor: pointer; text-shadow: none; }
body.fold-hero .hero-label, body.fold-hero .chips { display: none; }
body.fold-hero .hero { padding-top: 2px; }
body.fold-hero .hero-value { font-size: 34px; }
body.fold-hero .hero-value small { font-size: 15px; }
body.fold-hero .fold { top: 4px; }

/* グラフのパネル */
.glass { background: var(--glass); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25); }
.chart-card { position: relative; margin: 16px 12px 8px; padding: 10px 12px 10px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.card-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tool { min-height: 38px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--ghost-border); background: var(--ghost-bg); color: #fff; font-size: 13px; cursor: pointer; white-space: nowrap; }
.tool[aria-expanded="true"] { background: rgba(255, 255, 255, 0.26); }
/* グラフの上の縁（景色との境界）をつかんで、グラフの高さを変える */
.grip { position: absolute; left: 20%; right: 20%; top: -13px; height: 30px; z-index: 3; display: grid; place-items: center; cursor: ns-resize; touch-action: none; user-select: none; -webkit-user-select: none; }
.grip i { display: block; width: 52px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.75); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5); }
.grip:focus-visible i { outline: 2px solid var(--accent); outline-offset: 3px; }
.seg { display: inline-flex; background: rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 3px; }
.seg button { background: transparent; color: rgba(255, 255, 255, 0.78); border: 0; padding: 7px 11px; border-radius: 9px; font-size: 13px; min-height: 34px; cursor: pointer; }
.seg button.on { background: rgba(255, 255, 255, 0.24); color: #fff; font-weight: 600; }
.seg button:disabled { opacity: 0.35; cursor: default; }
.chart-wrap { position: relative; height: var(--chart-h, clamp(190px, 30vh, 280px)); }
.chart-wrap.is-empty canvas { visibility: hidden; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 0 16px; font-size: 14px; color: rgba(255, 255, 255, 0.85); }
.legend { margin-top: 4px; font-size: 12px; opacity: 0.9; text-align: right; }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c-p, #ff8fb3); margin-right: 4px; vertical-align: middle; }
.stats { display: flex; justify-content: space-around; gap: 6px; margin-top: 6px; font-size: 13px; }
.stats span { text-align: center; }
.stats b { display: block; font-size: 15px; }
.stats i { display: block; font-style: normal; font-size: 11px; opacity: 0.75; }

/* 食事（kcal） */
.bottom #btnMeal { flex: 0 0 36%; font-size: 15px; }
.seg.wrap { display: flex; width: 100%; margin: 10px 0 4px; }
.seg.wrap button { flex: 1; padding: 7px 2px; color: inherit; opacity: 0.8; white-space: nowrap; }
.seg.wrap button.on { background: rgba(var(--sheet-fg), 0.2); color: inherit; opacity: 1; }
.foods { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.food { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 6px 0 12px; border-radius: 999px; border: 1px solid var(--ghost-border); background: var(--ghost-bg); color: inherit; font-size: 14px; cursor: pointer; }
.food b { font-weight: 600; font-size: 12px; opacity: 0.75; }
.food .x { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: rgba(var(--sheet-fg), 0.14); font-size: 14px; }
.meal-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.meal-list li { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 12px; background: rgba(var(--sheet-fg), 0.08); font-size: 14px; }
.meal-list .slot { font-size: 12px; opacity: 0.75; min-width: 2.6em; }
.meal-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-list button { min-height: 36px; padding: 0 12px; font-size: 13px; }
#mealSummary { white-space: pre-line; }
.meal-total { font-size: 14px; font-weight: 700; opacity: 1; margin: 12px 0 2px; }
.regd { font-size: 12px; opacity: 0.7; white-space: nowrap; }
details.manual { border: 1px solid rgba(var(--sheet-fg), 0.16); border-radius: 14px; padding: 0 12px 8px; margin: 12px 0 4px; background: rgba(var(--sheet-fg), 0.04); }
details.manual > summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; font-size: 14px; font-weight: 600; }
.foodhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 16px 0 0; padding-top: 14px; border-top: 2px solid rgba(var(--sheet-fg), 0.28); font-size: 14px; font-weight: 700; }
#mealSummary { padding-bottom: 12px; border-bottom: 2px solid rgba(var(--sheet-fg), 0.28); }
#mealListHead { margin: 16px 0 0; padding-top: 12px; border-top: 2px solid rgba(var(--sheet-fg), 0.28); font-weight: 700; opacity: 1; }
#mealFolders > .folder-head:first-child { margin-top: 6px; padding-top: 0; border-top: 0; }
.foods .addhere { flex: 1 0 100%; min-height: 40px; font-size: 13px; border-style: dashed; }
.birthrow { display: flex; gap: 8px; margin-top: 4px; }
.birthrow input { flex: 1.4; min-width: 0; }
.birthrow select { flex: 1; min-width: 0; }
.addrow { flex: 1 0 100%; display: flex; gap: 8px; align-items: center; }
.addrow .addname { flex: 1; min-width: 0; }
.addrow .addkcal { width: 6.5em; flex: none; }
.addrow button { min-height: 44px; padding: 0 16px; flex: none; }
#modeSeg button::before { content: ''; display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 50%; vertical-align: middle; background: var(--c, transparent); }
#modeSeg [data-show="w"] { --c: var(--c-w, #4fc3ff); }
#modeSeg [data-show="b"] { --c: var(--c-b, #8be05a); }
#modeSeg [data-show="k"] { --c: var(--c-k, #ff9f43); }
#modeSeg [data-show="p"] { --c: var(--c-p, #ff8fb3); }
.foodhead button, .newfolder button { min-height: 40px; padding: 0 14px; font-size: 13px; }
.newfolder { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; }
.newfolder input { flex: 1; min-width: 0; }
.folder-head { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; padding-top: 12px; border-top: 1px solid rgba(var(--sheet-fg), 0.16); }
.folder-head .tg { flex: 1; display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px; border-radius: 12px; border: 1px solid rgba(var(--sheet-fg), 0.16); background: rgba(var(--sheet-fg), 0.06); color: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; }
.folder-head .tg i { font-style: normal; font-size: 11px; opacity: 0.7; }
.folder-head .tg em { font-style: normal; font-weight: 400; font-size: 12px; opacity: 0.7; }
.folder-head .danger { min-height: 40px; padding: 0 12px; font-size: 13px; }
.food.edit { padding: 0 6px 0 12px; cursor: default; }
.food.edit select { min-height: 32px; padding: 0 4px; font-size: 12px; max-width: 8em; }
.food.edit .del { min-height: 32px; padding: 0 10px; font-size: 12px; }
.folder-head input { flex: 1; min-width: 0; min-height: 44px; }
.folder-head button.sm { min-height: 40px; padding: 0 12px; font-size: 13px; }
.pend { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pend li { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 12px; background: rgba(120, 190, 255, 0.22); font-size: 14px; }
.pend .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pend button { min-height: 36px; padding: 0 12px; font-size: 13px; }
.meal-foot { position: sticky; bottom: -18px; z-index: 2; display: flex; align-items: center; gap: 8px; margin: 14px -18px -18px; padding: 10px 18px calc(10px + env(safe-area-inset-bottom, 0px)); background: rgba(12, 18, 30, 0.94); color: #fff; }
.meal-foot .ft { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; }
.meal-foot button { min-height: 46px; padding: 0 18px; }
.meal-foot #mealCommit { min-width: 6.5em; font-weight: 700; }
.meal-foot #mealCommit:disabled { opacity: 0.45; }

/* 下のボタンとメニュー */
button { font: inherit; }
.bottom { display: flex; gap: 10px; padding: 4px 12px calc(env(safe-area-inset-bottom) + 14px); } /* 左右の余白はグラフのパネルと同じ（幅をそろえる） */
.bottom button { min-height: 52px; white-space: nowrap; }
.bottom .primary { flex: 1; font-size: 17px; }
.menu-btn { flex: 0 0 46px; min-height: 38px !important; padding: 0 !important; font-size: 22px; line-height: 1; }
.menu-panel { position: absolute; right: 10px; top: 54px; z-index: 6; display: flex; flex-direction: column; gap: 6px; padding: 8px; width: 190px; border-radius: 18px; }
.menu-panel button { justify-content: flex-start; min-height: 48px; white-space: nowrap; }
#btnBack { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); z-index: 7; display: none; min-width: 120px; }
body.scenic #btnBack { display: inline-flex; }
body.scenic #app { visibility: hidden; opacity: 0; }
#app { transition: opacity 0.35s; }

.primary, .ghost, .danger, .filebtn { min-height: 46px; padding: 0 18px; border-radius: 14px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.primary { background: linear-gradient(180deg, var(--primary-top), var(--primary-bottom)); color: var(--primary-text); font-weight: 700; box-shadow: 0 6px 20px var(--primary-shadow); }
.ghost { background: var(--ghost-bg); color: #fff; border-color: var(--ghost-border); backdrop-filter: blur(8px); }
.danger { background: rgba(255, 90, 90, 0.2); color: #ffb3b3; border-color: rgba(255, 120, 120, 0.3); }
button:active { transform: scale(0.98); }
#btnBack:active { transform: translateX(-50%) scale(0.98); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ダイアログ（記録・履歴・設定）。背景は色か画像を選べる */
dialog.sheet {
  color: var(--sheet-text);
  background:
    linear-gradient(rgba(10, 16, 28, var(--sheet-dim)), rgba(10, 16, 28, var(--sheet-dim))),
    var(--sheet-img, none) center / cover no-repeat,
    var(--sheet-color);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  width: min(560px, 100%); max-height: 90vh; max-height: 90dvh; margin: auto auto 0; overflow: auto;
  transition: opacity 0.15s;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.sheet.peek { opacity: 0.06; }
dialog.sheet.peek::backdrop { background: transparent; }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
label { display: block; margin: 12px 0; font-size: 13px; opacity: 0.95; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
label.check input { width: 22px; height: 22px; min-height: 0; padding: 0; flex: none; margin: 0; } /* 通常の入力欄の高さ・余白が効いて、チェックが大きくずれていた */
input, select { width: 100%; margin-top: 6px; padding: 12px; font-size: 16px; color: inherit; background: rgba(var(--sheet-fg), 0.08); border: 1px solid rgba(var(--sheet-fg), 0.2); border-radius: 12px; min-height: 46px; }
select option { color: #111; background: #fff; }
fieldset { border: 1px solid rgba(var(--sheet-fg), 0.14); border-radius: 14px; margin: 14px 0; padding: 4px 12px 12px; }
/* 設定のカテゴリ（折りたたみ） */
details.cat { border: 1px solid rgba(var(--sheet-fg), 0.16); border-radius: 14px; margin: 10px 0; background: rgba(var(--sheet-fg), 0.04); }
details.cat > summary { list-style: none; cursor: pointer; min-height: 52px; padding: 0 14px; display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 600; user-select: none; -webkit-user-select: none; }
details.cat > summary::-webkit-details-marker { display: none; }
details.cat > summary::after { content: "▾"; opacity: 0.7; transition: transform 0.15s; }
details.cat[open] > summary::after { transform: rotate(180deg); }
details.cat > .cat-body { padding: 0 12px 12px; }
legend { font-size: 12px; padding: 0 6px; opacity: 0.8; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note { font-size: 12px; opacity: 0.8; margin: 6px 0; line-height: 1.5; }
.error { font-size: 13px; color: #ff9b9b; margin: 6px 0; min-height: 1em; }
dialog.sheet .ghost, dialog.sheet .filebtn { color: inherit; }
.stepper { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.stepper input { margin: 0; text-align: center; font-size: 24px; font-weight: 600; }
.stepper button { width: 52px; height: 52px; flex: none; border-radius: 14px; border: 1px solid var(--ghost-border); background: var(--ghost-bg); color: inherit; font-size: 24px; cursor: pointer; }
.filebtn { cursor: pointer; }
input[type="range"] { padding: 0; height: 32px; accent-color: var(--accent); }
output { font-weight: 600; margin-left: 6px; }
.sheet-head { position: sticky; top: -18px; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: -18px -18px 4px; padding: 14px 18px 8px; background: rgba(12, 18, 30, 0.9); color: #fff; }
.sheet-head h2 { margin: 0; }
.ghost.small { min-height: 38px; padding: 0 12px; font-size: 13px; touch-action: none; user-select: none; -webkit-user-select: none; color: #fff !important; }

/* 色の選択（見本の色をタップ。その他の色は右端） */
.colorfield { margin: 12px 0; }
.cf-label { display: block; font-size: 13px; opacity: 0.95; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(var(--sheet-fg), 0.35); padding: 0; cursor: pointer; }
.swatches button.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.colorfield input[type="color"] { width: 100%; height: 40px; padding: 3px; margin-top: 8px; cursor: pointer; }
#bgThumb, #sheetThumb { display: block; max-width: 100%; max-height: 150px; border-radius: 12px; margin-top: 10px; border: 1px solid var(--line); }
.builtin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.builtin-grid button { padding: 0; border: 2px solid rgba(var(--sheet-fg), 0.25); border-radius: 12px; overflow: hidden; background: none; cursor: pointer; aspect-ratio: 9 / 16; }
.builtin-grid button.on { border-color: var(--accent); outline: 2px solid var(--accent); }
.builtin-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.builtin-grid button.special { display: flex; align-items: flex-end; justify-content: center; padding: 8px 4px; color: #fff; font-size: 12px; font-weight: 700; line-height: 1.35; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75); }
.builtin-grid button.sp-auto { background: linear-gradient(180deg, #7fb4e8 0%, #e8a0b8 32%, #f0a050 62%, #1a2a4a 100%); }
.builtin-grid button.sp-scene { background: linear-gradient(180deg, #2a4a85 0%, #c86a58 50%, #1b3a2a 52%, #12251c 100%); }

.history { list-style: none; margin: 8px 0; padding: 0; }
.history li button { width: 100%; display: flex; justify-content: space-between; align-items: center; background: transparent; border: 0; border-bottom: 1px solid rgba(var(--sheet-fg), 0.1); color: inherit; padding: 14px 6px; font-size: 16px; text-align: left; cursor: pointer; min-height: 48px; }
.history .d { opacity: 0.85; }
.history .k { font-weight: 600; }
.history .df { font-size: 12px; opacity: 0.7; margin-left: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); transform: translate(-50%, 12px); background: rgba(12, 20, 34, 0.96); border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 品質「低」: ぼかしを外して半透明の色だけにする（GPU負荷を下げる） */
body.q-low .glass, body.q-low .chip, body.q-low .ghost, body.q-low dialog.sheet { backdrop-filter: none; -webkit-backdrop-filter: none; }
body.q-low .glass { background: var(--glass-low, rgba(12, 20, 36, 0.72)); }
body.q-low .chip { background: rgba(10, 18, 32, 0.7); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-height: 640px) { .hero-value { font-size: 52px; } .chart-wrap { height: var(--chart-h, 170px); } }
