/* 横向きタブレット前提: 上に赤い帯（店名・画面切替・通信状態）、下が各画面 */
:root {
  --bg: #f5f3f0;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --fg: #1f1a17;
  --muted: #6b6159;
  --line: #e2dcd5;
  --red: #d62b1f;
  --red-strong: #b8221a;
  --red-soft: #fde3df;
  --orange: #ee7a12;
  --orange-soft: #ffe8d2;
  --yellow: #ffc629;
  --yellow-soft: #fff4c6;
  --on-red: #ffffff;
  --on-yellow: #1f1a17;
  --shadow: 0 1px 2px rgba(60, 30, 10, 0.08), 0 2px 8px rgba(60, 30, 10, 0.06);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161311; --surface: #221d1a; --surface-2: #1c1816; --fg: #f6f1ec; --muted: #b0a59b; --line: #3b332e;
    --red-soft: #4a1d18; --orange-soft: #47290f; --yellow-soft: #43380f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161311; --surface: #221d1a; --surface-2: #1c1816; --fg: #f6f1ec; --muted: #b0a59b; --line: #3b332e;
  --red-soft: #4a1d18; --orange-soft: #47290f; --yellow-soft: #43380f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

#app { height: 100%; display: flex; flex-direction: column; }

/* ===== 上部の帯 ===== */
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--red); color: var(--on-red);
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  flex-wrap: wrap;
}
.brand { font-weight: 900; font-size: 22px; letter-spacing: 0.02em; white-space: nowrap; }
.brand b { color: var(--yellow); }
.nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--on-red); text-decoration: none; font-weight: 700; font-size: 20px;
  padding: 10px 18px; border-radius: 10px; white-space: nowrap;
}
.nav a[aria-current="page"] { background: var(--yellow); color: var(--on-yellow); }
.conn {
  font-weight: 700; font-size: 16px; padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  background: rgba(255, 255, 255, 0.18);
}
.conn.offline { background: var(--on-red); color: var(--red); }
.conn.demo { background: var(--orange); color: #fff; }

.banner {
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-weight: 700; font-size: 18px;
}
.banner.offline { background: var(--red-soft); color: var(--fg); border-bottom: 4px solid var(--red); }
.banner.info { background: var(--yellow-soft); }

main {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }

/* ===== 共通部品 ===== */
.btn {
  border: 0; border-radius: 12px; padding: 14px 20px; font-weight: 800; font-size: 20px;
  background: var(--surface); color: var(--fg); box-shadow: inset 0 0 0 2px var(--line);
  min-height: 56px;
}
.btn.primary { background: var(--red); color: var(--on-red); box-shadow: none; }
.btn.primary:active { background: var(--red-strong); }
.btn.accent { background: var(--yellow); color: var(--on-yellow); box-shadow: none; }
.btn.orange { background: var(--orange); color: #fff; box-shadow: none; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: 17px; }
.btn.danger { color: var(--red); box-shadow: inset 0 0 0 2px var(--red); background: var(--surface); }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); font-size: 22px; padding: 48px 16px; }
.subtabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.subtabs .btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); box-shadow: none; }
.count { display: inline-block; min-width: 1.6em; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--red); color: var(--on-red); font-size: 0.85em; text-align: center; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.chip.done { background: var(--yellow); color: var(--on-yellow); }
.chip.todo { box-shadow: inset 0 0 0 2px var(--line); color: var(--muted); }
.chip.changed { background: var(--red); color: var(--on-red); }

.dept-burger { --dept: var(--red); }
.dept-side { --dept: var(--orange); }
.dept-potato { --dept: var(--yellow); }

/* ===== ① 注文入力 ===== */
.order-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; }
.menu { padding-right: 4px; }
.menu-group + .menu-group { margin-top: 14px; }
.menu-head { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 800; margin: 0 0 8px; }
.menu-head::before { content: ""; width: 14px; height: 14px; border-radius: 4px; background: var(--dept); }
.menu-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.item-btn {
  position: relative; border: 0; border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow), inset 0 -5px 0 var(--dept);
  min-height: 96px; padding: 12px 12px 16px; font-size: 21px; font-weight: 800; line-height: 1.3; text-align: left;
}
.item-btn:active { transform: translateY(1px); background: var(--surface-2); }
.item-btn .badge {
  position: absolute; top: -8px; right: -6px; min-width: 40px; height: 40px; border-radius: 999px;
  background: var(--red); color: var(--on-red); font-size: 22px; display: grid; place-items: center; padding: 0 8px;
}

.ticket { display: flex; flex-direction: column; gap: 10px; min-height: 0; background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.edit-banner { background: var(--orange); color: #fff; border-radius: 10px; padding: 10px 12px; font-weight: 800; }
.box-row { display: flex; align-items: center; gap: 12px; }
.box-row label { font-weight: 800; font-size: 18px; }
.box-display {
  flex: 1; height: 64px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 3px var(--yellow);
  font-size: 44px; font-weight: 900; display: flex; align-items: center; justify-content: center;
}
.box-display.empty-box { color: var(--muted); font-size: 20px; font-weight: 700; }
.box-display.bad { box-shadow: inset 0 0 0 3px var(--red); }
.keypad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.keypad .btn { min-height: 50px; padding: 0; font-size: 24px; }
.warn-text { color: var(--red); font-weight: 800; }
.cart { flex: 1; min-height: 80px; border-top: 2px solid var(--line); padding-top: 6px; }
.cart-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.cart-row .name { font-weight: 700; font-size: 19px; overflow-wrap: anywhere; }
.cart-row .name small { display: block; color: var(--muted); font-size: 14px; font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper .btn { min-height: 46px; width: 46px; padding: 0; font-size: 24px; }
.stepper .q { min-width: 40px; text-align: center; font-size: 26px; font-weight: 900; }
.send-status { border-radius: 10px; padding: 10px 12px; font-weight: 700; font-size: 16px; line-height: 1.45; }
.send-status.unknown { background: var(--yellow-soft); box-shadow: inset 0 0 0 2px var(--yellow); }
.send-status.failed { background: var(--red-soft); box-shadow: inset 0 0 0 2px var(--red); }
.send-row { display: flex; gap: 8px; }
.send-row .send { flex: 1; min-height: 72px; font-size: 28px; }

.olist { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; align-content: start; }
.ocard { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.ocard-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.boxno { font-weight: 900; font-size: 40px; line-height: 1; }
.boxno small { font-size: 15px; font-weight: 800; color: var(--muted); margin-right: 4px; }
.ocard ul { margin: 0; padding: 0; list-style: none; font-size: 18px; }
.ocard li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.actions .btn { flex: 1; }

/* ===== ② キッチン ===== */
.dept-switch { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.dept-switch .btn { flex: 1; min-height: 64px; font-size: 24px; box-shadow: inset 0 0 0 3px var(--dept); min-width: 140px; }
.dept-switch .btn[aria-pressed="true"] { background: var(--dept); color: #fff; }
.dept-switch .dept-potato[aria-pressed="true"] { color: var(--on-yellow); }
.pick-dept { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; padding: 24px 0; }
.pick-dept .btn { min-height: 160px; font-size: 36px; background: var(--dept); color: #fff; box-shadow: none; }
.pick-dept .dept-potato { color: var(--on-yellow); }

.kgrid { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; align-content: start; }
.kcard {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow), inset 0 0 0 3px var(--line);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.kcard.warn { background: var(--yellow-soft); box-shadow: var(--shadow), inset 0 0 0 4px var(--yellow); }
.kcard.late { background: var(--red-soft); box-shadow: var(--shadow), inset 0 0 0 5px var(--red); }
.khead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kbox { font-size: 72px; font-weight: 900; line-height: 0.95; }
.kbox small { display: block; font-size: 15px; font-weight: 800; color: var(--muted); letter-spacing: 0.08em; }
.ktime { text-align: right; font-size: 30px; font-weight: 900; white-space: nowrap; }
.ktime small { display: block; font-size: 14px; font-weight: 700; color: var(--muted); }
.kitems { list-style: none; margin: 0; padding: 0; }
.kitems li { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 2px dashed var(--line); }
.kitems .name { font-size: 26px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.kitems .qty { font-size: 40px; font-weight: 900; color: var(--red); white-space: nowrap; }
.kcard .done-btn { min-height: 76px; font-size: 30px; margin-top: auto; }
.done-strip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 10px; border-top: 2px solid var(--line); margin-top: 10px; }
.done-strip .label { font-weight: 800; color: var(--muted); }

/* ===== ③ 受け渡し ===== */
.pickup { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; }
.pickup h2 { margin: 0 0 10px; font-size: 22px; display: flex; align-items: center; gap: 8px; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; align-content: start; }
.pcard { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.pcard.ready { background: var(--yellow); color: var(--on-yellow); box-shadow: var(--shadow), inset 0 0 0 4px var(--red); }
.pcard.ready .boxno small, .pcard.ready .muted { color: var(--on-yellow); opacity: 0.75; }
.pcard .ready-label { background: var(--red); color: var(--on-red); font-weight: 900; font-size: 20px; padding: 4px 12px; border-radius: 8px; }
.pcard.ready .chip.done { background: rgba(255, 255, 255, 0.7); }
.pcard ul { margin: 0; padding: 0; list-style: none; font-size: 17px; }
.pcard .hand-btn { min-height: 64px; font-size: 22px; }

/* ===== 設定 ===== */
.admin { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-content: start; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel h2 { margin: 0; font-size: 22px; }
.panel p { margin: 0; line-height: 1.6; }
.panel.wide { grid-column: 1 / -1; }
.ptable { width: 100%; border-collapse: collapse; font-size: 18px; }
.ptable td, .ptable th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.ptable th { font-size: 15px; color: var(--muted); }
.ptable tr.hidden-row td:first-child { color: var(--muted); text-decoration: line-through; }
.table-wrap { overflow-x: auto; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ===== ログイン ===== */
.login { max-width: 460px; width: 100%; margin: 32px auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.field input, .field select {
  font: inherit; font-size: 20px; padding: 12px; border-radius: 10px; border: 2px solid var(--line);
  background: var(--surface-2); color: var(--fg); min-height: 54px;
}

/* ===== 確認ダイアログ ===== */
.modal-back { position: fixed; inset: 0; background: rgba(20, 10, 5, 0.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 18px; padding: 22px; width: min(560px, 100%); max-height: 90%; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 26px; }
.modal p { margin: 0; font-size: 19px; line-height: 1.6; }
.modal .actions .btn { min-height: 64px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg .btn { flex: 1; box-shadow: inset 0 0 0 3px var(--dept, var(--line)); }
.seg .btn[aria-pressed="true"] { background: var(--dept, var(--fg)); color: #fff; }
.seg .dept-potato[aria-pressed="true"] { color: var(--on-yellow); }

/* ===== お知らせ ===== */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); top: calc(76px + env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(640px, calc(100% - 32px)); pointer-events: none; }
.toast { padding: 14px 18px; border-radius: 12px; font-weight: 800; font-size: 19px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); pointer-events: none; line-height: 1.45; }
.toast.ok { background: var(--fg); color: var(--bg); }
.toast.error { background: var(--red); color: var(--on-red); }

/* ===== セット・ウィング ===== */
.group-set { --dept: var(--red); }
.group-set .menu-head::before { background: linear-gradient(135deg, var(--red) 50%, var(--yellow) 50%); }
.group-set .item-btn { box-shadow: var(--shadow), inset 0 -5px 0 var(--red), inset 0 -10px 0 var(--yellow); padding-bottom: 20px; }
.item-btn .hint { display: block; margin-top: 4px; font-size: 14px; font-weight: 700; color: var(--muted); }
.wing-btn { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.wing-btn .badge { font-size: 18px; }
.cart-row .name small .total { color: var(--red); font-weight: 900; }
.cart-row.is-set .name small { color: var(--fg); }
.pieces-btn { min-height: 40px; padding: 2px 10px; font-size: 20px; font-weight: 900; margin-left: 4px; box-shadow: inset 0 0 0 2px var(--orange); color: var(--fg); }
.ocard li small.parts, .pcard li small.parts, .ptable small.parts { display: block; color: var(--muted); font-size: 14px; font-weight: 600; }
.kitems .name small { display: block; font-size: 18px; font-weight: 800; color: var(--muted); }
.parts-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.parts-pick .btn { box-shadow: inset 0 0 0 3px var(--dept, var(--line)); text-align: left; }
.parts-pick .btn small { display: block; font-size: 13px; font-weight: 700; opacity: 0.8; }
.parts-pick .btn[aria-pressed="true"] { background: var(--dept); color: #fff; }
.parts-pick .dept-potato[aria-pressed="true"] { color: var(--on-yellow); }

/* タップで開く4択（フリックと同じ並び） */
.pieces-cross { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 96px); gap: 10px; }
.pieces-opt { font-size: 52px; font-weight: 900; min-height: 0; background: var(--yellow); color: var(--on-yellow); box-shadow: none; }
.pieces-opt small { font-size: 22px; margin-left: 2px; }
.pieces-opt.current { box-shadow: inset 0 0 0 4px var(--red); }
.pieces-opt.pos-up { grid-area: 1 / 2; }
.pieces-opt.pos-left { grid-area: 2 / 1; }
.pieces-opt.pos-right { grid-area: 2 / 3; }
.pieces-opt.pos-down { grid-area: 3 / 2; }
.pieces-cancel { grid-area: 2 / 2; min-height: 0; font-size: 20px; }

/* 長押し・フリックの選択肢 */
#flick-root { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
.flick { position: fixed; width: 0; height: 0; }
.flick .petal, .flick .flick-center {
  position: absolute; width: 104px; height: 104px; margin: -52px 0 0 -52px; border-radius: 22px;
  display: grid; place-items: center; font-weight: 900; font-size: 48px;
  background: var(--surface); color: var(--fg); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), inset 0 0 0 3px var(--orange);
}
.flick .petal small { font-size: 20px; }
.flick .petal { display: flex; align-items: baseline; justify-content: center; padding-top: 22px; }
.flick .pos-up { transform: translateY(-112px); }
.flick .pos-down { transform: translateY(112px); }
.flick .pos-left { transform: translateX(-112px); }
.flick .pos-right { transform: translateX(112px); }
.flick .petal.on { background: var(--red); color: var(--on-red); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); }
.flick .pos-up.on { transform: translateY(-112px) scale(1.15); }
.flick .pos-down.on { transform: translateY(112px) scale(1.15); }
.flick .pos-left.on { transform: translateX(-112px) scale(1.15); }
.flick .pos-right.on { transform: translateX(112px) scale(1.15); }
.flick .flick-center { font-size: 18px; background: var(--surface-2); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), inset 0 0 0 3px var(--line); }
.flick .flick-center.on { box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), inset 0 0 0 3px var(--fg); }
.flick-banner {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--fg); color: var(--bg); border-radius: 16px; padding: 10px 24px; text-align: center;
  font-weight: 800; font-size: 20px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35); min-width: 280px;
}
.flick-banner b { display: block; font-size: 64px; line-height: 1.1; }
.flick-banner span { display: block; font-size: 16px; opacity: 0.8; }
.flick-banner.on { background: var(--red); color: var(--on-red); }

/* 狭い画面（スマホ・縦向き）では縦に並べる */
@media (max-width: 860px) {
  .order-grid, .pickup { grid-template-columns: minmax(0, 1fr); }
  main { overflow-y: auto; }
  .order-grid, .pickup { flex: none; }
  .kbox { font-size: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
