/* マチカゴ スタイル（スマホ優先・ライト/ダーク対応） */

:root {
  --bg: #fbf8f4;
  --surface: #ffffff;
  --surface-2: #f4efe8;
  --text: #2b2420;
  --muted: #6f655d;
  --line: #e6ddd2;
  --accent: #e8590c;
  --accent-strong: #c44a08;
  --accent-soft: #fde8da;
  --on-accent: #ffffff;
  --good: #2b8a3e;
  --good-soft: #e3f4e6;
  --danger: #c92a2a;
  --warn-bg: #fff4d6;
  --warn-text: #7a5a00;
  --amazon: #b45309;
  --rakuten: #bf0000;
  --yahoo: #6b21a8;
  --other: #52525b;
  --shadow: 0 1px 2px rgba(43, 36, 32, .06), 0 4px 16px rgba(43, 36, 32, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --text: #f2ece6;
    --muted: #b3a89e;
    --line: #3b3430;
    --accent: #ff8a3d;
    --accent-strong: #ffa065;
    --accent-soft: #3d2516;
    --on-accent: #1b1004;
    --good: #69db7c;
    --good-soft: #1b3321;
    --danger: #ff6b6b;
    --warn-bg: #3a3014;
    --warn-text: #f5d77a;
    --amazon: #f59e0b;
    --rakuten: #ff6b6b;
    --yahoo: #c084fc;
    --other: #a1a1aa;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171412;
  --surface: #221e1b;
  --surface-2: #2c2723;
  --text: #f2ece6;
  --muted: #b3a89e;
  --line: #3b3430;
  --accent: #ff8a3d;
  --accent-strong: #ffa065;
  --accent-soft: #3d2516;
  --on-accent: #1b1004;
  --good: #69db7c;
  --good-soft: #1b3321;
  --danger: #ff6b6b;
  --warn-bg: #3a3014;
  --warn-text: #f5d77a;
  --amazon: #f59e0b;
  --rakuten: #ff6b6b;
  --yahoo: #c084fc;
  --other: #a1a1aa;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
/* display を指定した要素でも hidden 属性で必ず隠す */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-x: hidden;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent-strong); }
h1, h2, h3 { line-height: 1.4; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- ヘッダー・フッター ---- */
.pr-note {
  margin: 0; padding: 4px 16px; text-align: center;
  font-size: .75rem; color: var(--muted); background: var(--surface-2);
}
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand img { flex: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-name { font-size: 1.15rem; letter-spacing: .04em; }
.brand-tagline { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-link { font-size: .85rem; white-space: nowrap; }

.site-footer { margin-top: 48px; padding: 24px 0 96px; background: var(--surface-2); border-top: 1px solid var(--line); }
.footer-nav { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: .9rem; }

/* ---- タブ ---- */
.tabs {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  margin: 12px -16px 12px; padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
}
.tabs button {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 4px; border-radius: 999px; font: inherit; font-size: .92rem; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }

/* ---- ボタン・入力 ---- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-size: .9rem; line-height: 1.3; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .82rem; }
.btn.danger-text { color: var(--danger); }
.btn.ec { font-weight: 700; }
.btn.ec-amazon { color: var(--amazon); }
.btn.ec-rakuten { color: var(--rakuten); }
.btn.ec-yahoo { color: var(--yahoo); }
.btn.ec-open { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font-size: 1.5rem; line-height: 1; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

input, select, textarea {
  font: inherit; font-size: 16px; /* iOSで拡大されないように */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
.field input, .field select, .field textarea { color: var(--text); }
.req, .opt { font-size: .7rem; padding: 0 6px; border-radius: 4px; margin-left: 4px; align-self: flex-start; }
.req { background: var(--accent-soft); color: var(--accent-strong); }
.opt { background: var(--surface-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: .82rem; cursor: pointer; text-decoration: none;
}
.chip:hover { border-color: var(--accent); }

/* ---- パネル ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; box-shadow: var(--shadow); }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.tools h2 { font-size: 1rem; }

/* ---- セールのお知らせ ---- */
.sale-banner { display: grid; gap: 8px; margin-bottom: 12px; }
.sale-banner:empty { display: none; }
.banner-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--accent-soft); border-radius: var(--radius); color: var(--text);
  text-decoration: none; border: 0; width: 100%; font: inherit; text-align: left; cursor: pointer;
}
.banner-card.sub { background: var(--surface); border: 1px solid var(--line); }
.banner-days { flex: none; text-align: center; min-width: 64px; }
.banner-days strong { display: block; font-size: 1.5rem; color: var(--accent-strong); line-height: 1.1; }
.banner-days small { font-size: .72rem; color: var(--muted); }
.banner-text { min-width: 0; font-size: .88rem; line-height: 1.5; }
.banner-text b { display: block; font-size: .98rem; }

/* ---- 一覧 ---- */
.toolbar { display: grid; gap: 8px; margin: 12px 0; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; }
.filters select { padding: 6px 8px; }
.summary { font-size: .85rem; color: var(--muted); margin: 8px 0; }
.item-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.card.is-buytime { border-color: var(--good); box-shadow: 0 0 0 1px var(--good), var(--shadow); }
.card.is-bought { opacity: .72; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.store-amazon { color: var(--amazon); }
.badge.store-rakuten { color: var(--rakuten); }
.badge.store-yahoo { color: var(--yahoo); }
.badge.store-other { color: var(--other); }
.badge.buytime { background: var(--good); color: var(--bg); }
.badge.prio-1 { background: var(--accent-soft); color: var(--accent-strong); }
.badge.tentative { background: var(--warn-bg); color: var(--warn-text); }
.badge.ongoing { background: var(--accent); color: var(--on-accent); }
.badge.drop { background: var(--good-soft); color: var(--good); }
.auto-check { font-size: .78rem; margin: 6px 0 0; color: var(--good); }
.auto-check.muted { color: var(--muted); }
.card h3 { margin: 2px 0 6px; font-size: 1.02rem; overflow-wrap: anywhere; }
.price-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.eff { font-size: 1.3rem; font-weight: 800; }
.eff small { font-size: .75rem; font-weight: 400; color: var(--muted); margin-right: 4px; }
.price-detail { font-size: .8rem; color: var(--muted); }
.target { font-size: .85rem; }
.target.ok { color: var(--good); font-weight: 700; }
.memo { font-size: .85rem; color: var(--muted); margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.card-actions {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line);
}
.card-actions .spacer { flex: 1; }
.card-actions .check { font-size: .82rem; margin-right: 4px; }
.empty { text-align: center; padding: 32px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- 広告 ---- */
.ad-slot { display: block; margin: 20px 0; min-height: 120px; text-align: center; }
.ad-slot.ad-top { min-height: 110px; }
.ad-slot.ad-article { min-height: 280px; }
li.ad-slot { list-style: none; margin: 12px 0; }
.ad-label { display: block; font-size: .68rem; color: var(--muted); margin-bottom: 4px; }
.ad-placeholder {
  display: flex; align-items: center; justify-content: center; min-height: 100px;
  border: 2px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: .85rem;
}

/* ---- セールカレンダー ---- */
.sale-next { display: grid; gap: 8px; }
.sale-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.sale-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.sale-item.is-pointday { background: var(--surface-2); }
.sale-item .name { font-weight: 700; font-size: .92rem; }
.sale-item .when { font-size: .8rem; color: var(--muted); }
.sale-item .days { font-size: .8rem; font-weight: 700; color: var(--accent-strong); white-space: nowrap; text-align: right; }
.sale-item a { font-size: .78rem; }
.sticky-actions { position: sticky; bottom: 8px; background: var(--surface); padding: 8px 0 0; }

/* ---- 買い回り ---- */
.planner-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.planner-inputs label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.2; }
.stat span { font-size: .72rem; color: var(--muted); }
.next-hint { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-weight: 700; margin: 8px 0; }
.points-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 8px 0; }
.points-table th, .points-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.points-table td:last-child { text-align: right; white-space: nowrap; }
.points-table tr.total td { font-weight: 800; border-bottom: 0; }
.shop-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.shop-row { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.shop-row.ng { border-style: dashed; }
.shop-row header { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: .92rem; }
.shop-row ul { margin: 4px 0 0; padding-left: 1.2em; font-size: .82rem; color: var(--muted); }
.ok-mark { color: var(--good); }
.ng-mark { color: var(--danger); font-size: .8rem; }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 8px 12px; font-size: .85rem; }

/* ---- ダイアログ ---- */
dialog {
  width: min(560px, calc(100vw - 16px)); max-height: calc(100dvh - 16px);
  padding: 0; border: 0; border-radius: 16px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(20, 14, 10, .5); }
dialog form, .dialog-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 16px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 6px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.dialog-body { padding: 16px; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
.url-badge { font-size: .8rem; min-height: 1.2em; }
.url-lookup { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: -4px 0 12px; }
.url-lookup:not([hidden]) + .grid-2 { margin-top: 0; }
.url-badge .badge { margin-right: 6px; }
.eff-preview { margin: 0 0 12px; font-size: .9rem; }
.eff-preview:empty { display: none; }

.chart-box { position: relative; height: 220px; margin: 8px 0 16px; }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: .85rem; background: var(--surface-2); border-radius: 10px; text-align: center; padding: 12px; }
.record-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; background: var(--surface-2); padding: 12px; border-radius: 10px; }
.record-form .field { margin: 0; }
.record-form button { grid-column: 1 / -1; }
.history-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 12px; }
.history-table th, .history-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.history-table td.num { text-align: right; }
.breakdown { font-size: .9rem; margin: 0 0 12px; padding: 0; list-style: none; }
.breakdown li { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--line); padding: 4px 0; }

.share-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.share-grid [data-share="native"] { grid-column: 1 / -1; }
.share-url { overflow-wrap: anywhere; max-height: 4.5em; overflow: hidden; }

.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  appearance: none; border: 0; border-radius: 999px; padding: 14px 20px;
  background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 800;
  box-shadow: 0 6px 20px rgba(232, 89, 12, .4); cursor: pointer;
}
.fab:hover { background: var(--accent-strong); }
body.shared-mode .fab { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- 使い方・記事 ---- */
.guide { margin-top: 40px; }
.guide h2 { margin-top: 28px; }
.guide ol { padding-left: 1.4em; }
.guide li { margin-bottom: 6px; }
details { border-bottom: 1px solid var(--line); padding: 10px 0; }
summary { cursor: pointer; font-weight: 700; }
details p { margin: 8px 0 0; color: var(--muted); }
.article-links { padding-left: 1.2em; }

.shared-head { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.shared-head h1 { font-size: 1.3rem; margin: 0 0 4px; }

.article { margin: 24px auto; }
.article h1 { font-size: 1.5rem; margin: 8px 0 4px; }
.article h2 { font-size: 1.2rem; margin-top: 36px; padding-left: 10px; border-left: 4px solid var(--accent); }
.article h3 { font-size: 1.05rem; margin-top: 24px; }
.article p, .article li { line-height: 1.9; }
.article table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 12px 0; display: block; overflow-x: auto; }
.article th, .article td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.article th { background: var(--surface-2); }
.article .lead { font-size: 1.02rem; }
.article .note { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; font-size: .9rem; }
.article .cta { background: var(--accent-soft); border-radius: var(--radius); padding: 16px; margin: 28px 0; }
.article .cta p { margin: 0 0 8px; }
.breadcrumb { font-size: .8rem; color: var(--muted); margin-top: 16px; }
.breadcrumb a { color: var(--muted); }

@media (min-width: 600px) {
  .toolbar { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(4, auto); justify-content: start; }
  .share-grid { grid-template-columns: repeat(3, 1fr); }
  .header-link { font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---- 動線の見直し（2026-10） ---- */
.url-row { display: flex; gap: 8px; align-items: center; }
.url-row input { flex: 1; }
.dialog-body > label.field[for] { margin-bottom: 4px; }
.more-fields { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.more-fields > summary { font-size: .88rem; color: var(--accent-strong); font-weight: 700; margin-bottom: 10px; }
.empty { text-align: left; }
.empty h2 { text-align: center; margin-bottom: 12px; }
.empty .btn { display: flex; width: 100%; margin: 16px 0 8px; }
.empty > .small { text-align: center; }
.steps { margin: 0; padding-left: 1.4em; display: grid; gap: 10px; }
.steps b { display: block; }
.steps span { font-size: .85rem; color: var(--muted); }
body.is-empty .fab { display: none; }
.prompt { background: var(--accent-soft); border-radius: var(--radius); padding: 14px; margin: 8px 0 12px; }
.prompt p { margin: 0 0 10px; }
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary h2 { display: inline; font-size: 1rem; }
details.panel > summary::after { content: '＋'; float: right; color: var(--muted); }
details.panel[open] > summary::after { content: '－'; }
details.panel[open] > summary { margin-bottom: 8px; }
.more-actions { position: relative; }
.more-actions > summary { list-style: none; }
.more-actions > summary::-webkit-details-marker { display: none; }
.more-actions[open] .more-menu { display: flex; }
.more-menu { display: none; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

#url-badge { display: block; margin: 4px 0 8px; }

/* PCの画面左右の縦長広告（本文 760px の両側に固定。狭い画面では ads.ts が枠ごと外す） */
.side-ad { display: none; }
@media (min-width: 1128px) and (min-height: 760px) {
  .side-ad.ad-slot {
    display: block; position: fixed; top: 96px;
    width: 160px; min-height: 620px; margin: 0; text-align: left;
  }
  .side-ad.side-right { left: calc(50% + 380px + 24px); }
  .side-ad.side-left { right: calc(50% + 380px + 24px); }
  .side-ad .ad-placeholder { min-height: 600px; }
}
@media (min-width: 1408px) and (min-height: 760px) {
  .side-ad.ad-slot { width: 300px; }
}
/* 広い画面では「＋登録」ボタンを本文の列の右端に寄せ、右側の広告に重ねない */
@media (min-width: 1128px) {
  .fab { right: calc(50% - 380px + 16px); }
}
