/* 見た目。ライト/ダークどちらでも読めるように、色は変数にまとめています。 */
:root {
  --bg: #f6f1e7; --fg: #2a2118; --muted: #6d6152; --card: #ffffff; --line: #ddd2bf;
  --accent: #d4472b; --accent-fg: #ffffff; --good: #2e7d32; --bad: #c62828;
  --hud: rgba(255, 252, 245, .88); --shadow: 0 4px 16px rgba(0, 0, 0, .18); --warn: #b26a00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1713; --fg: #f2e9da; --muted: #b3a690; --card: #2a241d; --line: #4a4033;
    --accent: #ef6a4c; --accent-fg: #1b1713; --good: #6fcf76; --bad: #ff8a80;
    --hud: rgba(34, 29, 23, .88); --shadow: 0 4px 16px rgba(0, 0, 0, .5); --warn: #ffb74d;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif; }
body { overflow: hidden; overscroll-behavior: none; }
h1, h2, h3 { margin: .4em 0; line-height: 1.3; }
h2 { font-size: 1.1rem; } h3 { font-size: 1rem; margin-top: 1.1em; }
.muted { color: var(--muted); font-size: .85em; }
.loading { padding: 2rem; text-align: center; }

/* ボタンと入力欄 */
.btn { font: inherit; padding: .6em 1em; min-height: 44px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--fg); }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 700; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
input { font: inherit; width: 100%; padding: .55em .7em; min-height: 44px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
input[type=number] { width: 7em; }
.field { display: block; margin: .6em 0; font-size: .9rem; }
.field input { margin-top: .25em; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* 中央のカード(タイトル・結果・ゲームオーバー) */
.center-screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto; }
.center-screen.scroll { align-items: flex-start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.2rem;
  width: 100%; max-width: 460px; box-shadow: var(--shadow); }
.logo { text-align: center; color: var(--accent); }
.group { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: .5rem; }
.group .btn { width: 100%; }
#screen { height: 100dvh; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; margin: .8rem 0; }
.table th { text-align: left; font-weight: 500; color: var(--muted); }
.table th, .table td { padding: .4em .2em; border-bottom: 1px solid var(--line); }
.table td { text-align: right; }
.table .total th, .table .total td { font-weight: 700; font-size: 1.1em; color: var(--fg); }
.plus { color: var(--good); } .minus { color: var(--bad); }
.comments { padding-left: 1.2em; }

/* お店の画面: 3Dが画面いっぱい、HUDは上、ボタンは下 */
.game { position: relative; width: 100%; height: 100dvh; overflow: hidden; }
#stage { position: absolute; inset: 0; background: #2b2520; }
#stage canvas { display: block; width: 100%; height: 100%; }
.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; gap: .3rem .9rem;
  align-items: center; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--hud); font-size: .9rem; z-index: 5; }
.hud-name { font-weight: 700; flex: 1 1 100%; }
.hud-item small { color: var(--muted); margin-right: .3em; font-size: .75em; }
.hud .xp { color: var(--muted); font-size: .8em; margin-left: .3em; }
/* スマホ幅: HUD の項目を小さく詰めて、2段くらいに収める */
@media (max-width: 600px) {
  .hud { font-size: .75rem; gap: .1rem .5rem; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); }
  .hud-name { flex-basis: auto; margin-right: .3rem; }
  .hud-item small { margin-right: .15em; font-size: .85em; }
  .hud .xp { margin-left: .15em; }
}
.dock { position: absolute; bottom: 0; left: 0; right: 0; z-index: 5; padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom)); display: flex; flex-direction: column;
  align-items: center; gap: .5rem; pointer-events: none; }
.dock > * { pointer-events: auto; }
.dock-row { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.dock-btn { background: var(--hud); }
.nobori { font-size: 1.1rem; padding: .7em 1.6em; box-shadow: var(--shadow); }

/* パネル(画面の上に重ねる。スマホ幅では下からのシート) */
#panel { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { background: var(--card); color: var(--fg); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 85dvh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 1rem; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: .6rem 1rem 1.2rem; overflow-y: auto; }
@media (max-width: 600px) {
  #panel { align-items: flex-end; padding: 0; }
  .sheet { max-width: none; border-radius: 16px 16px 0 0; max-height: 80dvh; }
}
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap;
  padding: .6rem 0; border-bottom: 1px solid var(--line); }
.item.on { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.item > div:first-child { flex: 1 1 10rem; min-width: 0; overflow-wrap: anywhere; }
.btn-pair, .ctrl { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.tag { font-size: .7em; padding: .1em .5em; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.card-sub { border: 1px solid var(--line); border-radius: 12px; padding: .7rem; margin: .8rem 0; }
.locked { font-size: 1.2rem; text-align: center; padding: 1.5rem 0 .5rem; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font: inherit; padding: .4em .8em; min-height: 44px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); display: flex; flex-direction: column;
  align-items: center; line-height: 1.2; }
.chip small { color: var(--muted); font-size: .7em; }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chip.on small { color: inherit; }
.bowl { display: block; width: 100%; max-width: 320px; margin: .3rem auto; border-radius: 12px; background: var(--bg); }
.stats { text-align: center; }
.code { font-size: 1.2em; letter-spacing: .15em; }
.bar { height: 14px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }

/* お知らせ */
#toasts { position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%); z-index: 40; width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: .4rem; pointer-events: none; }
.toast { padding: .6em .9em; border-radius: 10px; background: var(--card); color: var(--fg);
  border-left: 5px solid var(--muted); box-shadow: var(--shadow); font-size: .9rem; }
.toast.good { border-left-color: var(--good); } .toast.bad { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { font-weight: 700; }

/* 操作の案内(下のボタン列の下) */
.dock-hint { margin: 0; padding: .15em .6em; border-radius: 8px; background: var(--hud); text-align: center; font-size: .75rem; }
.help-list { padding-left: 1.2em; }

/* 手書きパネル */
.draw-canvas { display: block; width: 100%; height: auto; max-width: 100%; touch-action: none;
  border: 2px solid var(--line); border-radius: 8px; background: var(--bg); cursor: crosshair; }
.tool-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .5rem; }
.tool-row > .muted { min-width: 3.5em; }
.swatch { width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--line); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); }
.swatch.square { border-radius: 8px; }
.swatch:hover, .swatch:focus-visible { border-color: var(--accent); }
.btn.small { min-height: 40px; padding: .4em .8em; font-size: .9rem; }

/* 在庫の警告(HUD・仕入れ・メニュー) */
.hud-alert { font: inherit; font-weight: 700; flex: 1 1 100%; text-align: left; cursor: pointer;
  padding: .25em .6em; border-radius: 8px; border: 1px solid var(--bad); background: var(--card); color: var(--bad); }
.tag.bad { color: var(--bad); border-color: var(--bad); }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.item.low { background: color-mix(in srgb, var(--bad) 8%, transparent); }
.stock-out { color: var(--bad); font-weight: 700; font-size: .85em; }
.stock-low { color: var(--warn); font-weight: 700; font-size: .85em; }
.details { margin: .4rem 0; }
.details summary { cursor: pointer; color: var(--muted); }

/* カジノ */
.casino-result { text-align: center; }
.reels { display: flex; justify-content: center; gap: .4rem; font-size: 2.2rem; margin: .3rem 0; }
.reels span { min-width: 1.6em; padding: .1em .2em; border-radius: 10px; border: 2px solid var(--line); background: var(--bg);
  animation: reel-in .35s ease-out both; }
.reels span:nth-child(2) { animation-delay: .12s; } .reels span:nth-child(3) { animation-delay: .24s; }
@keyframes reel-in { from { transform: translateY(-40%); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .reels span { animation: none; } }
.cards { font-size: 1.2em; letter-spacing: .05em; }
.field.bet input { width: 10em; }
.tag.good { color: var(--good); border-color: var(--good); }

/* はじめての案内(下のボタン列の上) */
.tutorial { max-width: min(92vw, 640px); padding: .5em .8em; border-radius: 12px; background: var(--card);
  border: 2px solid #f2b705; box-shadow: var(--shadow); display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; }
.tutorial-text { margin: 0; flex: 1 1 16rem; font-size: .9rem; }
.tutorial-btns { display: flex; gap: .4rem; }
/* 設定 */
.pref input[type=range] { width: 100%; min-height: 32px; padding: 0; }
.pref select { font: inherit; width: 100%; min-height: 44px; margin-top: .25em; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.pref-check { display: flex; align-items: center; gap: .5em; min-height: 44px; }
.pref-check input { width: 22px; height: 22px; min-height: 0; }
.pref-note { margin: -.3em 0 .4em; }

/* 記録(実績とグラフ)。グラフの色は役割ごとの変数(線と点だけに使い、文字は文字の色) */
.viz { --series-1: #2a78d6; --series-2: #eb6834; margin: .6rem 0 1rem; }
@media (prefers-color-scheme: dark) { .viz { --series-1: #3987e5; --series-2: #d95926; } }
.viz figcaption { font-weight: 700; font-size: .9rem; margin-bottom: .2rem; }
.viz-svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-grid { stroke: var(--line); stroke-width: 1; opacity: .6; }
.viz-zero { stroke: var(--muted); stroke-width: 1; }
.viz-tick { fill: var(--muted); font-size: 11px; }
.viz-label { fill: var(--fg); font-size: 11px; font-weight: 700; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-dot { stroke: var(--card); stroke-width: 2; }
.viz-hit { fill: transparent; }
.viz-pt:hover .viz-dot { r: 6; }
.viz-legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.viz-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: .35em; vertical-align: middle; }
.trophies { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .5rem; }
.trophy { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem; border: 1px solid var(--line); border-radius: 12px; opacity: .75; }
.trophy.on { opacity: 1; border-color: #d4af37; background: color-mix(in srgb, #d4af37 10%, transparent); }
.trophy-icon { font-size: 1.4rem; line-height: 1; }
.trophy .bar { height: 8px; margin: .3rem 0 .1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: .5rem .7rem; display: flex; flex-direction: column; }
.stat small { color: var(--muted); font-size: .75rem; }
.stat strong { font-size: 1.1rem; }

/* お店どうしの訪問 */
.visit-status { margin: 0; padding: .4em .8em; border-radius: 10px; background: var(--card); border: 2px solid #f2b705;
  box-shadow: var(--shadow); font-size: .9rem; max-width: min(92vw, 560px); }
.stamps { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0; }
.stamp { display: flex; align-items: center; gap: .3em; min-height: 44px; padding: 0 .7em; border: 1px solid var(--line);
  border-radius: 99px; cursor: pointer; }
.stamp input { width: 18px; height: 18px; min-height: 0; }
