:root {
  --accent: #24ADA6;        /* iOS AccentColor (teal) */
  --accent-dark: #1f988f;
  --bg: #F2F2F7;            /* systemGroupedBackground */
  --card: #FFFFFF;
  --text: #1c1c1e;
  --secondary: #8e8e93;
  --tertiary: #c7c7cc;
  --separator: #e5e5ea;
  --brown: #A2845E;        /* tap number badge */
  --red: #FF3B30;
  --green: #34C759;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }
.screen.app { max-width: 720px; margin: 0 auto; position: relative; padding-bottom: 100px; }

/* ===== ログイン ===== */
#auth-screen {
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  background: var(--card); border-radius: 20px; padding: 44px 32px;
  width: 100%; max-width: 360px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.08);
}
.auth-logo { font-size: 48px; margin-bottom: 8px; }
.auth-title { font-size: 26px; font-weight: 700; margin: 0 0 4px; }
.auth-lead { color: var(--secondary); margin: 0 0 28px; font-size: 14px; }
.btn-oauth {
  width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--separator);
  background: #fff; font-size: 15px; font-weight: 600; cursor: pointer; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-oauth:active { transform: scale(.99); }
.btn-oauth.apple { background: #000; color: #fff; border-color: #000; }
.oauth-ic { font-weight: 700; }
.btn-oauth.google .oauth-ic { color: #4285F4; }
.auth-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ===== ナビゲーション ===== */
.nav {
  position: sticky; top: 0; z-index: 20;
  background: rgba(242,242,247,.9); backdrop-filter: saturate(180%) blur(20px);
  padding-top: var(--safe-top);
}
.nav-row, .nav-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 0;
}
.nav-title-lg { font-size: 30px; font-weight: 800; margin: 4px 16px 10px; letter-spacing: -.5px; }
.nav-actions { display: flex; gap: 2px; }
.nav-back {
  display: flex; align-items: center; gap: 2px; background: none; border: none;
  color: var(--accent); font-size: 16px; cursor: pointer; padding: 6px 4px;
}
.ic-chevron { width: 22px; height: 22px; color: var(--accent); }

.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--accent);
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
}
.icon-btn:active { background: rgba(0,0,0,.05); }
.icon-btn.danger { color: var(--red); }
.ic { width: 24px; height: 24px; color: currentColor; }

/* ===== コンテンツ ===== */
.content { padding: 8px 16px 24px; }

/* ===== ホーム: メニューカードのグリッド ===== */
.shop-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.menu-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.08); cursor: pointer; text-align: left;
  border: none; padding: 0; font: inherit; color: inherit;
}
.menu-card:active { transform: scale(.98); }
.menu-card .thumb {
  background: #f2f2f7; padding: 6px;
}
.menu-card .thumb img {
  width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; display: block;
}
.menu-card .meta { padding: 10px 12px 14px; }
.menu-card .meta .name { font-size: 14px; font-weight: 700; margin: 0 0 2px; }
.menu-card .meta .sub { font-size: 11px; color: var(--secondary); margin: 0; }

/* ===== ビール一覧: リスト ===== */
.list-section { margin-bottom: 22px; }
.list-header {
  font-size: 13px; color: var(--secondary); font-weight: 500;
  margin: 4px 8px 8px; text-transform: none;
}
.list-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.beer-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--separator); cursor: pointer; position: relative;
}
.beer-row:last-child { border-bottom: none; }
.beer-row:active { background: #f7f7fa; }

.toggle-btn {
  background: none; border: none; cursor: pointer; padding: 0; flex-shrink: 0;
  width: 26px; height: 26px; display: grid; place-items: center;
}
.toggle-btn .circ { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.toggle-btn.remove .circ { background: var(--red); }
.toggle-btn.add .circ { background: var(--green); }
.toggle-btn .circ::before { content: ""; width: 12px; height: 2.5px; background: #fff; border-radius: 2px; }
.toggle-btn.add .circ::after { content: ""; position: absolute; width: 2.5px; height: 12px; background: #fff; border-radius: 2px; }

.tap-badge {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brown);
  color: #fff; font-weight: 700; font-size: 17px; display: grid; place-items: center; flex-shrink: 0;
}
.beer-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: #eee; }
.beer-info { flex: 1; min-width: 0; }
.beer-info .ja { font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.beer-info .en { font-size: 14px; color: var(--secondary); margin: 1px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.beer-meta { font-size: 12px; color: var(--secondary); flex-shrink: 0; text-align: right; }
.drag-handle { color: var(--tertiary); flex-shrink: 0; display: grid; place-items: center; cursor: grab; }
.drag-handle svg { width: 22px; height: 22px; }
.beer-row.dragging { opacity: .4; background: #eef6f5; }
.beer-row[draggable="true"] { cursor: grab; }

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: 24px; right: max(24px, calc(50% - 360px + 24px));
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgba(0,0,0,.25); z-index: 30;
}
.fab:active { transform: scale(.94); }
.ic-plus { width: 26px; height: 26px; color: #fff; }

/* ===== 空状態 ===== */
.empty-state { text-align: center; padding: 80px 24px; color: var(--secondary); }
.empty-ic { font-size: 48px; margin-bottom: 12px; }
.empty-title { font-size: 17px; font-weight: 600; color: var(--text); margin: 0 0 6px; }
.empty-sub { font-size: 14px; margin: 0; }

/* ===== シート（モーダル） ===== */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 600px) { .sheet-overlay { align-items: center; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px;
  border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto;
  animation: slideUp .25s ease;
}
@media (min-width: 600px) { .sheet { border-radius: 16px; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 5px; background: var(--tertiary); border-radius: 3px; margin: 8px auto 0; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--separator);
  position: sticky; top: 0; background: var(--bg); z-index: 2;
}
.sheet-head h3 { font-size: 16px; font-weight: 600; margin: 0; }
.sheet-btn { background: none; border: none; color: var(--accent); font-size: 16px; cursor: pointer; padding: 4px; }
.sheet-btn.strong { font-weight: 600; }
.sheet-btn.ghost { color: transparent; }
.sheet-body { padding: 16px; }

/* ===== フォーム ===== */
.field-group { display: flex; gap: 12px; }
.field { display: block; flex: 1; margin-bottom: 14px; }
.field.third { flex: 1; min-width: 0; }
.field > span { display: block; font-size: 12px; color: var(--secondary); margin-bottom: 5px; }
input, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--separator); border-radius: 10px;
  font-size: 16px; font-family: inherit; color: var(--text); background: #fff;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(36,173,166,.15); }
textarea { resize: vertical; }

/* ===== 設定リスト ===== */
.list-card.spaced { margin-top: 14px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; font-size: 16px; width: 100%;
  border-bottom: 1px solid var(--separator); background: none; border-left: none; border-right: none; border-top: none;
}
.set-row:last-child { border-bottom: none; }
.set-val { color: var(--secondary); }
.btn-row { cursor: pointer; font: inherit; justify-content: center; }
.btn-row.danger { color: var(--red); font-weight: 500; }
.app-version { text-align: center; color: var(--tertiary); font-size: 12px; margin-top: 24px; }

/* ===== プレビュー ===== */
.preview-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 70;
  display: flex; flex-direction: column;
}
.preview-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, var(--safe-top));
  border-bottom: 1px solid var(--separator); background: var(--card); flex-shrink: 0;
}
.preview-nav h3 { font-size: 16px; font-weight: 600; margin: 0; }
.preview-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.menu-sheet-wrap { max-width: 600px; margin: 0 auto; overflow: hidden; }

/* PC（広い画面）：プレビューとオプションを横並び */
@media (min-width: 880px) {
  .preview-layout { display: flex; align-items: flex-start; gap: 28px; max-width: 1080px; margin: 0 auto; }
  .menu-sheet-wrap { flex: 0 0 500px; margin: 0; }
  .preview-side { flex: 1; min-width: 280px; max-width: 460px; }
  .preview-side .preview-options { margin: 0 0 16px; max-width: none; }
}

/* --- メニューシート（A4・2カラム / 中身が収まるよう自動縮小） --- */
.menu-sheet {
  position: relative; background: #fff;
  width: 700px; height: 990px; /* 固定サイズで1回だけレイアウト。表示/印刷は transform で拡縮 */
  box-shadow: 0 4px 20px rgba(0,0,0,.12); border-radius: 4px; overflow: hidden;
  transform-origin: top left;
}
/* iOS PDFGenerator の実寸比率に合わせる（本文 beerName=15pt を 1em の基準に） */
.menu-inner {
  position: absolute; inset: 0; padding: 5%; color: #0d0901; /* iOS margin 30pt ≒ 5% */
  font-family: "Futura", "Trebuchet MS", "Hiragino Sans", sans-serif;
  font-size: 17px; /* JS が iOS scale1(15pt相当)から開始して収まるまで縮小 */
  display: flex; flex-direction: column;
}
.menu-title { text-align: center; font-weight: 700; font-size: 1.6em; letter-spacing: .5px; } /* 24pt */
.menu-note { font-family: "Hiragino Sans", sans-serif; font-size: .667em; color: #555; } /* 10pt */
.menu-rule { border: none; border-top: .04em solid #999; margin: 0 0 .53em; } /* 罫線下 8pt */
.menu-rule.bottom { margin: 0 0 .27em; }

.menu-rows { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.menu-row { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.menu-row:not(:last-child) { border-bottom: .05em solid #ccc; }
.menu-cell { padding: .53em .3em .53em 0; min-width: 0; overflow: hidden; } /* 上下 8pt */
.menu-cell.left { padding-right: .6em; }
.menu-cell.right { padding-left: .6em; border-left: .05em solid #ccc; }

.bc { display: flex; gap: .4em; }
.bc-tap {
  width: 1.467em; height: 1.467em; flex-shrink: 0; border-radius: 50%; /* 22pt */
  background: var(--brown); color: #fff; font-weight: 700;
  display: grid; place-items: center; font-size: .807em; margin-top: .1em;
}
.bc-body { min-width: 0; flex: 1; position: relative; }
.bc-icon { position: absolute; top: 0; right: 0; width: 24%; aspect-ratio: 1; object-fit: cover; border-radius: .3em; }
.bc.has-icon .bc-name, .bc.has-icon .bc-ja { padding-right: 27%; }
.bc-glass { height: 1.1em; width: auto; vertical-align: middle; }
.bc-name { font-weight: 700; font-size: 1em; line-height: 1.15; overflow-wrap: break-word; } /* 15pt */
.bc-ja { font-family: "Hiragino Sans", sans-serif; font-size: .733em; color: #333; margin-top: .33em; } /* 11pt, 行間5pt */
.bc-brewery { font-family: "Hiragino Sans", sans-serif; font-size: .667em; color: #555; margin-top: .33em; } /* 10pt */
.bc-badges { display: flex; flex-wrap: wrap; align-items: center; gap: .3em; margin-top: .33em; }
.abv-badge {
  background: #555; color: #fff; font-size: .667em;
  padding: .1em .35em; border-radius: .2em; font-family: "Hiragino Sans", sans-serif; white-space: nowrap;
}
.bc-style { font-family: "Hiragino Sans", sans-serif; font-size: .667em; color: #555; }
.bc-price { margin-top: .33em; font-weight: 700; font-size: .933em; display: flex; align-items: center; gap: .15em; flex-wrap: wrap; } /* 14pt */
.rs-circle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.8em; height: 1.8em; flex-shrink: 0; line-height: 1; box-sizing: border-box;
  border: .11em solid #262626; border-radius: 50%;
  font-size: .55em; font-weight: 700; color: #262626; margin-right: .2em;
}
.rs-circle > span { display: block; transform: translateY(.07em); } /* 文字を視覚的に中央へ */
.bc-price .yen { font-size: .67em; }
.bc-price .sep { width: .6em; }
.bc-desc { font-family: "Hiragino Sans", sans-serif; font-size: .8em; color: #0d0901; margin-top: .33em; line-height: 1.3; } /* 12pt・黒 */

.menu-foot-labels { display: flex; justify-content: space-between; font-family: "Hiragino Sans", sans-serif; font-size: .667em; color: #888; margin-top: .27em; }
.menu-footer { text-align: center; font-family: "Hiragino Sans", sans-serif; font-size: .8em; color: #888; margin-top: .27em; } /* 12pt */

/* --- オプション --- */
.preview-options { max-width: 560px; margin: 22px auto 0; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--separator); font-size: 15px; }
.opt-row:last-child { border-bottom: none; }
.opt-row > span { flex-shrink: 0; }
.opt-input { width: auto; max-width: 60%; text-align: right; border: none; background: none; color: var(--secondary); font-size: 15px; padding: 4px 0; }
.opt-input:focus { box-shadow: none; color: var(--text); }
select.opt-input { text-align: right; -webkit-appearance: none; }
.opt-color { width: 40px; height: 28px; padding: 0; border: 1px solid var(--separator); border-radius: 6px; background: none; }
.opt-range { width: 48%; max-width: 220px; accent-color: var(--accent); }
.menu-hspace { flex-shrink: 0; }
.menu-footer-zone { flex-shrink: 0; display: flex; flex-direction: column; }
.opt-addbtn { background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px 0; }

/* --- ステッカー --- */
.menu-sticker {
  position: absolute; transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  cursor: grab; touch-action: none; user-select: none; -webkit-user-drag: none;
}
.menu-sticker img { width: 100%; height: auto; display: block; pointer-events: none; }
.menu-sticker.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-sticker:active { cursor: grabbing; }
.sticker-hint { font-size: 12px; color: var(--secondary); text-align: center; margin: 8px 0 0; }
/* ステッカー追加シートはプレビュー(z70)より前面に出す */
#sticker-picker { z-index: 100; }
.sticker-presets { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.sticker-preset { background: #fff; border: 1px solid var(--separator); border-radius: 10px; padding: 8px; cursor: pointer; width: 90px; height: 90px; }
.sticker-preset img { width: 100%; height: 100%; object-fit: contain; }

/* ===== 印刷 ===== */
@media print {
  /* シート(700×990=A4比)を A4 全面にぴったり拡大。内側に5%の余白があるので端は切れない */
  @page { size: A4; margin: 0; }
  /* プレビュー以外を完全に非表示にして、メニューシートだけを印刷 */
  body > *:not(#preview-overlay) { display: none !important; }
  #preview-overlay { display: block !important; position: static !important; height: auto !important; background: #fff !important; }
  #preview-overlay .preview-nav,
  #preview-overlay .preview-options { display: none !important; }
  .preview-scroll { display: block !important; overflow: visible !important; padding: 0 !important; height: auto !important; }
  .menu-sheet-wrap { max-width: none !important; overflow: visible !important; height: auto !important; margin: 0 !important; }
  /* 700px → A4幅210mm（793.7px）に拡大 = scale(1.1339)。高さも 990→1122px=297mm でぴったり */
  .menu-sheet { transform: scale(1.1339) !important; transform-origin: top left; box-shadow: none !important; border-radius: 0 !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ===== 文字数カウンター ===== */
.char-count { display: block; text-align: right; font-size: 12px; color: var(--secondary); margin-top: 4px; }
.char-count.over { color: var(--red); font-weight: 600; }

/* ===== スタイル選択フィールド ===== */
.select-field {
  width: 100%; margin-top: 4px; padding: 11px 12px; border: 1px solid var(--separator);
  border-radius: 10px; font-size: 16px; background: #fff; color: var(--text);
  display: flex; align-items: center; justify-content: space-between; cursor: pointer; text-align: left;
}
.select-field .placeholder { color: var(--tertiary); }
.select-chevron { width: 18px; height: 18px; color: var(--secondary); flex-shrink: 0; }

#style-picker { z-index: 100; }
.style-add { display: flex; gap: 8px; margin-bottom: 8px; }
.style-add input { flex: 1; margin-top: 0; }
.style-list-header { font-size: 13px; color: var(--secondary); margin: 16px 4px 8px; }
.style-item {
  display: block; width: 100%; text-align: left; padding: 13px 16px;
  border: none; border-bottom: 1px solid var(--separator); background: #fff;
  font-size: 16px; cursor: pointer; color: var(--text);
}
.style-item:last-child { border-bottom: none; }
.style-item.selected { color: var(--accent); font-weight: 600; }
.style-item:active { background: #f3f4f6; }

/* ===== ビールアイコン選択 ===== */
.icon-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.icon-thumb {
  width: 60px; height: 60px; border-radius: 10px; overflow: hidden; flex-shrink: 0;
  background: #f0f0f3; display: grid; place-items: center; object-fit: cover;
}
.icon-thumb img { width: 100%; height: 100%; object-fit: cover; }
.icon-thumb.empty { color: var(--tertiary); }
.icon-thumb.empty svg { width: 28px; height: 28px; }
.btn-ghost.small { padding: 7px 14px; font-size: 14px; border-radius: 999px; }
.btn-text.small { font-size: 14px; }

/* アイコン履歴グリッド（ビール編集の上に出す） */
#icon-history-modal { z-index: 100; }
.icon-history-grid { display: grid; grid-template-columns: repeat(auto-fill, 72px); gap: 12px; }
.icon-history-item {
  width: 72px; height: 72px; border-radius: 10px; overflow: hidden;
  border: none; padding: 0; cursor: pointer; background: #eee;
}
.icon-history-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.icon-history-empty { color: var(--secondary); font-size: 14px; }

/* ===== 正方形クロップ ===== */
.crop-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.crop-sheet { width: 100%; max-width: 420px; }
.crop-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;
}
.crop-head h3 { color: #fff; font-size: 16px; font-weight: 600; margin: 0; }
.crop-head .sheet-btn { color: #fff; }
.crop-area {
  position: relative; width: 100%; aspect-ratio: 1; background: #000;
  overflow: hidden; border-radius: 8px; touch-action: none; cursor: grab; user-select: none;
}
.crop-area:active { cursor: grabbing; }
#crop-img { position: absolute; top: 0; left: 0; transform-origin: top left; -webkit-user-drag: none; pointer-events: none; }
.crop-zoom { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.crop-zoom input { flex: 1; accent-color: var(--accent); }
.crop-zoom-ic { color: #fff; font-size: 18px; width: 20px; text-align: center; }
.crop-hint { color: rgba(255,255,255,.7); font-size: 12px; text-align: center; margin: 10px 0 0; }

/* ===== トースト ===== */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.82); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 14px; z-index: 80; max-width: 80%; text-align: center;
}
