/* style.css — 寛永通寳を掘り出す：ダークで落ち着いた UI。
   全画面 canvas の上に、上部の判読表示・下部の道具・各種オーバーレイを重ねる。 */

:root {
  --bg: #111110;
  --ink: #ebe5d9;
  --ink-dim: rgba(235, 229, 217, 0.55);
  --ink-faint: rgba(235, 229, 217, 0.22);
  --brass: #c9a46a;
  --brass-dim: rgba(201, 164, 106, 0.35);
  --panel: rgba(22, 21, 19, 0.72);
  --panel-solid: #1a1917;
  --line: rgba(235, 229, 217, 0.10);
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", "Noto Serif JP", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Yu Gothic UI", "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --toolbar-h: 76px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
body { position: fixed; inset: 0; }

#app { position: fixed; inset: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.hidden { display: none !important; }

/* ---------- canvas ---------- */
#coin-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#coin-canvas.flip { animation: coin-flip 240ms ease-in-out; pointer-events: none; }
@keyframes coin-flip {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0); }
}

/* ---------- 上部：判読表示 ---------- */
.reading {
  position: absolute;
  top: calc(var(--safe-t) + 18px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.reading .slot {
  width: 42px;
  height: 46px;
  display: grid;
  place-items: center;
  font-family: var(--mincho);
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  color: var(--ink-faint);
}
.reading .slot.read {
  color: var(--ink);
  text-shadow: 0 0 14px rgba(201, 164, 106, 0.35);
  animation: slot-pop 0.5s ease-out;
}
.reading .slot.back { margin-left: 10px; position: relative; }
/* v9: 5 つ目が裏の字であることを小さく示す */
.reading .slot.back::after {
  content: attr(data-label);
  position: absolute;
  left: 0; right: 0; bottom: -11px;
  font-family: var(--sans, sans-serif);
  font-weight: 400;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-align: center;
}
@keyframes slot-pop {
  0% { transform: scale(1.25); color: var(--brass); }
  100% { transform: scale(1); }
}
.reading.done .slot.read { color: var(--brass); }

/* コインから判読表示へ飛ぶ文字 */
.fly {
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--mincho);
  font-weight: 700;
  line-height: 1;
  color: #f3e6c8;
  text-shadow: 0 0 18px rgba(240, 200, 130, 0.6);
  pointer-events: none;
  will-change: transform, opacity;
  z-index: 20;
}

/* ---------- 左上：自動モード ---------- */
.auto-btn, .flip-btn, .restart-btn {
  position: absolute;
  top: calc(var(--safe-t) + 18px);
  left: calc(var(--safe-l) + 12px);
  height: 32px;
  padding: 0 11px;
  border-radius: 16px;
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--ink-dim);
  background: rgba(22, 21, 19, 0.55);
  border: 1px solid var(--line);
  z-index: 15;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.flip-btn { top: calc(var(--safe-t) + 18px + 32px + 8px); }
.flip-btn:active { color: var(--brass); }
/* v12: ▶自動 の倍率メニュー（ボタンの右に出る） */
.auto-menu {
  position: absolute;
  top: calc(var(--safe-t) + 14px + 40px + 10px);   /* 上部中央の見せるの下、裏返すの右 */
  left: calc(var(--safe-l) + 12px + 78px);
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 14px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 16;
}
.auto-menu .auto-speed { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 56px; height: 44px; padding: 0 8px; border-radius: 10px; border: 1px solid var(--line); background: rgba(22, 21, 19, 0.6); color: var(--ink-dim); }
.auto-menu .auto-speed b { font-size: 14px; color: var(--brass); }
.auto-menu .auto-speed span { font-size: 10px; }
.auto-menu .auto-speed:active { background: rgba(201, 164, 106, 0.15); }
@media (max-width: 350px) { .auto-menu { left: calc(var(--safe-l) + 6px + 66px); } }
/* v12: 最初から（裏返すの下。裏返すが無ければその位置）。長押し中は縁が赤くなる */
.restart-btn { top: calc(var(--safe-t) + 18px + 32px + 8px + 32px + 8px); }
.flip-btn.hidden + .restart-btn { top: calc(var(--safe-t) + 18px + 32px + 8px); }
.restart-btn.holding { border-color: #b5473a; color: #d9736a; transition: border-color 1s linear, color 1s linear; }
.restart-btn:disabled { opacity: 0.35; cursor: default; }
.restart-btn:not(.hidden) ~ .benches { top: calc(var(--safe-t) + 18px + 32px + 8px + 32px + 8px + 32px + 10px); }
.confirm-sheet .confirm-text { margin: 4px 0 6px; font-size: 16px; color: var(--ink); }
/* v12: 上部中央の「見せる」。何回でも押せる。金のピル */
.show-top {
  position: absolute;
  top: calc(var(--safe-t) + 14px);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 20px 0 16px;
  border-radius: 20px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: #1a1512;
  background: linear-gradient(180deg, #ead3a0 0%, #d2ad6c 55%, #b8893f 100%);
  box-shadow: 0 4px 16px rgba(201, 164, 106, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -1px 0 rgba(0, 0, 0, 0.15);
  z-index: 15;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease;
}
.show-top:active { transform: translateX(-50%) translateY(1px); box-shadow: 0 2px 8px rgba(201, 164, 106, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
.show-top:disabled { opacity: 0.45; cursor: default; }
.show-top svg { display: block; }
/* 開発画面では判読の □ が上に居るので、その下へ */
html:not(.release) .show-top { top: calc(var(--safe-t) + 18px + 44px + 10px); }
.auto-btn.on {
  color: var(--brass);
  border-color: var(--brass-dim);
  background: rgba(201, 164, 106, 0.10);
}
.auto-btn:disabled, .flip-btn:disabled { opacity: 0.35; cursor: default; }

/* 自動中の工程（判読表示の下に 1 行） */
.auto-status {
  position: absolute;
  top: calc(var(--safe-t) + 18px + 46px + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- 右上：⚙ ---------- */
.gear {
  position: absolute;
  top: calc(var(--safe-t) + 14px);
  right: calc(var(--safe-r) + 12px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  color: var(--ink-dim);
  opacity: 0.6;
  z-index: 15;
}
.gear:active { opacity: 1; }

.debug {
  position: absolute;
  top: calc(var(--safe-t) + 58px);
  right: calc(var(--safe-r) + 12px);
  width: 220px;
  max-height: calc(100% - var(--safe-t) - var(--safe-b) - 76px);
  overflow-y: auto;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  font-size: 13px;
  z-index: 15;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.debug h2 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.debug label,
.debug .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.debug input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brass);
}
/* ×1 / ×3 の切り替え（押すたびに反転） */
.debug .seg, .show-sheet .seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}
.debug .seg span, .show-sheet .seg button { padding: 3px 9px; color: var(--ink-dim); }
.debug .seg span.on, .show-sheet .seg button.on { background: rgba(201, 164, 106, 0.18); color: var(--brass); }
.debug .info {
  margin-top: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-dim);
  white-space: pre;
}

/* ---------- 下部：道具 ---------- */
.toolbar {
  position: absolute;
  left: calc(var(--safe-l) + 10px);
  right: calc(var(--safe-r) + 10px);
  bottom: calc(var(--safe-b) + 12px);
  max-width: 460px;
  margin: 0 auto;
  height: var(--toolbar-h);
  display: grid;
  /* 道具の数（v3 は6つ）に合わせて等分。390px 幅で 1 つ ≈ 56px（370 − 枠2 − 余白10 − 間隔5×4 = 338 / 6） */
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 5px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  z-index: 10;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  border-radius: 15px;
  color: var(--ink-dim);
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tool svg {
  width: 26px;
  height: 26px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* ラベル 11px（「ブラシ」「ピック」3 文字 ≈ 33px が 56px 幅に収まる） */
.tool span { font-size: 11px; letter-spacing: 0; line-height: 1.2; white-space: nowrap; }
.tool.active {
  color: var(--brass);
  background: rgba(201, 164, 106, 0.10);
  border-color: var(--brass-dim);
}
.tool:active { background: rgba(255, 255, 255, 0.05); }

/* 道具先端の目印（オフセット時に指で隠れない位置を示す） */
.tip {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  border: 1px solid rgba(240, 225, 195, 0.55);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.tip.on { opacity: 1; }
/* v9: リングが手応えを返す */
.tip { border-width: 1.5px; transition: opacity 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease; }
.tip.live {
  border-color: rgba(255, 240, 205, 0.95);
  border-width: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 10px rgba(255, 225, 160, 0.45);
}
.tip.slip {
  border-color: rgba(150, 150, 150, 0.55);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  opacity: 0.6;
}
.tip.scratch, .tip.scratch.live {
  border-color: rgba(230, 90, 70, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 12px rgba(230, 90, 70, 0.6);
}
.tip.born { animation: tip-born 0.26s ease-out; }
@keyframes tip-born {
  0% { scale: 1.6; opacity: 0.4; }
  100% { scale: 1; opacity: 1; }
}
/* 自動モードの仮想ポインタ: 輪を少し濃くし、中心に点を打って「指先」に見せる */
.tip.auto { border-color: rgba(240, 225, 195, 0.85); }
.tip.auto::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: rgba(240, 225, 195, 0.9);
}

/* ---------- 同定バナー ---------- */
.banner {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + var(--toolbar-h) + 26px);
  transform: translateX(-50%);
  width: min(360px, calc(100% - 28px));
  padding: 18px 18px 14px;
  border-radius: 18px;
  background: rgba(24, 22, 19, 0.92);
  border: 1px solid var(--brass-dim);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  text-align: center;
  z-index: 12;
  animation: rise 0.45s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.banner .title {
  font-family: var(--mincho);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.06em;
  color: var(--brass);
}
.banner .title small {
  font-size: 15px;
  color: var(--ink-dim);
  font-weight: 400;
  letter-spacing: 0.02em;
}
.banner .note {
  margin: 8px 0 14px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink-dim);
}
.actions {
  display: flex;
  gap: 8px;
}
.btn {
  flex: 1;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  font-size: 15px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}
.btn.primary {
  background: var(--brass);
  border-color: var(--brass);
  color: #1a1610;
  font-weight: 600;
}
.btn:active { filter: brightness(1.12); }
.btn:disabled { opacity: 0.5; }

/* ---------- 仕舞う画面 ---------- */
.stored-top {
  position: absolute;
  top: calc(var(--safe-t) + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 8;
}
.compare {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 14px;
  overflow: hidden;
  background: #151412;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  touch-action: none;
}
.compare img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.compare .before { clip-path: inset(0 50% 0 0); }
.compare .divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: rgba(235, 229, 217, 0.8);
  pointer-events: none;
}
.compare input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  touch-action: none;
}
.compare-labels {
  width: 150px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}
.stored-name {
  font-family: var(--mincho);
  font-size: 13px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
}
.stored-back-note { color: var(--ink-faint); font-size: 11.5px; }

.stored-bottom {
  position: absolute;
  left: calc(var(--safe-l) + 14px);
  right: calc(var(--safe-r) + 14px);
  bottom: calc(var(--safe-b) + 14px);
  max-width: 460px;
  margin: 0 auto;
  z-index: 10;
}

/* 見せる画像のプレビューと端末への保存 */
.show-backdrop {
  position: absolute;
  inset: 0;
  z-index: 29;
  background: rgba(8, 8, 7, 0.72);
}
.show-sheet {
  position: absolute;
  left: calc(var(--safe-l) + 14px);
  right: calc(var(--safe-r) + 14px);
  bottom: 0;
  max-width: 480px;
  max-height: calc(100% - var(--safe-t) - 14px);
  margin: 0 auto;
  padding: 16px 16px calc(var(--safe-b) + 14px);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.55);
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
.show-preview {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
  margin: 0 auto 12px;
  border-radius: 8px;
}
.show-sheet .seg { display: flex; margin-bottom: 12px; }
.show-sheet .seg button { flex: 1; min-height: 44px; font-size: 14px; }
.show-sheet .seg button:disabled { opacity: 0.5; }
.show-sheet .actions .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; font-size: 14px; white-space: nowrap; }
.show-note { margin: 10px 0 0; font-size: 12px; line-height: 1.6; color: var(--ink-dim); }
.show-sheet .actions + .actions { margin-top: 8px; }
.show-sheet .btn.ghost { border-color: transparent; color: var(--ink-dim); background: transparent; }

/* ---------- 開始オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(ellipse at 50% 45%, rgba(17, 17, 16, 0.55), rgba(10, 10, 9, 0.92) 70%);
  z-index: 30;
  transition: opacity 0.25s ease;
}
.overlay.fade { opacity: 0; pointer-events: none; }
.overlay h1 {
  margin: 0;
  font-family: var(--mincho);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: 0.12em;
  color: var(--ink);
}
.overlay p {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink-dim);
}
.overlay p.sub { font-size: 14px; margin-top: -8px; }
.overlay p.credit { position: absolute; left: 16px; right: 16px; bottom: calc(var(--safe-b, 0px) + 100px); font-size: 11px; line-height: 1.5; color: var(--ink-faint); }
.overlay p span { display: inline-block; }   /* 文の切れ目でだけ折り返す */
.overlay .btn {
  flex: none;
  min-width: 180px;
  min-height: 52px;
  margin-top: 10px;
  font-size: 17px;
  letter-spacing: 0.1em;
}

.fatal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--ink-dim);
  z-index: 40;
  background: var(--bg);
}

/* 狭い画面（iPhone SE 1st 等 320px）：道具6つを収める（1 つ ≈ 48px） */
@media (max-width: 350px) {
  .toolbar { left: calc(var(--safe-l) + 6px); right: calc(var(--safe-r) + 6px); gap: 2px; padding: 4px; }
  .tool { border-radius: 13px; }
  .tool svg { width: 22px; height: 22px; }
  .tool span { font-size: 11px; letter-spacing: 0; }
  .auto-btn, .flip-btn, .restart-btn { left: calc(var(--safe-l) + 6px); padding: 0 7px; font-size: 11px; letter-spacing: 0; }
  .restart-btn { top: calc(var(--safe-t) + 10px + 32px + 8px + 32px + 8px); }
  .flip-btn.hidden + .restart-btn { top: calc(var(--safe-t) + 10px + 32px + 8px); }
}

/* 横画面・低い画面 */
@media (max-height: 520px) {
  :root { --toolbar-h: 62px; }
  .tool svg { width: 24px; height: 24px; }
  .reading { top: calc(var(--safe-t) + 8px); }
  .reading .slot { width: 34px; height: 36px; font-size: 24px; }
  .auto-btn { top: calc(var(--safe-t) + 10px); }
  .flip-btn { top: calc(var(--safe-t) + 10px + 32px + 8px); }
  .show-top { top: calc(var(--safe-t) + 8px); height: 34px; font-size: 13px; }
  .auto-status { top: calc(var(--safe-t) + 8px + 36px + 2px); }
  .compare, .compare-labels { width: 110px; }
  .compare { height: 110px; }
  .stored-top { left: calc(var(--safe-l) + 80px); transform: none; }
  .overlay h1 { font-size: 24px; }
}

/* ---------- v4 工房：右上「工房」ボタン（⚙ の左。判読表示と重ならない位置） ---------- */
.workshop-btn {
  position: absolute;
  top: calc(var(--safe-t) + 18px);
  right: calc(var(--safe-r) + 12px + 44px);
  height: 32px;
  padding: 0 11px;
  border-radius: 16px;
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--ink-dim);
  background: rgba(22, 21, 19, 0.55);
  border: 1px solid var(--line);
  z-index: 15;
}
.workshop-btn:active { color: var(--brass); }

/* 見習いの作業台: 左上の下に縦に並ぶ小さな丸い canvas（磨く領域は狭めない） */
.benches {
  position: absolute;
  top: calc(var(--safe-t) + 18px + 32px + 10px);
  left: calc(var(--safe-l) + 12px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 14;
}
/* 反転ボタンがあるときだけ、見習いをもう一段下へ */
.flip-btn:not(.hidden) ~ .benches { top: calc(var(--safe-t) + 18px + 32px + 8px + 32px + 10px); }
.bench {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #151412;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.bench-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.bench-idle {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  background: #151412;
}
.bench:not(.idle) .bench-idle { display: none; }

/* 短い知らせ（棚に並べた など。2.6 秒で消える） */
.toast {
  position: absolute;
  top: calc(var(--safe-t) + 18px + 46px + 4px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--brass);
  background: rgba(22, 21, 19, 0.8);
  border: 1px solid var(--brass-dim);
  white-space: nowrap;
  pointer-events: none;
  z-index: 31; /* 見せるシートの上にもコピー完了を出す */
}

/* 作業台が空のときの案内 */
.empty-note {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  z-index: 9;
}
.empty-note p { margin: 0; font-size: 14px; color: var(--ink-dim); }
.empty-note .btn { flex: none; min-width: 140px; }

/* 工房パネル（下からのシート） */
.workshop {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 78%;
  display: flex;
  flex-direction: column;
  border-radius: 20px 20px 0 0;
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.55);
  z-index: 25;
  animation: ws-rise 0.3s ease-out;
}
@keyframes ws-rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.ws-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
}
.ws-head h2 { margin: 0; font-family: var(--mincho); font-size: 18px; letter-spacing: 0.12em; font-weight: 700; }
.ws-close { width: 36px; height: 36px; border-radius: 50%; color: var(--ink-dim); font-size: 16px; }
.ws-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px calc(var(--safe-b) + 18px);
  touch-action: pan-y;
}
.ws-sec { padding: 12px 0; border-top: 1px solid var(--line); }
.ws-sec h3 {
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.ws-sec h3 small { font-weight: 400; color: var(--ink-faint); font-size: 11px; }
.ws-money { font-family: var(--mincho); font-size: 26px; letter-spacing: 0.06em; color: var(--brass); margin-bottom: 4px; }
.ws-note { margin: 0 0 10px; font-size: 12.5px; line-height: 1.6; color: var(--ink-dim); }
.ws-sec .btn { width: 100%; }
.ws-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.ws-ap-label { color: var(--ink-dim); font-size: 12px; text-align: right; }
.ws-item { display: flex; gap: 12px; align-items: center; padding: 8px 0; }
.ws-item-body { flex: 1; min-width: 0; }
.ws-item-title { font-size: 12.5px; color: var(--ink-dim); margin-bottom: 6px; }
.ws-item-actions { display: flex; gap: 8px; }
.btn.small { min-height: 36px; font-size: 13px; border-radius: 11px; padding: 0 10px; }
.ws-thumb {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  background: #151412;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-size: 12px;
}
.ws-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ws-appraisers { display: flex; flex-direction: column; gap: 8px; }
.ws-appraiser {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
}
.ws-appraiser strong { font-family: var(--mincho); font-size: 15px; color: var(--ink); letter-spacing: 0.08em; }
.ws-appraiser span { font-size: 12px; line-height: 1.5; }
.ws-appraiser.on { border-color: var(--brass-dim); background: rgba(201, 164, 106, 0.10); }
.ws-appraiser.on strong { color: var(--brass); }
.ws-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
.ws-shelf-item { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 44px; min-height: 44px; padding: 4px 2px; border-radius: 12px; }
.ws-shelf-item:active { background: rgba(201, 164, 106, 0.08); }
.ws-shelf-item .ws-thumb { width: 60px; height: 60px; }
.ws-shelf-val { font-size: 12px; color: var(--ink); }
.ws-shelf-sub { font-size: 10px; color: var(--ink-faint); text-align: center; line-height: 1.3; }

@media (max-width: 350px) {
  /* 320px では判読表示と重なるので、工房は右上 2 段目、仕舞うは 3 段目へ */
  .workshop-btn { top: calc(var(--safe-t) + 18px + 32px + 8px); right: calc(var(--safe-r) + 6px); padding: 0 9px; font-size: 11px; }
  .benches { left: calc(var(--safe-l) + 6px); }
  .bench { width: 42px; height: 42px; }
}
@media (max-height: 520px) {
  .workshop-btn { top: calc(var(--safe-t) + 10px); }
  .benches { top: calc(var(--safe-t) + 10px + 32px + 8px); flex-direction: row; }
  .flip-btn:not(.hidden) ~ .benches { top: calc(var(--safe-t) + 10px + 32px + 8px + 32px + 8px); }
  .toast { top: calc(var(--safe-t) + 8px + 36px + 2px); }
}

/* 5 枠はボタンの下へ。狭い画面でも左の見習い・右の「仕舞う」と重ねない */
@media (max-width: 520px) {
  .show-sheet { padding-left: 12px; padding-right: 12px; }
  .show-sheet .actions .btn { padding: 0 6px; font-size: 13px; }
  .reading.with-back { top: calc(var(--safe-t) + 100px); gap: 4px; }
  .reading.with-back .slot { width: 32px; height: 40px; font-size: 26px; }
  .reading.with-back ~ .auto-status, .reading.with-back ~ .toast { top: calc(var(--safe-t) + 144px); }
  /* v11: 公開版は右上に工房・⚙ が無いので、□ を 2 段目（裏返すと同じ行）に上げる */
  html.release .reading.with-back { top: calc(var(--safe-t) + 56px); }
  html.release .reading.with-back ~ .auto-status, html.release .reading.with-back ~ .toast { top: calc(var(--safe-t) + 104px); }
  .benches { flex-direction: column; }
}

/* 同定済みでバナーを閉じた後の「仕舞う」（右上 2 段目。判読表示と重ならない） */
.store-btn {
  position: absolute;
  top: calc(var(--safe-t) + 18px + 32px + 8px);
  right: calc(var(--safe-r) + 12px);
  height: 32px;
  padding: 0 11px;
  border-radius: 16px;
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--brass);
  background: rgba(201, 164, 106, 0.10);
  border: 1px solid var(--brass-dim);
  z-index: 15;
}
@media (max-width: 350px) { .store-btn { top: calc(var(--safe-t) + 18px + 32px + 8px + 32px + 6px); right: calc(var(--safe-r) + 6px); padding: 0 9px; font-size: 11px; } }
@media (max-height: 520px) { .store-btn { top: calc(var(--safe-t) + 10px + 32px + 6px); } }

/* v5: 仕舞う画面の一行（両派の鑑定と筋の言葉） */
.stored-grade {
  margin: 0 0 10px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.5;
  letter-spacing: 0.03em;
  color: var(--ink-dim);
}
.stored-grade:empty { display: none; }
/* v9: 結果画面の 2 ボタン（両派） */
.stored-bottom .actions.shelve2 { margin-top: 8px; }
.stored-bottom .actions.shelve2 .btn { flex: 1 1 0; min-width: 0; padding-left: 8px; padding-right: 8px; font-size: 13.5px; }
.ws-short { margin: 6px 0 0; color: var(--ink-faint); }
.banner .note.back { color: var(--brass); }

/* v5: ⚙ の旗の説明 */
.debug .flag-hint { margin: 6px 0 0; font-size: 11px; line-height: 1.5; color: var(--ink-faint); }
.debug input[type="checkbox"]:disabled { opacity: 0.45; }

/* v5: 棚のコインを眺める（工房パネルの上のモーダル） */
.ws-view {
  position: absolute;
  inset: 0;
  z-index: 28;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
  background: rgba(8, 8, 7, 0.78);
  animation: ws-rise 0.25s ease-out;
}
.ws-view-card {
  width: min(100%, 340px);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 14px 16px;
  border-radius: 20px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}
.ws-view-head { align-self: stretch; display: flex; justify-content: flex-end; }
.ws-view-close { width: 44px; height: 44px; border-radius: 50%; color: var(--ink-dim); font-size: 18px; }
.ws-view-stage { width: 300px; height: 300px; max-width: 100%; display: grid; place-items: center; }
.ws-view-canvas { display: block; width: 300px; height: 300px; border-radius: 12px; touch-action: none; cursor: crosshair; }
.ws-view-thumb { width: 120px; height: 120px; border-radius: 50%; overflow: hidden; background: #151412; border: 1px solid var(--line); }
.ws-view-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ws-view-flip { flex: none; margin-top: 10px; min-width: 96px; }
.ws-view-ticket {
  align-self: stretch;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--ink-dim);
}
.ws-view-val { display: flex; align-items: baseline; gap: 10px; }
.ws-view-val strong { font-family: var(--mincho); font-size: 22px; color: var(--brass); letter-spacing: 0.06em; font-weight: 700; }
.ws-view-val span { font-family: var(--mincho); font-size: 14px; color: var(--ink); letter-spacing: 0.08em; }
.ws-view-line:empty { display: none; }
.ws-view-line.dim, .ws-view-hint { color: var(--ink-faint); font-size: 11.5px; }

/* ======================================================================
   v13: UI を整える「文机の上の工房」（SPEC_v13_UI）。以降の規則は上の規則を上書きする。
   色は墨と真鍮の 2 つ、見出しは明朝、操作は細いゴシック。影は使わず、線と灯りだけ。
   ====================================================================== */
:root {
  --bg: #0f0e0d;
  --ink: #ece6da;
  --ink-dim: rgba(236, 230, 218, 0.6);
  --ink-faint: rgba(236, 230, 218, 0.26);
  --brass: #c9a46a;
  --brass-hi: #e6cc96;
  --brass-dim: rgba(201, 164, 106, 0.4);
  --panel: rgba(18, 17, 16, 0.78);
  --panel-solid: #161514;
  --line: rgba(236, 230, 218, 0.12);
  --line-brass: rgba(201, 164, 106, 0.45);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --top-h: 40px;
}
button { transition: transform 160ms var(--ease), background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), opacity 160ms var(--ease); }
button:active:not(:disabled) { transform: scale(0.97); filter: none; }

/* 灯りと台 */
.stage-glow {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background:
    radial-gradient(circle at 50% 50%, transparent 0, transparent 46%, rgba(201, 164, 106, 0.08) 52%, rgba(201, 164, 106, 0.03) 60%, transparent 72%);
}
html.release .stage-glow::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 112vw; height: 112vw; max-width: 560px; max-height: 560px;
  transform: translate(-50%, -50%); border-radius: 50%; border: 1px solid var(--line);
}

/* ボタンの 3 段。一次 = 真鍮の塗り、二次 = 真鍮の細枠、三次 = 枠なし */
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 22px; font-size: 14px; letter-spacing: 0.06em;
  border: 1px solid var(--line-brass); background: transparent; color: var(--brass);
}
.btn.primary { background: var(--brass); border-color: var(--brass); color: #1a1512; font-weight: 700; }
.btn.ghost { border-color: transparent; color: var(--ink-dim); }
.btn:active { filter: none; }

/* 上段（公開版は 1 列、開発画面は従来の絶対配置のまま） */
html.release .topbar {
  position: absolute; top: calc(var(--safe-t) + 14px); left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px);
  display: flex; align-items: center; gap: 8px; z-index: 15; height: var(--top-h);
}
html.release .topbar .spacer { flex: 1 1 auto; }
html.release .topbar .auto-btn, html.release .topbar .flip-btn, html.release .topbar .restart-btn, html.release .topbar .store-btn, html.release .topbar .show-top {
  position: static; transform: none; margin: 0; flex: 0 0 auto;
}
.auto-btn, .flip-btn, .restart-btn, .store-btn {
  height: var(--top-h); padding: 0 12px; border-radius: 20px; font-size: 12px; letter-spacing: 0.06em;
  color: var(--brass); background: rgba(15, 14, 13, 0.55); border: 1px solid var(--line-brass);
}
.auto-btn.on { color: var(--brass-hi); border-color: var(--brass); background: rgba(201, 164, 106, 0.12); }
.restart-btn.holding { border-color: #b5473a; color: #d9736a; }
.auto-btn:disabled, .flip-btn:disabled, .restart-btn:disabled, .show-top:disabled { opacity: 0.4; }
/* 一次は画面に 1 つ。仕舞うが出ている間は見せるを二次に下げる */
html.release .store-btn { background: var(--brass); color: #1a1512; font-weight: 700; border-color: var(--brass); }
.show-top {
  height: var(--top-h); padding: 0 16px 0 14px; gap: 6px; font-size: 13px; letter-spacing: 0.08em; font-weight: 700;
  background: var(--brass); color: #1a1512; box-shadow: none; border: 1px solid var(--brass);
}
.show-top:active { transform: scale(0.97); box-shadow: none; }
html.release .has-store .show-top { background: rgba(15, 14, 13, 0.55); color: var(--brass); border-color: var(--line-brass); font-weight: 600; }
html.release .topbar .show-top { transform: none; }
html.release .topbar .show-top:active { transform: scale(0.97); }
@media (max-width: 370px) {
  html.release .topbar { gap: 6px; }
  .auto-btn, .flip-btn, .restart-btn, .store-btn { padding: 0 9px; font-size: 11px; letter-spacing: 0.02em; }
  .show-top { padding: 0 12px; font-size: 12px; }
}

/* 倍率メニュー: 上段の真下、左寄せ。二次の様式 */
.auto-menu {
  top: calc(var(--safe-t) + 14px + var(--top-h) + 8px); left: calc(var(--safe-l) + 12px);
  padding: 6px; gap: 6px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: none;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.auto-menu .auto-speed { border-color: var(--line-brass); background: transparent; color: var(--brass); border-radius: 12px; }
.auto-menu .auto-speed b { color: var(--brass-hi); }
.auto-menu .auto-speed span { color: var(--ink-dim); }
@media (max-width: 350px) { .auto-menu { left: calc(var(--safe-l) + 12px); } }

/* 状態チップ: 上段の下、中央。真鍮の点が明滅 */
.auto-status, .toast {
  top: calc(var(--safe-t) + 14px + var(--top-h) + 10px);
  font-size: 13px; letter-spacing: 0.04em; color: var(--ink-dim);
}
.auto-status { display: inline-flex; align-items: center; gap: 8px; }
.auto-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--brass); box-shadow: 0 0 8px var(--brass); animation: chip-blink 1.2s ease-in-out infinite; }
@keyframes chip-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.toast { padding: 7px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line-brass); color: var(--brass); box-shadow: none; }
html.release .reading.with-back ~ .auto-status, html.release .reading.with-back ~ .toast { top: calc(var(--safe-t) + 14px + var(--top-h) + 10px); }

/* 道具バー */
.toolbar { height: 72px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); gap: 0; padding: 5px; -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); bottom: calc(var(--safe-b) + 14px); }
.tool { border-radius: 13px; gap: 5px; color: var(--ink-dim); position: relative; }
.tool + .tool::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 1px; background: var(--line); }
.tool svg { width: 22px; height: 22px; }
.tool span { font-size: 12px; letter-spacing: 0.02em; }
.tool.active { background: rgba(201, 164, 106, 0.14); color: var(--brass); border-color: transparent; box-shadow: none; }
.tool.active::after { content: ""; position: absolute; top: 5px; left: 50%; width: 4px; height: 4px; border-radius: 50%; background: var(--brass); transform: translateX(-50%); }
.tool.active::before { background: transparent; }
.tool.active + .tool::before { background: transparent; }
.tool:active { background: rgba(201, 164, 106, 0.08); }

/* 紙（カード・仕舞う画面・シート）: 上端に真鍮の線 */
.banner, .show-sheet, .stored-bottom {
  background: var(--panel); border: 1px solid var(--line); box-shadow: none; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line-brass);
}
.banner { border-radius: 22px; padding: 20px 18px 16px; }
.banner .title { font-size: 26px; letter-spacing: 0.08em; }
.banner .note { color: var(--ink-dim); font-size: 13px; }
.show-sheet { border-radius: 22px 22px 0 0; }
.show-sheet .seg { border-color: var(--line-brass); border-radius: 12px; }
.show-sheet .seg button { color: var(--ink-dim); }
.show-sheet .seg button.on { background: rgba(201, 164, 106, 0.14); color: var(--brass); }
.confirm-sheet .confirm-text { font-family: var(--mincho); font-size: 18px; letter-spacing: 0.06em; }
.stored-name { font-family: var(--mincho); letter-spacing: 0.1em; }
.stored-grade { color: var(--ink-dim); font-size: 13px; letter-spacing: 0.04em; }

/* タイトル */
.overlay { gap: 14px; background: radial-gradient(ellipse at 50% 45%, rgba(15, 14, 13, 0.6), rgba(10, 10, 9, 0.94) 72%); }
.overlay h1 { font-size: 34px; letter-spacing: 0.18em; font-weight: 700; }
.overlay .rule { width: 48px; height: 1px; background: var(--brass); margin: 2px 0 4px; }
.overlay p { font-size: 15px; letter-spacing: 0.04em; line-height: 1.9; }
.overlay p.sub { font-size: 14px; margin-top: -10px; }
.overlay .btn { min-height: 48px; padding: 0 44px; font-size: 16px; margin-top: 10px; border-radius: 24px; }
/* 仕舞うが出ている間は見せるをアイコンだけに（375px で 5 つが収まるように） */
html.release .has-store .show-top span { display: none; }
html.release .has-store .show-top { padding: 0 12px; }
html.release .topbar { gap: 6px; }
.auto-btn, .flip-btn, .restart-btn, .store-btn { padding: 0 11px; }
/* 開発画面（?debug=1）: 見せるは判読の □ の行の下、中央 */
html:not(.release) .show-top { top: calc(var(--safe-t) + 18px + 44px + 10px + 52px); }
@media (max-width: 520px) { html:not(.release) .show-top { top: calc(var(--safe-t) + 100px + 44px + 10px); } }

/* v14: 仕舞う画面のビフォー・アフター（比較の枠）を出さない。名前と「裏は手つかず」だけ残す */
html.release .stored-top .compare, html.release .stored-top .compare-labels { display: none; }

/* v14: 共有する文章を見せる */
.show-sheet .show-text {
  margin: 10px 0 12px; padding: 10px 12px; border-radius: 12px;
  background: rgba(236, 230, 218, 0.05); border: 1px solid var(--line);
  font-size: 13px; line-height: 1.7; color: var(--ink); white-space: pre-wrap; word-break: break-all;
  -webkit-user-select: text; user-select: text;
}

/* v14f: 鑑定（旧 見せる）は公開版では画面下の中央、道具バーのすぐ上。大きく、一次（真鍮の塗り）のまま */
html.release .show-top {
  top: auto; bottom: calc(var(--safe-b) + 14px + 72px + 14px);
  left: 50%; transform: translateX(-50%);
  height: 52px; padding: 0 30px 0 24px; gap: 8px; border-radius: 26px;
  font-size: 16px; letter-spacing: 0.14em; font-weight: 700;
  background: var(--brass); color: #1a1512; border-color: var(--brass);
  box-shadow: 0 6px 20px rgba(201, 164, 106, 0.28);
}
html.release .show-top:active { transform: translateX(-50%) scale(0.97); }
html.release .has-store .show-top { background: var(--brass); color: #1a1512; border-color: var(--brass); font-weight: 700; padding: 0 30px 0 24px; }
html.release .has-store .show-top span { display: inline; }
/* 仕舞うは上段で二次に（一次は鑑定 1 つ） */
html.release .store-btn { background: rgba(15, 14, 13, 0.55); color: var(--brass); border-color: var(--line-brass); font-weight: 600; }
@media (max-height: 700px) { html.release .show-top { height: 44px; font-size: 15px; } }

/* v14h: 鑑定は下の道具バーの中央（ユーザー「下の道具一覧の中央に配置」）。丸い真鍮のボタンをバーから少し浮かせる。
   左に 水・ブラシ、右に ピック・綿棒・布。上段は 1 段に戻す */
html.release .toolbar { display: flex; overflow: visible; }
html.release .toolbar .tool { flex: 1 1 0; }
html.release .toolbar .show-top {
  position: relative; top: auto; bottom: auto; left: auto; transform: none;
  flex: 0 0 78px; height: 78px; width: 78px; margin: -26px 4px 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 50%; font-size: 13px; letter-spacing: 0.12em; font-weight: 700;
  background: var(--brass); color: #1a1512; border: 3px solid var(--bg);
  box-shadow: 0 6px 18px rgba(201, 164, 106, 0.3);
}
html.release .toolbar .show-top svg { width: 24px; height: 24px; }
html.release .toolbar .show-top:active { transform: scale(0.96); }
html.release .toolbar .show-top + .tool::before { background: transparent; }
html.release .has-store .toolbar .show-top { background: var(--brass); color: #1a1512; border-color: var(--bg); padding: 0; }
html.release .has-store .toolbar .show-top span { display: inline; }
@media (max-width: 370px) { html.release .toolbar .show-top { flex-basis: 68px; width: 68px; height: 68px; font-size: 12px; } }

/* v14i: 鑑定は右上（上段の右端）。一次（真鍮の塗り）のピル。仕舞うが出ている間はルーペのアイコンだけ */
html.release .topbar .show-top {
  position: static; top: auto; bottom: auto; left: auto; transform: none; margin: 0; flex: 0 0 auto;
  height: var(--top-h); width: auto; padding: 0 16px 0 13px; gap: 6px; border-radius: 20px;
  flex-direction: row; font-size: 13px; letter-spacing: 0.1em; font-weight: 700;
  background: var(--brass); color: #1a1512; border: 1px solid var(--brass); box-shadow: none;
}
html.release .topbar .show-top svg { width: 17px; height: 17px; }
html.release .topbar .show-top:active { transform: scale(0.97); }
/* v30: 鑑定の文字は必ず出す（ルーペだけだと分かりにくい）。仕舞うが出ている間は上段の余白を詰めて収める */
html.release .has-store .topbar { gap: 5px; }
html.release .has-store .topbar .auto-btn, html.release .has-store .topbar .flip-btn, html.release .has-store .topbar .restart-btn, html.release .has-store .topbar .store-btn { padding: 0 8px; letter-spacing: 0.02em; }
html.release .has-store .topbar .show-top { padding: 0 11px 0 9px; gap: 4px; letter-spacing: 0.04em; }
html.release .has-store .topbar .show-top span { display: inline; }
@media (max-width: 350px) {
  html.release .has-store .topbar { gap: 4px; }
  html.release .has-store .topbar .auto-btn, html.release .has-store .topbar .flip-btn, html.release .has-store .topbar .restart-btn, html.release .has-store .topbar .store-btn { padding: 0 6px; font-size: 11px; letter-spacing: 0; }
  html.release .has-store .topbar .show-top { padding: 0 9px 0 7px; font-size: 12px; }
}

/* ======================================================================
   v15: 鑑定の場（SPEC_v15_reveal）。判子 → 引かれた所の輪と札 → 一言 → 両派の値 → ボタン。
   色は v13 の墨と真鍮、判子の赤は showcard の RED と同じ値。報酬演出（火花・数え上げ・揺れ）は入れない
   ====================================================================== */
:root { --seal: #b5473a; }
/* 開いている間は道具バー・上段・判読・バナー・仕舞う画面を隠す（コインは描き続ける） */
.revealing .toolbar, .revealing .topbar, .revealing .reading, .revealing .banner, .revealing .auto-btn, .revealing .auto-menu,
.revealing .flip-btn, .revealing .restart-btn, .revealing .show-top, .revealing .workshop-btn, .revealing .store-btn,
.revealing .benches, .revealing .gear, .revealing .debug, .revealing .auto-status, .revealing .stored-top, .revealing .stored-bottom,
.revealing .tip, .revealing .toolsprite, .revealing .empty-note, .revealing .fly-layer, .revealing .stage-glow {
  visibility: hidden !important; pointer-events: none !important;
}
.reveal { position: absolute; inset: 0; z-index: 30; padding-top: var(--safe-t); touch-action: none; }
.reveal-marks { position: absolute; inset: 0; pointer-events: none; }
.reveal .rv-wait { opacity: 0; pointer-events: none; }
.reveal .rv-in { opacity: 1; transition: opacity 240ms var(--ease); }
.reveal.instant *, .reveal.instant { transition: none !important; animation: none !important; }

/* 判子: 赤枠 2px・角丸 4px・22px 太字・−4° */
.reveal-seal {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) rotate(-4deg);
  padding: 4px 10px; border: 2px solid var(--seal); border-radius: 4px; background: rgba(239, 230, 210, 0.12);
  color: var(--seal); font-family: var(--mincho); font-size: 22px; font-weight: 700; letter-spacing: 0.08em; line-height: 1.3;
  white-space: nowrap;
}
.reveal-seal.rv-in { animation: reveal-seal 420ms var(--ease); }
.reveal.done .reveal-seal.rv-in { opacity: 0.55; transition: opacity 400ms var(--ease); }
@keyframes reveal-seal {
  from { opacity: 0; transform: translate(-50%, -50%) rotate(-4deg) scale(1.08); }
  to { opacity: 1; transform: translate(-50%, -50%) rotate(-4deg) scale(1); }
}
/* 輪: 真鍮 1.5px。番号は外側の右上の小さな丸 */
.reveal-ring { position: absolute; box-sizing: border-box; border: 1.5px solid var(--brass); border-radius: 50%; }
.reveal-ring.rv-in { animation: reveal-ring 240ms var(--ease); }
@keyframes reveal-ring { from { opacity: 0; transform: scale(1.25); } to { opacity: 1; transform: scale(1); } }
.reveal-num {
  position: absolute; right: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; background: var(--brass); color: #1a1512; font-size: 12px; font-weight: 700; line-height: 1;
}

/* パネル: 墨の面。画面の 46% まで、あふれたら中でスクロール */
.reveal-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 46%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-sizing: border-box; padding: 14px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 16px);
  background: var(--panel); border-top: 1px solid var(--line-brass); border-radius: 22px 22px 0 0;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  animation: reveal-rise 240ms var(--ease); touch-action: pan-y;
}
@keyframes reveal-rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.reveal-name { font-family: var(--mincho); font-size: 19px; letter-spacing: 0.06em; line-height: 1.35; text-align: center; color: var(--ink); }
.reveal-name .prefix { color: var(--brass); }
.reveal-remark { margin: 4px 0 0; font-size: 13px; line-height: 1.5; text-align: center; color: var(--ink-dim); }
.reveal-values { display: flex; align-items: baseline; justify-content: center; gap: 16px; margin-top: 6px; min-height: 36px; }
.reveal-value { display: inline-flex; align-items: baseline; gap: 4px; }
.reveal-value .by { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.04em; }
.reveal-value.big b { font-family: var(--mincho); font-size: 28px; color: var(--brass); letter-spacing: 0.04em; }
.reveal-value.big .unit { font-size: 14px; color: var(--brass); }
.reveal-value.small b { font-size: 14px; font-weight: 400; color: var(--ink-dim); }
.reveal-value.small .unit { font-size: 12px; color: var(--ink-dim); }
.reveal-values:has(.reveal-reading) { min-height: 0; }
.reveal-reading { font-size: 14px; color: var(--ink-dim); letter-spacing: 0.04em; }
.reveal-lines, .reveal-dlines { list-style: none; margin: 6px 0 0; padding: 0; }
.reveal-line, .reveal-dline { font-size: 14px; line-height: 1.6; color: var(--ink); }
.reveal-line .num, .reveal-dline .num { color: var(--brass); margin-right: 4px; }
.reveal-line .part, .reveal-dline .part { margin-left: 0.9em; white-space: nowrap; }
.reveal-line .by, .reveal-dline .by { color: var(--ink-dim); margin-right: 2px; }
.reveal-line.none { color: var(--ink-dim); }
/* v15b: 自動に任せた分（指摘の下に 1 行。番号も輪も無い） */
.reveal-auto { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: var(--ink-dim); }
.reveal-auto .part { margin-left: 0.9em; white-space: nowrap; color: var(--ink); }
.reveal-auto .by { color: var(--ink-dim); margin-right: 2px; }
.reveal .reveal-more { display: block; margin: 2px auto 0; min-height: 32px; padding: 0 14px; font-size: 13px; }
.reveal-detail { margin: 2px 0 6px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); }
.reveal-dline { font-size: 13px; }
.reveal-dnote { margin: 4px 0 0; font-size: 12px; color: var(--ink-dim); }
.reveal-actions { display: flex; gap: 10px; margin-top: 8px; }
.reveal-actions .btn { flex: 1 1 0; min-width: 0; }
@media (max-height: 680px) {
  .reveal-panel { padding-top: 10px; }
  .reveal-name { font-size: 17px; }
  .reveal-value.big b { font-size: 24px; }
  .reveal-line { font-size: 13.5px; line-height: 1.5; }
}


/* ---------------------------------------------------------------- v18: 値は 1 つ／棚（SPEC_v18_shelf） */
.reveal-value .by:empty { display: none; }
.reveal-prev { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.04em; margin-left: 10px; align-self: baseline; }
.shelf-btn {
  height: var(--top-h); padding: 0 11px; border-radius: 20px; font-size: 12px; letter-spacing: 0.06em;
  color: var(--brass); background: rgba(15, 14, 13, 0.55); border: 1px solid var(--line-brass);
}
html.release .topbar .shelf-btn { position: static; transform: none; margin: 0; flex: 0 0 auto; }
.shelf-btn:disabled { opacity: 0.4; }
@media (max-width: 370px) { .shelf-btn { padding: 0 9px; font-size: 11px; letter-spacing: 0.02em; } }
.shelf-sheet .confirm-text { margin: 2px 0 0; }
.shelf-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  margin: 12px 0 14px; max-height: 52vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.shelf-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px;
  border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.02);
  color: var(--ink); font: inherit; cursor: pointer;
}
.shelf-item:not(:disabled):active { border-color: var(--line-brass); background: rgba(201, 164, 106, 0.08); }
.shelf-item:disabled { cursor: default; opacity: 0.45; }
.shelf-item.is-bench { opacity: 0.7; border-style: dashed; }
.shelf-thumb { width: 72px; height: 72px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; background: #1b1915; }
.shelf-thumb img { width: 100%; height: 100%; object-fit: cover; }
.shelf-raw { font-family: var(--mincho); color: var(--ink-dim); font-size: 18px; }
.shelf-cap { font-size: 13px; color: var(--brass); letter-spacing: 0.04em; }
.shelf-item.is-waiting .shelf-cap, .shelf-item.is-bench .shelf-cap, .shelf-item.is-gone .shelf-cap { color: var(--ink-dim); font-size: 12px; }
.shelf-sub { font-size: 11px; color: var(--ink-dim); }
/* 「仕舞う」が出ている間は上段の「棚」を隠す（6 つは 402px でも収まらない。仕舞う画面の「棚から選ぶ」から開ける） */
html.release .has-store .topbar .shelf-btn { display: none; }
/* 確認シート: 注記とボタンの間を空ける（詰まって見えた） */
.confirm-sheet .show-note { margin: 0 0 16px; }

/* ---------------------------------------------------------------- v20: 赤い輪と場所の言葉（SPEC_v20_finer） */
.reveal-marks.finer .reveal-ring { border-color: var(--seal); border-width: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.reveal-marks.finer .reveal-num { background: var(--seal); color: #fff; }
.reveal-line .place, .reveal-dline .place { margin-left: 6px; font-size: 11.5px; color: var(--ink-dim); letter-spacing: 0.02em; }

/* ---------------------------------------------------------------- v21: 鑑定の場でコインを回す（SPEC_v21_turn） */
.revealing #coin-canvas { will-change: transform; }
.reveal-marks.turned-away { opacity: 0; transition: opacity 120ms linear; }
.reveal-turn-hint {
  position: absolute; left: 0; right: 0; top: calc(var(--safe-t) + 10px); text-align: center; pointer-events: none;
  font-size: 12px; letter-spacing: 0.1em; color: var(--ink-dim);
}
.reveal-turn-hint.gone { opacity: 0 !important; transition: opacity 300ms var(--ease); }
/* v21b: 回しているコインの厚み（canvas の下に円板を重ねる） */
.turn-edge { position: absolute; inset: 0; pointer-events: none; }
.turn-edge.hidden { display: none; }
.turn-edge-layer { position: absolute; border-radius: 50%; }
/* v26: 縁 = 周りに並べた帯片（側面の絵、外向きの面だけ描く） */
.turn-rim-seg { position: absolute; transform-origin: 50% 50%; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background-image: var(--rim-img, none); background-color: var(--rim-col, transparent); background-repeat: no-repeat; }
.turn-rim-shade { position: absolute; inset: 0; background: #000; }

/* ---------------------------------------------------------------- v22: 磨く段階で傾ける（SPEC_v22_angle） */
.tilt-reset {
  position: absolute; right: calc(var(--safe-r) + 14px); bottom: calc(var(--safe-b) + 108px); z-index: 12;
  height: 34px; padding: 0 14px; border-radius: 18px; font-size: 12px; letter-spacing: 0.08em;
  color: var(--brass); background: rgba(15, 14, 13, 0.7); border: 1px solid var(--line-brass);
}
.tilt-reset.hidden { display: none; }
.revealing .tilt-reset { display: none; }

/* ---------------------------------------------------------------- v23: 面の切り替えと側面の区画（SPEC_v23_side） */
.face-seg, .side-nav {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 14; display: flex; align-items: center;
  top: calc(var(--safe-t) + 14px + var(--top-h, 36px) + 10px);
  border: 1px solid var(--line-brass); border-radius: 18px; background: rgba(15, 14, 13, 0.6); overflow: hidden;
}
html:not(.release) .face-seg { top: calc(var(--safe-t) + 120px); }
.face-seg.hidden, .side-nav.hidden, .face-seg button.hidden { display: none; }
.face-seg button { height: 32px; min-width: 52px; padding: 0 12px; font-size: 12.5px; letter-spacing: 0.08em; color: var(--ink-dim); background: transparent; border: 0; }
.face-seg button + button { border-left: 1px solid var(--line); }
.face-seg button.on { color: #1a1512; background: var(--brass); font-weight: 700; }
.face-seg button:disabled { opacity: 0.4; }
.side-nav { top: calc(var(--safe-t) + 14px + var(--top-h, 36px) + 52px); gap: 4px; padding: 0 4px; }
html:not(.release) .side-nav { top: calc(var(--safe-t) + 162px); }
.side-nav button { height: 30px; min-width: 36px; font-size: 13px; color: var(--brass); background: transparent; border: 0; }
.side-label { min-width: 72px; text-align: center; font-size: 12px; letter-spacing: 0.08em; color: var(--ink); }
.revealing .face-seg, .revealing .side-nav { display: none; }

/* v25: 鑑定の場のボタンは 1 段のまま、折り返さない。狭い画面は文字と余白を小さく（2 段にすると 360×640 で画面の外に出た） */
.reveal-actions .btn { white-space: nowrap; }
@media (max-width: 400px) { .reveal-actions { gap: 8px; } .reveal-actions .btn { padding: 0 6px; font-size: 13px; letter-spacing: 0.02em; } }

/* ---------------------------------------------------------------- v27: 側面を立てて転がす（SPEC_v27_stand） */
.stand-face { position: absolute; pointer-events: none; transform-origin: 50% 50%; user-select: none; -webkit-user-select: none; }
html.is-stand .stage-glow { display: none; }
.stand-hint { position: absolute; left: 0; right: 0; text-align: center; pointer-events: none; font-size: 13px; letter-spacing: 0.12em; color: var(--ink-dim); transition: opacity 300ms var(--ease); }
.stand-hint.gone { opacity: 0; }

/* v29: 音のボタンと板（SPEC_v29_sound） */
.sound-btn {
  position: absolute; top: calc(var(--safe-t) + 14px + var(--top-h) + 10px); right: calc(var(--safe-r) + 12px); z-index: 15;
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--brass); background: rgba(15, 14, 13, 0.55); border: 1px solid var(--line-brass);
}
.sound-btn.off { color: var(--ink-dim); }
.sound-btn:active { transform: scale(0.95); }
.sound-menu {
  position: absolute; top: calc(var(--safe-t) + 14px + var(--top-h) + 10px + 36px + 8px); left: calc(var(--safe-l) + 12px);
  display: flex; align-items: center; gap: 12px; padding: 8px 14px 8px 8px; border-radius: 14px;
  background: var(--panel-solid); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); z-index: 16;
}
.sound-toggle {
  min-width: 72px; height: 40px; padding: 0 12px; border-radius: 12px; font-size: 12px; letter-spacing: 0.06em;
  border: 1px solid var(--line-brass); background: transparent; color: var(--ink-dim);
}
.sound-toggle.on { color: var(--brass-hi); border-color: var(--brass); background: rgba(201, 164, 106, 0.12); }
.sound-vol { width: 150px; height: 40px; margin: 0; accent-color: var(--brass); background: transparent; }
.sound-menu.muted .sound-vol { opacity: 0.45; }
@media (max-width: 370px) { .sound-vol { width: 120px; } }

/* v29b: 鑑定の場（z-index 30）の上にも音のボタンと板を出す */
.revealing .sound-btn, .revealing .sound-menu { z-index: 31; }

/* v31: 出典（スタート画面の下に小さく 1 行） */
.overlay p.credit {
  position: absolute; left: 16px; right: 16px; bottom: calc(var(--safe-b) + 14px); margin: 0;
  font-size: 11px; line-height: 1.5; letter-spacing: 0.02em; color: var(--ink-dim); opacity: 0.8; text-align: center;
}
.overlay p.credit a { white-space: nowrap; color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* v34: 段落の折り返し（日本語）。文節で折り返し、最後の行に 1〜2 文字だけ残さない。
   中央揃えの短い文は行の長さをそろえ、複数行の説明文は左揃えにする */
.overlay p, .banner .note, .reveal-remark, .show-sheet p { text-wrap: pretty; word-break: auto-phrase; line-break: strict; }
.overlay p:not(.credit), .banner .title, .banner .note.back { text-wrap: balance; }
.banner .title { line-height: 1.3; }
.banner .title small { display: block; margin-top: 6px; font-family: var(--sans, inherit); font-size: 13px; letter-spacing: 0.06em; white-space: nowrap; }
.banner .note:not(.back) { text-align: left; }
/* v34: 区切りの中では折り返さない（区切りより狭い画面ではその中でも折り返す） */
.ph { display: inline-block; max-width: 100%; }
.banner .actions .btn { white-space: nowrap; }
@media (max-width: 360px) { .banner .actions .btn { padding-left: 10px; padding-right: 10px; font-size: 14px; letter-spacing: 0.02em; } }
/* v34: 320px 幅でも上段が収まるように（仕舞うが無いときも詰める） */
@media (max-width: 350px) {
  html.release .topbar { gap: 4px; }
  html.release .topbar .auto-btn, html.release .topbar .flip-btn, html.release .topbar .restart-btn, html.release .topbar .store-btn { padding: 0 6px; font-size: 11px; letter-spacing: 0; }
  html.release .topbar .show-top { padding: 0 9px 0 7px; font-size: 12px; gap: 4px; }
}
/* v35: 鑑定の場の下に「他のゲームも遊ぶ」（sonchofox.com 版だけ） */
.reveal-more-games { display: block; width: max-content; margin: 12px auto 0; padding: 8px 12px; font-size: 13px; letter-spacing: 0.06em;
  color: var(--ink-dim); text-decoration: underline; text-underline-offset: 4px; }
.reveal-more-games:active { color: var(--brass); }

/* v41（sonchofox-web #171）: 鑑定の板の下、「他のゲームも遊ぶ」の横に、別のゲームへのアイコン（sonchofox.com 版だけ） */
.reveal-more-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; }
.reveal-more-row .reveal-more-games { margin: 0; }
.reveal-cross { flex: 0 0 auto; display: block; width: 40px; height: 40px; border-radius: 50%; overflow: hidden; border: 1px solid var(--line-brass); background: #f4e6cf; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); -webkit-tap-highlight-color: transparent; }
.reveal-cross img { display: block; width: 100%; height: 100%; object-fit: cover; }
.reveal-cross:active { transform: scale(0.94); }

/* v42: 「何をシェアする？」（鑑定の場の上） */
.share-pick-backdrop { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(8, 8, 7, 0.62); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.share-pick { width: min(340px, 100%); display: flex; flex-direction: column; align-items: stretch; gap: 12px; padding: 20px 18px 12px; border-radius: 22px;
  background: var(--panel-solid); border: 1px solid var(--line); border-top: 1px solid var(--line-brass); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55); }
.share-pick-title { margin: 0 0 4px; text-align: center; font-family: var(--mincho); font-size: 20px; letter-spacing: 0.08em; color: var(--brass); }
.share-pick-image { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 12px 10px; border-radius: 16px;
  border: 1px solid var(--line-brass); background: rgba(22, 21, 19, 0.6); color: var(--ink); }
.share-pick-image:active { transform: scale(0.98); }
.share-pick-thumb { display: block; width: 100%; max-width: 220px; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #000; }
.share-pick-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.share-pick-label { font-size: 16px; font-weight: 700; letter-spacing: 0.12em; color: var(--brass); }
.share-pick-text { min-height: 46px; font-size: 14px; letter-spacing: 0.08em; }
.share-pick-close { min-height: 40px; font-size: 13px; color: var(--ink-dim); }
