/* style.css — 共通の土台（変数・レイアウト・HUD・ドック・パネル・ボタン・トースト・モーダル）。
   各モジュールの見た目は tree.css / story.css / workshop.css / extras.css に書く。 */

:root {
  /* 色：夜の藍と琥珀 */
  --ink: #0b0d24;          /* いちばん暗い夜 */
  --indigo: #151a3d;       /* 藍 */
  --navy: #1f2858;         /* 群青（暗） */
  --gunjo: #2e3d7a;        /* 群青 */
  --panel: #08204f;        /* パネル地（frame.webp の中身の色） */
  --lilac: #b7a2ff;        /* ライラック */
  --lavender: #d8ccff;
  --amber: #ffbf5e;        /* 琥珀（ランタン） */
  --honey: #ffd98a;
  --gold: #fdc842;         /* 枠の金 */
  --gold-dark: #b8792a;
  --cream: #fff3dc;        /* クリーム */
  --pink: #ff9ccf;
  --teal: #5ad1c8;
  --text: #f4ecff;
  --muted: #a9a3d0;
  --good: #9ef0c8;
  --danger: #ff8a9a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);

  --font-dot: 'DotGothic16', 'M PLUS Rounded 1c', system-ui, sans-serif;     /* 見出し・数値 */
  --font-body: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', system-ui, sans-serif; /* 本文 */

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --hud-h: 56px;           /* HUD の高さ（上） */
  --dock-h: 76px;          /* ドックの高さ（下） */
  --panel-w: 400px;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--ink); color: var(--text);
  font-family: var(--font-body); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; touch-action: manipulation; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea { user-select: text; -webkit-user-select: text; }

.pix, canvas, img.icon { image-rendering: pixelated; image-rendering: crisp-edges; }
.pix { image-rendering: pixelated; }
.num, .dot { font-family: var(--font-dot); letter-spacing: .02em; font-variant-numeric: tabular-nums; }
/* DotGothic16 は等幅で「,」「.」も全角の半分の幅をとる → 後ろの空きを詰める（ui.setNum / numHtml が span で包む） */
.np { letter-spacing: -.3em; margin-left: -.04em; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.warn { color: var(--amber); }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------------ レイヤー */
#sky {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  display: block; z-index: 0; touch-action: none; cursor: none;
  image-rendering: pixelated;
}
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.layer { position: fixed; inset: 0; pointer-events: none; }
.layer > * { pointer-events: auto; }
#layer-panel { z-index: 20; }
#layer-tree { z-index: 30; }
#layer-story { z-index: 40; }
#layer-extras { z-index: 45; }
#layer-title { z-index: 50; }
#layer-modal { z-index: 60; }
#layer-toast { z-index: 70; }
#layer-panel > *, #layer-toast > * { pointer-events: none; }
#layer-panel > .panel.open { pointer-events: auto; }

/* 画面ごとの表示切替（main / ui が body のクラスを付ける） */
body:not(.in-game) #hud, body:not(.in-game) #dock { display: none; }
body.fs-open #dock { display: none; }
body.fs-open:not(.fs-keep-hud) #hud { display: none; }
body.fs-keep-hud #ui { z-index: 35; }               /* 星図の上に HUD を出す */
body.chrome-hidden #hud, body.chrome-hidden #dock { opacity: 0; pointer-events: none !important; }
body.chrome-hidden #hud *, body.chrome-hidden #dock * { pointer-events: none !important; }

/* ------------------------------------------------------------------ 枠（frame） */
/* frame.webp が無いときの近い見た目：藍の地に金の縁、角に飾り */
.frame {
  position: relative;
  background:
    radial-gradient(120% 80% at 20% 0%, rgba(90, 120, 220, .16), transparent 60%),
    linear-gradient(180deg, #0a2558, var(--panel) 60%, #061a44);
  border: 3px solid var(--gold);
  border-radius: 6px;
  box-shadow: 0 0 0 2px #10072a, inset 0 0 0 2px #10072a, inset 0 0 0 3px rgba(255, 217, 138, .25), var(--shadow);
}
.frame::before, .frame::after {
  content: ''; position: absolute; width: 10px; height: 10px; top: -7px;
  background: var(--honey); transform: rotate(45deg); box-shadow: 0 0 0 2px #10072a, 0 0 8px rgba(255, 191, 94, .7);
  pointer-events: none;
}
.frame::before { left: -7px; }
.frame::after { right: -7px; }
/* frame.webp が読めたとき（assets.js が <html> に .has-frame を付ける） */
.has-frame .frame {
  border: 14px solid transparent;
  border-radius: 0;
  background: none;
  border-image: url(../assets/img/ui/frame.webp) 20 fill / 40px round;
  image-rendering: pixelated;
  box-shadow: none;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, .5));
}
.has-frame .frame::before, .has-frame .frame::after { display: none; }
.frame-sm {
  background: rgba(11, 13, 36, .88);
  border: 2px solid rgba(255, 217, 138, .55);
  border-radius: 6px;
  box-shadow: 0 0 0 2px rgba(16, 7, 42, .9), 0 6px 16px rgba(0, 0, 0, .4);
}

/* ------------------------------------------------------------------ ボタン・タブ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px 16px;
  font-family: var(--font-dot); font-size: 15px; line-height: 1.2;
  color: var(--cream);
  background: linear-gradient(180deg, #34468c, var(--navy));
  border: 2px solid rgba(255, 217, 138, .7);
  border-radius: 6px;
  box-shadow: 0 0 0 2px #10072a, inset 0 2px 0 rgba(255, 255, 255, .14), inset 0 -3px 0 rgba(0, 0, 0, .25);
  cursor: pointer; transition: transform .08s, filter .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--lavender); outline-offset: 3px; }
.btn:disabled, .btn.disabled { filter: grayscale(.7) brightness(.7); cursor: default; transform: none; }
.btn-primary {
  color: #2a1606;
  background: linear-gradient(180deg, #ffe7a8, var(--amber) 55%, #e8952f);
  border-color: #fff3c4;
  box-shadow: 0 0 0 2px #3a1d06, inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -3px 0 rgba(150, 70, 0, .35), 0 0 14px rgba(255, 191, 94, .35);
}
.btn-ghost { background: transparent; border-color: rgba(183, 162, 255, .45); box-shadow: none; }
.btn-danger { background: linear-gradient(180deg, #8a3550, #5a1f36); border-color: var(--danger); }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn-icon { min-height: 0; padding: 4px; border-radius: 6px; }

.tabs { display: flex; gap: 4px; padding: 2px; border-bottom: 2px solid rgba(183, 162, 255, .25); margin-bottom: 10px; }
.tab {
  flex: 1 1 0; padding: 6px 8px; background: transparent; border: 0; border-radius: 6px 6px 0 0;
  font-family: var(--font-dot); color: var(--muted); cursor: pointer; position: relative;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--honey); background: rgba(255, 217, 138, .08); }
.tab.active::after { content: ''; position: absolute; left: 12%; right: 12%; bottom: -2px; height: 2px; background: var(--honey); box-shadow: 0 0 6px var(--amber); }

.card {
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(183, 162, 255, .22);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.card + .card { margin-top: 8px; }
.divider { height: 2px; margin: 10px 0; background: linear-gradient(90deg, transparent, rgba(255, 217, 138, .45), transparent); border: 0; }
.cost { font-family: var(--font-dot); color: var(--honey); white-space: nowrap; }
.cost.lack { color: var(--danger); }

/* スクロールバー */
* { scrollbar-width: thin; scrollbar-color: rgba(183, 162, 255, .45) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(183, 162, 255, .4); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px) 0 calc(var(--safe-left) + 12px);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  transition: opacity .3s;
}
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hud-right { justify-content: flex-end; }
.chip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 4px 12px 4px 6px;
  background: linear-gradient(180deg, rgba(21, 26, 61, .86), rgba(11, 13, 36, .86));
  border: 2px solid rgba(255, 217, 138, .45);
  border-radius: 8px;
  box-shadow: 0 0 0 2px rgba(16, 7, 42, .8), inset 0 1px 0 rgba(255, 255, 255, .08), 0 4px 12px rgba(0, 0, 0, .35);
  white-space: nowrap;
}
.chip { position: relative; }
.chip img.icon { width: 28px; height: 28px; flex: none; }
.chip-pops { position: absolute; left: 34px; top: 0; width: 0; height: 0; pointer-events: none; }
.chip-pop {
  position: absolute; left: 0; top: 30px; white-space: nowrap;
  font-family: var(--font-dot); font-size: 13px; line-height: 1; color: var(--honey);
  text-shadow: 0 0 6px rgba(255, 191, 94, .8), 0 1px 0 #10072a, 1px 0 0 #10072a, -1px 0 0 #10072a, 0 -1px 0 #10072a;
  animation: chipPop .95s cubic-bezier(.2, .8, .3, 1) forwards;
}
.chip-pop.big { font-size: 15px; color: #fff3c0; }
.hud-chip[data-cur="wishes"] .chip-pop { color: #ffe9a0; }
.hud-chip[data-cur="moon"] .chip-pop { color: #cfe4ff; text-shadow: 0 0 6px rgba(160, 200, 255, .8), 0 1px 0 #10072a; }
@keyframes chipPop {
  0% { transform: translate(0, 4px) scale(.6); opacity: 0; }
  18% { transform: translate(0, 10px) scale(1.12); opacity: 1; }
  40% { transform: translate(0, 12px) scale(1); opacity: 1; }
  100% { transform: translate(0, 24px) scale(.96); opacity: 0; }
}
.chip-val { display: inline-block; transform-origin: 30% 60%; }
.chip-val.tick { animation: valTick .26s ease-out; }
@keyframes valTick { 0% { transform: scale(1); } 35% { transform: scale(1.09); color: #fff8e0; text-shadow: 0 0 12px rgba(255, 217, 138, .9); } 100% { transform: scale(1); } }
.chip-text { display: flex; align-items: baseline; gap: 6px; }
.chip-val { font-size: 20px; color: var(--cream); text-shadow: 0 0 8px rgba(255, 217, 138, .35); min-width: 1.5em; }
.chip-sub { font-size: 12px; color: var(--amber); }
.chip-sub:empty { display: none; }
.hud-chip[data-cur="wishes"] .chip-val { color: #ffe9a0; }
.hud-chip[data-cur="moon"] .chip-val { color: #cfe4ff; }
.hud-chapter { padding-right: 12px; gap: 4px; }
.hud-moon { width: 32px; height: 32px; }
.hud-chapter-text { font-family: var(--font-dot); font-size: 14px; color: var(--lavender); }
.hud-goal { cursor: pointer; font: inherit; color: inherit; gap: 8px; padding-right: 10px; }
.hud-goal .goal-icon img { width: 24px; height: 24px; opacity: .85; }
.goal-main { display: flex; flex-direction: column; gap: 2px; width: 150px; }
.goal-row { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 11px; line-height: 1.1; color: var(--muted); }
.goal-pct { font-size: 12px; color: var(--honey); }
.goal-bar { height: 8px; background: #0a0b1e; border: 1px solid rgba(255, 217, 138, .35); border-radius: 2px; overflow: hidden; }
.goal-fill {
  height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, var(--lilac) 0 6px, #9c86f0 6px 8px);
  box-shadow: 0 0 8px rgba(183, 162, 255, .7);
  transition: width .4s;
}
.hud-goal.lantern .goal-fill { background: repeating-linear-gradient(90deg, var(--amber) 0 6px, #f0a040 6px 8px); box-shadow: 0 0 8px rgba(255, 191, 94, .8); }
.hud-goal { transition: border-color .3s, background .3s, filter .15s, transform .1s; }
.hud-goal:hover { filter: brightness(1.12); }
.hud-goal:active { transform: translateY(1px) scale(.98); }
.hud-goal.ready { border-color: var(--honey); animation: goalGlow 1.6s ease-in-out infinite; background: linear-gradient(180deg, rgba(58, 52, 120, .92), rgba(24, 22, 66, .92)); }
.hud-goal.ready .goal-icon img { opacity: 1; animation: goalIcon 1.6s ease-in-out infinite; }
.hud-goal.ready .goal-label { color: #fff3c0; font-family: var(--font-dot); font-size: 12px; }
.hud-goal.ready .goal-pct { font-size: 18px; line-height: .8; color: var(--honey); animation: goalArrow 1s ease-in-out infinite; }
.hud-goal.ready .goal-fill { background: linear-gradient(90deg, #b7a2ff, #e9dcff 50%, #b7a2ff); background-size: 200% 100%; animation: goalShine 1.8s linear infinite; }
.hud-goal.ready.lantern .goal-fill { background: linear-gradient(90deg, var(--amber), #fff3c0 50%, var(--amber)); background-size: 200% 100%; }
@keyframes goalIcon { 50% { transform: translateY(-2px) scale(1.08); filter: drop-shadow(0 0 4px rgba(255, 217, 138, .9)); } }
@keyframes goalArrow { 50% { transform: translateX(3px); } }
@keyframes goalShine { from { background-position: 200% 0; } to { background-position: 0 0; } }
/* ゴールのチップがボタンになっている間は、extras の呼びかけボタン（同じ行き先）を重ねて出さない */
body.goal-cta .ex-call { display: none !important; }
@keyframes goalGlow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(16, 7, 42, .8), 0 0 6px rgba(255, 217, 138, .3); }
  50% { box-shadow: 0 0 0 2px rgba(16, 7, 42, .8), 0 0 18px rgba(255, 217, 138, .85); }
}
.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { transform: scale(1); } 35% { transform: scale(1.12); filter: brightness(1.5); } 100% { transform: scale(1); } }

/* ------------------------------------------------------------------ ドック */
#dock {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 10px); transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px 8px;
  background: linear-gradient(180deg, rgba(21, 26, 61, .82), rgba(11, 13, 36, .9));
  border: 2px solid rgba(255, 217, 138, .5);
  border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(16, 7, 42, .85), 0 8px 24px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .08);
  pointer-events: auto;
  transition: opacity .3s;
}
.dock-btn {
  position: relative; width: 64px; height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  background: transparent; border: 0; border-radius: 8px; cursor: pointer; color: var(--muted);
  transition: background .15s, color .15s, transform .1s;
}
.dock-btn img.icon { width: 32px; height: 32px; transition: transform .22s cubic-bezier(.3, 1.6, .5, 1), filter .2s; position: relative; z-index: 1; }
.dock-btn::before {
  content: ''; position: absolute; left: 50%; top: 42%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 217, 138, .38), rgba(183, 162, 255, .12) 55%, transparent 70%);
  opacity: 0; transform: scale(.6); transition: opacity .2s, transform .25s; pointer-events: none;
}
.dock-btn:hover { background: rgba(183, 162, 255, .1); color: var(--text); }
.dock-btn:hover::before { opacity: 1; transform: scale(1); }
.dock-btn:hover img.icon { transform: translateY(-3px) scale(1.08); filter: drop-shadow(0 3px 0 rgba(16, 7, 42, .6)) brightness(1.1); }
.dock-btn:active { transform: translateY(1px) scale(.94); transition-duration: .05s; }
.dock-btn:active img.icon { transform: translateY(0) scale(.96); }
.dock-btn.press img.icon { animation: dockPress .34s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes dockPress { 0% { transform: scale(.86); } 55% { transform: translateY(-3px) scale(1.12); } 100% { transform: scale(1); } }
.dock-btn:focus-visible { outline: 2px solid var(--lavender); outline-offset: -2px; }
.dock-btn.active { background: rgba(255, 217, 138, .14); color: var(--honey); }
.dock-btn.active::before { opacity: .7; transform: scale(1); }
.dock-btn.active::after { content: ''; position: absolute; bottom: 2px; left: 30%; right: 30%; height: 2px; background: var(--honey); box-shadow: 0 0 6px var(--amber); }
.dock-label { font-family: var(--font-dot); font-size: 12px; line-height: 1.2; }
.dock-btn.appear { animation: dockAppear 1.1s ease-out; }
@keyframes dockAppear { 0% { transform: scale(.2); opacity: 0; } 40% { transform: scale(1.2); opacity: 1; filter: brightness(2); } 100% { transform: scale(1); } }
.badge {
  position: absolute; z-index: 2; top: 2px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px;
  font-family: var(--font-dot); font-size: 11px; line-height: 18px; text-align: center;
  color: #2a1606; background: var(--amber); border-radius: 9px;
  box-shadow: 0 0 0 2px #10072a, 0 0 8px rgba(255, 191, 94, .7);
}
.badge.dot { min-width: 10px; width: 10px; height: 10px; padding: 0; top: 6px; right: 14px; }

/* ------------------------------------------------------------------ パネル（右スライドイン／ボトムシート） */
.panel {
  position: absolute;
  top: calc(var(--safe-top) + var(--hud-h) + 12px);
  bottom: calc(var(--safe-bottom) + var(--dock-h) + 22px);
  right: calc(var(--safe-right) + 12px);
  width: min(var(--panel-w), calc(100vw - 24px));
  display: flex; flex-direction: column;
  transform: translateX(calc(100% + 40px)); opacity: 0;
  transition: transform .32s cubic-bezier(.2, .8, .2, 1), opacity .25s;
}
.panel.wide { --panel-w: 520px; }
.panel.open { transform: none; opacity: 1; }
.panel { transition: transform .38s cubic-bezier(.2, .9, .25, 1.04), opacity .25s; }
.panel:not(.open) { transition: transform .26s cubic-bezier(.5, 0, .9, .5), opacity .22s .04s; }
/* 開いた直後だけ、中身を少しずつ浮かび上がらせる（refreshPanel の描き直しでは動かない） */
.panel.opening .panel-head { animation: panelHead .42s cubic-bezier(.2, .8, .3, 1) both; }
.panel.opening .panel-body > * { animation: panelItem .4s cubic-bezier(.2, .8, .3, 1) both; }
.panel.opening .panel-body > :nth-child(2) { animation-delay: .04s; }
.panel.opening .panel-body > :nth-child(3) { animation-delay: .08s; }
.panel.opening .panel-body > :nth-child(4) { animation-delay: .12s; }
.panel.opening .panel-body > :nth-child(5) { animation-delay: .16s; }
.panel.opening .panel-body > :nth-child(n+6) { animation-delay: .2s; }
@keyframes panelHead { from { opacity: 0; transform: translateY(-6px); } }
@keyframes panelItem { from { opacity: 0; transform: translateY(10px); } }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px 14px; flex: none; position: relative; }
.panel-handle { display: none; }
.panel-icon img { width: 28px; height: 28px; display: block; }
.panel-icon:empty { display: none; }
.panel-title {
  flex: 1; margin: 0; font-family: var(--font-dot); font-weight: normal; font-size: 20px; color: var(--honey);
  text-shadow: 0 0 10px rgba(255, 191, 94, .45), 0 2px 0 #10072a;
}
.panel-close { background: transparent; border: 0; padding: 4px; cursor: pointer; border-radius: 6px; line-height: 0; }
.panel-close:hover { background: rgba(255, 255, 255, .08); }
.panel-close img { width: 28px; height: 28px; }
.panel-body { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 4px 14px 14px; overscroll-behavior: contain; user-select: text; }
.has-frame .panel-head { padding: 6px 14px 6px 18px; }
.has-frame .panel-body { padding: 2px 8px 8px; margin-bottom: 14px; }   /* 下の角飾りの下に文字が潜らないように */

/* ------------------------------------------------------------------ トースト */
#toasts {
  position: fixed; left: 50%; top: calc(var(--safe-top) + var(--hud-h) + 14px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; width: max-content; max-width: calc(100vw - 24px);
}
.toast {
  display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 10px;
  font-size: 14px; color: var(--cream);
  opacity: 0; transform: translateY(-12px) scale(.92); transition: opacity .25s, transform .35s cubic-bezier(.2, 1.4, .4, 1);
}
.toast img.icon { width: 20px; height: 20px; }
.toast.show { opacity: 1; transform: none; }
.toast.show img.icon { animation: toastIcon .5s cubic-bezier(.3, 1.6, .5, 1) .05s both; }
@keyframes toastIcon { from { transform: scale(.3) rotate(-20deg); } }
.toast.hide { opacity: 0; transform: translateY(-8px) scale(.97); transition: opacity .3s, transform .3s ease-in; }
.toast-good { border-color: var(--good); }
.toast-rare { border-color: var(--honey); box-shadow: 0 0 0 2px rgba(16, 7, 42, .9), 0 0 16px rgba(255, 191, 94, .6); }

/* ------------------------------------------------------------------ モーダル */
.modal-root { position: fixed; inset: 0; pointer-events: none; }
.modal-wrap {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(5, 6, 20, .6); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .2s; pointer-events: auto;
}
.modal-wrap.show { opacity: 1; }
.modal-card { width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: 18px 20px 16px; transform: scale(.94); transition: transform .2s; }
.modal-wrap.show .modal-card { transform: none; }
.has-frame .modal-card { padding: 14px 14px 10px; }
.modal-title { margin: 0 0 8px; font-family: var(--font-dot); font-weight: normal; font-size: 20px; color: var(--honey); text-align: center; text-shadow: 0 0 10px rgba(255, 191, 94, .45); }
.modal-text { margin: 0 0 14px; white-space: pre-line; text-align: center; }
.modal-body { margin-bottom: 14px; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal-buttons .btn { min-width: 110px; }

/* ------------------------------------------------------------------ 起動画面 */
#boot {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 120%, #2b2f6b, var(--ink) 70%);
  transition: opacity .5s;
}
#boot.done { opacity: 0; pointer-events: none; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.boot-text { font-family: var(--font-dot); color: var(--lavender); letter-spacing: .1em; animation: bootBlink 1.6s ease-in-out infinite; }
.boot-gauge { width: 200px; height: 6px; background: #0a0b1e; border: 1px solid rgba(255, 217, 138, .4); border-radius: 3px; overflow: hidden; }
#boot-bar { height: 100%; width: 0; background: var(--honey); box-shadow: 0 0 8px var(--amber); transition: width .2s; }
@keyframes bootBlink { 50% { opacity: .5; } }

/* ------------------------------------------------------------------ スタブ用の最小タイトル（extras.css で上書きされる想定） */
.title-stub {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: var(--ink) center / cover no-repeat; image-rendering: pixelated;
}
.title-stub .title-logo { font-family: var(--font-dot); font-size: clamp(28px, 6vw, 56px); color: var(--cream); text-shadow: 0 0 18px rgba(255, 191, 94, .8), 0 3px 0 #10072a; margin: 0; }

/* ------------------------------------------------------------------ ゲーム開始時に HUD とドックがすべりこむ */
body.chrome-intro #hud { animation: hudIn .9s cubic-bezier(.2, .8, .25, 1) .35s both; }
body.chrome-intro #dock { animation: dockIn .9s cubic-bezier(.2, .8, .25, 1) .55s both; }
@keyframes hudIn { from { opacity: 0; transform: translateY(-18px); } }
@keyframes dockIn { from { opacity: 0; translate: 0 26px; } }

/* ------------------------------------------------------------------ スマホ縦 */
@media (max-width: 600px), (orientation: portrait) and (max-width: 820px) {
  :root { --hud-h: 92px; --dock-h: 64px; }
  html, body { font-size: 14px; }
  #hud { flex-direction: column; align-items: stretch; gap: 6px; padding-top: calc(var(--safe-top) + 8px); padding-left: calc(var(--safe-left) + 8px); padding-right: calc(var(--safe-right) + 8px); }
  .hud-left { gap: 6px; flex-wrap: nowrap; }
  .hud-right { justify-content: space-between; flex-wrap: nowrap; }
  .chip { height: 36px; padding: 3px 10px 3px 4px; }
  .chip img.icon { width: 24px; height: 24px; }
  .chip-val { font-size: 17px; }
  .chip-sub { font-size: 11px; }
  .hud-chip[data-cur="shards"] { flex: 1 1 auto; min-width: 0; }
  .hud-goal { flex: 1 1 auto; }
  .goal-main { width: auto; flex: 1 1 auto; }
  #dock {
    left: 0; right: 0; transform: none; bottom: 0; border-radius: 14px 14px 0 0; border-bottom: 0;
    padding: 4px calc(var(--safe-right) + 4px) calc(var(--safe-bottom) + 4px) calc(var(--safe-left) + 4px);
    justify-content: space-around; gap: 0;
  }
  .dock-btn { width: auto; flex: 1 1 0; max-width: 72px; height: 54px; }
  .dock-btn img.icon { width: 28px; height: 28px; }
  .dock-label { font-size: 11px; }
  .panel, .panel.wide {
    top: auto; right: 0; left: 0; width: auto;
    bottom: calc(var(--safe-bottom) + var(--dock-h) + 2px);
    height: 62dvh; max-height: calc(100dvh - var(--hud-h) - var(--dock-h) - var(--safe-top) - var(--safe-bottom) - 12px);
    transform: translateY(calc(100% + var(--dock-h) + 40px)); opacity: 1;
    border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  }
  .panel.open { transform: none; }
  .panel-handle { display: block; position: absolute; top: 3px; left: 50%; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: rgba(255, 217, 138, .45); }
  .panel-head { padding-top: 12px; touch-action: none; }
  #toasts { top: calc(var(--safe-top) + var(--hud-h) + 8px); }
  /* 下の段（章・ゴール）に重ならないよう、「+N」はチップの中の右側でふわっと */
  .chip-pops { left: auto; right: 12px; top: 50%; }
  .chip-pop { left: auto; right: 0; top: -9px; animation-name: chipPopM; }
  .hud-chip[data-cur="wishes"] .chip-pops { right: 6px; top: 50%; }
  .hud-chip[data-cur="wishes"] .chip-pop { font-size: 12px; }
}
@keyframes chipPopM {
  0% { transform: translateY(8px) scale(.6); opacity: 0; }
  20% { transform: translateY(0) scale(1.1); opacity: 1; }
  45% { transform: translateY(-2px) scale(1); opacity: 1; }
  100% { transform: translateY(-10px); opacity: 0; }
}

/* 大きなデスクトップ（1920×1080 以上）：夜空は論理解像度で拡大されるので、HUD とドックも少し大きく */
@media (min-width: 1700px) and (min-height: 950px) {
  :root { --hud-h: 68px; --dock-h: 92px; }
  #hud, #dock { zoom: 1.2; }
}

/* 横長で背の低い画面（スマホ横） */
@media (max-height: 460px) and (orientation: landscape) {
  :root { --dock-h: 60px; }
  .dock-btn { height: 46px; width: 56px; }
  .dock-label { display: none; }
}

/* 動きを減らす */
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important;
}

/* ================================================================== 修正（QA） */
/* トースト：会話・確認・便箋・演出の上では、操作への返事以外は出さない（ui が待たせる。いま出ているものは隠す） */
body.toast-quiet #toasts .toast:not(.feedback) { opacity: 0 !important; transition: opacity .2s; }
@media (max-width: 600px), (orientation: portrait) and (max-width: 820px) {
  .toast { max-width: calc(100vw - 32px); }
  .toast > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  /* スマホ：チップの中のポップが「+N/秒」に重なるあいだは、/秒 の字を消しておく */
  .hud-chip .chip-sub { transition: opacity .25s; }
  .hud-chip.popping .chip-sub { opacity: 0; transition: opacity .12s; }
}

/* はじめの数回：星図のバッジだけを目立たせる（つぎに押すところ） */
.badge.primary {
  min-width: 20px; height: 20px; line-height: 20px; font-size: 12px;
  background: #ffe9a0; box-shadow: 0 0 0 2px #10072a, 0 0 12px rgba(255, 217, 138, .95);
  animation: badgeBeckon 1.4s ease-in-out infinite;
}
@keyframes badgeBeckon { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-3px) scale(1.12); } }
.dock-btn.beckon .dock-icon { filter: drop-shadow(0 0 6px rgba(255, 217, 138, .8)); }
.reduce-motion .badge.primary { animation: none; }

/* 二重タブ：このタブは保存を止めている */
#tab-lock {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(5, 6, 22, .82); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.tab-lock-card { width: min(420px, 100%); padding: 18px 20px 16px; }
.tab-lock-card .modal-text { white-space: pre-line; }
