:root {
  --bg: #f6f2ee;
  --card: #ffffff;
  --line: #e8e1db;
  --text: #1f1a19;
  --muted: #877d77;
  --accent: #7b1e2b;
  --accent-ink: #ffffff;
  --gold: #b08a2e;
  --chip: #efe8e2;
  --shadow: 0 1px 2px rgba(40, 20, 20, .06);
  --t-red: #8c1c2c; --t-white: #d6bf5e; --t-rose: #e3919f; --t-spark: #c7b36a;
  --t-champ: #b8963e; --t-sake: #5f87b0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141112; --card: #1e1a1b; --line: #2e2829; --text: #efe8e5; --muted: #9a8f8b;
    --accent: #d46b79; --accent-ink: #1a1012; --gold: #d9b45a; --chip: #2a2425;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141112; --card: #1e1a1b; --line: #2e2829; --text: #efe8e5; --muted: #9a8f8b;
  --accent: #d46b79; --accent-ink: #1a1012; --gold: #d9b45a; --chip: #2a2425;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { margin: 0; font-size: 19px; letter-spacing: .04em; font-weight: 700; }
.summary { margin: 2px 0 8px; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.edit-pill {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 3px 12px; font-size: 12.5px; color: var(--muted);
}
.edit-pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--chip); border-radius: 10px; padding: 3px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 0; border-radius: 8px; font-size: 13.5px; color: var(--muted);
}
.tabs button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.tools { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.tools[hidden] { display: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 3px 11px; font-size: 12.5px; color: var(--muted);
}
.chips button.on { border-color: var(--text); color: var(--text); font-weight: 600; }
#sort[hidden], .view-btn[hidden] { display: none; }
.view-btn {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  padding: 3px 8px; font-size: 12.5px; color: var(--muted);
}
#sort {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  padding: 3px 6px; font-size: 12.5px; color: var(--muted);
}

/* 一覧 */
.list { padding: 8px 12px 40px; }
.group { margin: 14px 4px 6px; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .05em; }
.row {
  display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center;
  background: var(--card); border-radius: 12px; padding: 6px 12px 6px 8px; margin-bottom: 5px;
  box-shadow: var(--shadow); border: 0; width: 100%; text-align: left;
}
.row.empty { opacity: .62; }
.thumb { width: 38px; height: 50px; object-fit: contain; display: block; }
.thumb-ph { width: 38px; height: 50px; display: grid; place-items: center; }
.r-main { min-width: 0; }
.r-name, .r-sub { display: block; }
.r-name { font-size: 14.5px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.r-sub { font-size: 12px; color: var(--muted); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.r-sub s { opacity: .8; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.r-side { text-align: right; font-variant-numeric: tabular-nums; }
.stock { font-size: 15px; font-weight: 700; }
.stock small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.stock.zero { color: var(--muted); font-weight: 500; font-size: 12px; }
.fav { color: var(--gold); font-size: 13px; line-height: 1; }
.tag-res { display: inline-block; font-size: 10.5px; padding: 0 6px; border-radius: 4px; background: var(--chip); color: var(--accent); margin-left: 4px; vertical-align: 1px; }
.empty-msg { text-align: center; color: var(--muted); padding: 40px 0; font-size: 13px; }

/* 飲んだ記録タブ */
.drink-row {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; background: var(--card); border-radius: 12px;
  padding: 10px 12px 10px 8px; margin-bottom: 6px; box-shadow: var(--shadow); width: 100%; border: 0; text-align: left;
}
.drink-row .thumb, .drink-row .thumb-ph { width: 30px; height: 44px; }
.d-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.d-name { font-size: 14px; font-weight: 600; line-height: 1.35; }
.d-comment { font-size: 13px; margin-top: 2px; white-space: pre-wrap; }
.stars { color: var(--gold); letter-spacing: 1px; font-size: 12px; }

/* 詳細シート */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet[hidden] { display: none; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  animation: up .22s ease-out; overscroll-behavior: contain;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) {
  .sheet-body { left: 50%; width: 560px; transform: translateX(-50%); bottom: 4dvh; border-radius: 18px; max-height: 88dvh; animation: none; }
  .list { max-width: 640px; margin: 0 auto; }
  .top > * { max-width: 616px; margin-left: auto; margin-right: auto; }
}
.grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.d-head { display: grid; grid-template-columns: 74px 1fr; gap: 14px; align-items: start; }
.d-img { width: 74px; height: 120px; object-fit: contain; }
.d-head .thumb-ph { width: 74px; height: 120px; }
.d-title { padding-right: 28px; font-size: 18px; font-weight: 700; line-height: 1.35; margin: 2px 0 4px; }
.d-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.reserved { margin-top: 6px; font-size: 12.5px; color: var(--accent); }
.close-x { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 22px; color: var(--muted); padding: 4px 8px; }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 14px 0 6px; }
.btn {
  border: 0; border-radius: 12px; padding: 11px 14px; font-weight: 700; font-size: 15px;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: .4; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.fav-btn.on { color: var(--gold); }

.sec { margin-top: 16px; }
.sec h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); letter-spacing: .06em; font-weight: 600; }
.box { background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 14px; }
.box + .box { margin-top: 6px; }
.text { white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; grid-template-columns: 4.5em 1fr; gap: 2px 8px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.buy-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.buy-price { font-weight: 700; white-space: nowrap; }
.buy-price s { font-weight: 400; color: var(--muted); font-size: 12px; margin-right: 4px; }
.buy-note { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: pre-wrap; }
.mini { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.link { color: var(--accent); word-break: break-all; font-size: 13px; }

/* インライン編集 */
[data-edit] { border-radius: 4px; }
body.editing [data-edit] { outline: 1px dashed var(--line); outline-offset: 2px; min-width: 2em; display: inline-block; }
body.editing [data-edit].block { display: block; }
body.editing [data-edit]:focus { outline: 2px solid var(--accent); background: var(--card); }
body.editing [data-edit]:empty::before { content: attr(data-ph); color: var(--muted); opacity: .7; }
.ph-only { display: none; }
body.editing .ph-only { display: block; }

/* 飲んだシート */
.form label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.form input, .form textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 10px; font-size: 16px;
}
.form textarea { min-height: 96px; resize: vertical; }
.rate { display: flex; gap: 4px; }
.rate button { border: 0; background: transparent; font-size: 28px; color: var(--line); padding: 0 2px; line-height: 1; }
.rate button.on { color: var(--gold); }
.warn { background: var(--chip); color: var(--accent); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 13.5px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast button { border: 0; background: transparent; color: var(--bg); font-weight: 700; text-decoration: underline; padding: 0; }

/* 詳しい表示 */
.row, .card, .drink-row { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.card { background: var(--card); border-radius: 14px; padding: 10px 12px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.card.empty { opacity: .7; }
.c-head { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: start; }
.c-img { width: 56px; height: 84px; object-fit: contain; display: block; }
.c-head .thumb-ph { width: 56px; height: 84px; }
.c-name { font-size: 15.5px; font-weight: 700; line-height: 1.35; }
.c-price { font-size: 13px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.c-price s { font-weight: 400; color: var(--muted); }
.c-text { margin: 8px 0 0; font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; }
.c-memo { color: var(--text); background: var(--chip); border-radius: 8px; padding: 6px 8px; }
.c-small { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.c-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
