:root {
  --bg: #faf6ef;
  --surface: #ffffff;
  --surface-2: #f3ece0;
  --text: #2b2620;
  --muted: #7a6f62;
  --line: #e7dece;
  --egg: #e8a33d;
  --egg-soft: #fbedd5;
  --egg-ink: #8a5a12;
  --gain: #2f7d5b;
  --gain-soft: #e1f1e8;
  --loss: #c2453b;
  --loss-soft: #fbe5e2;
  --rakuten: #bf0000;
  --yahoo: #ff0033;
  --amazon: #232f3e;
  --other: #6b6b6b;
  --focus: #2f6fb3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 16px rgba(60, 40, 10, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1814; --surface: #25211c; --surface-2: #2e2923; --text: #f1ebe2; --muted: #b0a596;
    --line: #3b352d; --egg: #f0b552; --egg-soft: #3c2f1a; --egg-ink: #f6cf8c;
    --gain: #6fcf9f; --gain-soft: #1f3a2d; --loss: #f08a80; --loss-soft: #43221f;
    --rakuten: #ff6b6b; --yahoo: #ff6b88; --amazon: #c8d1dc; --other: #b8b8b8; --focus: #7fb3ea;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1814; --surface: #25211c; --surface-2: #2e2923; --text: #f1ebe2; --muted: #b0a596;
  --line: #3b352d; --egg: #f0b552; --egg-soft: #3c2f1a; --egg-ink: #f6cf8c;
  --gain: #6fcf9f; --gain-soft: #1f3a2d; --loss: #f08a80; --loss-soft: #43221f;
  --rakuten: #ff6b6b; --yahoo: #ff6b88; --amazon: #c8d1dc; --other: #b8b8b8; --focus: #7fb3ea;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }

/* ---- layout ---- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; font-size: 20px; padding: 4px 10px 18px; }
.egg { width: 22px; height: 28px; fill: var(--egg); }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-list a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-weight: 600;
}
.nav-list a:hover { background: var(--surface-2); color: var(--text); }
.nav-list a[aria-current="page"] { background: var(--egg-soft); color: var(--egg-ink); }
.nav-list .ic { width: 16px; text-align: center; font-size: 12px; }
.nav-soon-title { margin: 14px 12px 4px; font-size: 12px; color: var(--muted); }
.nav-soon a { font-weight: 500; font-size: 14px; }
.nav-soon em { margin-left: auto; font-style: normal; font-size: 10px; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); }

.view { padding: 28px 32px 60px; max-width: 1040px; width: 100%; outline: none; }
.page-title { font-size: 22px; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 22px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; z-index: 10;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .nav-soon-title, .nav-soon { display: none; }
  .nav-list { grid-template-columns: repeat(5, 1fr); }
  .nav-list a { flex-direction: column; gap: 0; padding: 6px 4px; font-size: 12px; }
  .view { padding: 20px 16px 96px; }
}

/* ---- cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 760px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 16px; }
.stack > *, .grid > *, .results > * { min-width: 0; }

/* ---- home hero ---- */
.hero {
  display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center;
  background: var(--egg-soft); border-color: transparent;
}
.hero-egg { width: 96px; height: 120px; }
.hero-egg .shell-path { fill: var(--surface); stroke: var(--egg); stroke-width: 2; }
.hero-egg .fill { fill: var(--egg); }
.hero-label { color: var(--egg-ink); font-weight: 700; margin: 0; }
.hero-total { font-size: 48px; font-weight: 800; line-height: 1.1; margin: 4px 0 10px; letter-spacing: -.01em; }
.hero-total small { font-size: 20px; font-weight: 700; margin-left: 4px; }
.goal-bar { height: 10px; border-radius: 99px; background: var(--surface); overflow: hidden; }
.goal-bar span { display: block; height: 100%; background: var(--egg); border-radius: 99px; transition: width .8s ease; }
.goal-text { font-size: 13px; color: var(--egg-ink); margin-top: 6px; }
@media (max-width: 520px) { .hero { grid-template-columns: 1fr; text-align: center; } .hero-egg { margin: 0 auto; } .hero-total { font-size: 40px; } }

.stat-label { font-size: 13px; color: var(--muted); margin: 0; }
.stat-value { font-size: 26px; font-weight: 800; margin: 2px 0 0; }
.stat-note { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.pos { color: var(--gain); }
.neg { color: var(--loss); }

.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; align-items: end; height: 150px; }
.bar { display: grid; grid-template-rows: auto 1fr auto; height: 100%; text-align: center; font-size: 12px; color: var(--muted); }
.bar-track { display: flex; align-items: end; justify-content: center; }
.bar-fill { width: 70%; max-width: 40px; background: var(--egg); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-val { font-weight: 700; color: var(--text); }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.small { font-size: 12px; color: var(--muted); }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.m-rakuten { color: var(--rakuten); } .m-yahoo { color: var(--yahoo); } .m-amazon { color: var(--amazon); } .m-other { color: var(--other); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag-sample { background: var(--egg-soft); color: var(--egg-ink); }
.tag-warn { background: var(--loss-soft); color: var(--loss); }
.tag-good { background: var(--gain-soft); color: var(--gain); font-weight: 700; }

/* ---- shop memo ---- */
.shop-line { display: flex; gap: 6px; align-items: center; min-width: 0; }
.result.is-ng { opacity: .6; }
.result.is-ng:focus-within, .result.is-ng:hover { opacity: 1; }
details.shopmemo { margin-top: 4px; font-size: 13px; }
details.shopmemo summary { cursor: pointer; color: var(--focus); width: fit-content; }
details.shopmemo[open] summary { margin-bottom: 8px; }
.memo-flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; cursor: pointer; }
label.check input { width: auto; margin-top: 4px; }
label.check .hint { display: block; }

/* ---- forms ---- */
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.btn {
  font: inherit; font-weight: 700; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--egg); border-color: var(--egg); color: #2b1d05; }
.btn-primary:hover { filter: brightness(1.05); background: var(--egg); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.searchbar { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.notice { font-size: 13px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.notice b { color: var(--text); }

/* ---- result cards ---- */
.results { display: grid; gap: 12px; }
.result { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; }
.thumb { width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); object-fit: cover; display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.result-name { font-weight: 600; margin: 4px 0 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.figures { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.figures b { color: var(--text); }
.gain-box { text-align: right; min-width: 110px; }
.gain-box .label { font-size: 12px; color: var(--muted); }
.gain-box .val { font-size: 22px; font-weight: 800; }
.gain-box .row { justify-content: flex-end; margin-top: 6px; }
@media (max-width: 620px) {
  .result { grid-template-columns: 48px 1fr; }
  .thumb { width: 48px; height: 48px; }
  .gain-box { grid-column: 1 / -1; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .gain-box .row { margin-top: 0; }
}

.calc-result { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.calc-result > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.calc-result .k { font-size: 12px; color: var(--muted); }
.calc-result .v { font-size: 18px; font-weight: 800; }
.calc-result .main { background: var(--gain-soft); }
.calc-result .main.bad { background: var(--loss-soft); }
@media (max-width: 620px) { .calc-result { grid-template-columns: repeat(2, 1fr); } }

details.calc summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.calc summary::-webkit-details-marker { display: none; }
details.calc summary::after { content: "＋"; color: var(--muted); }
details.calc[open] summary::after { content: "－"; }
details.calc[open] summary { margin-bottom: 14px; }

/* ---- records ---- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 5px 14px; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.rec { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; }
.rec select { width: auto; padding: 5px 8px; font-size: 13px; }
@media (max-width: 620px) { .rec { grid-template-columns: 1fr auto; } .rec .rec-fig { grid-column: 1 / -1; order: 3; } }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .egg { width: 40px; height: 50px; opacity: .5; margin-bottom: 6px; }

.soon { max-width: 640px; }
.soon ol { padding-left: 1.2em; }
.soon li { margin: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; font-size: 14px;
  transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 760px) { .toast { bottom: 84px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
