:root {
  --paper: #f3ead6;
  --paper-2: #e9dcc0;
  --sumi: #2b2118;
  --muted: #6b5a48;
  --shu: #b8322a;
  --ai: #1f3a5f;
  --wood: #8a5a33;
  --wood-2: #b07a48;
  --brown: #4a230b;
  --line: rgba(43, 33, 24, .2);
  --vh: 100vh;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  color: var(--sumi);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body {
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  /* 和紙の地合い */
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, .5), transparent 40%),
    repeating-linear-gradient(115deg, rgba(120, 90, 50, .035) 0 2px, transparent 2px 7px),
    var(--paper);
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ai); outline-offset: 2px; }

/* ---------- 1画面に収める ---------- */
.app {
  max-width: 480px;
  height: var(--vh);
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.head { display: flex; align-items: center; gap: 10px; }
.title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: "Yuji Syuku", "Hiragino Mincho ProN", serif;
  font-weight: 400;
  font-size: clamp(21px, 6.6vw, 30px);
  line-height: 1.2;
  white-space: nowrap;
}
.title-btn { max-width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; white-space: inherit; overflow: inherit; text-overflow: inherit; cursor: pointer; }
html[lang="en"] .head .title-btn { display: block; overflow: hidden; text-overflow: ellipsis; }
html[lang="en"] .head .title { font-size: clamp(16px, 5.2vw, 26px); overflow: hidden; text-overflow: ellipsis; }
.menu-btn {
  flex: none;
  padding: 5px 12px;
  border: 1.5px solid var(--sumi);
  border-radius: 6px;
  background: rgba(255, 255, 255, .5);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.game-language a { color: var(--muted) !important; }
.game-language a[aria-current] { color: var(--sumi) !important; }

/* ---------- 屋台 ---------- */
.scene {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto 6px;
  grid-template-areas: "nobori sign" "nobori counter" "nobori bubble" "timer timer";
  column-gap: 10px;
  row-gap: 6px;
  padding: 10px 10px 10px;
  border: 2px solid var(--sumi);
  border-top-width: 6px;
  border-radius: 10px;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .06) 0 3px, transparent 3px 22px),
    linear-gradient(#efe2c4, #e4d2ab);
}
.scene.enter { animation: rise .25s ease-out; }
.scene.good { box-shadow: 0 0 0 3px #4f7f4a; }
.scene.miss { box-shadow: 0 0 0 3px var(--shu); animation: shake .45s ease both; }
.sign {
  grid-area: sign;
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 4px 14px;
  border: 2px solid var(--sumi);
  border-radius: 4px;
  background: linear-gradient(var(--wood-2), var(--wood));
  color: #fff8e8;
  box-shadow: 0 3px 0 rgba(43, 33, 24, .35);
}
.sign-label { flex: none; padding: 0 4px; border-radius: 3px; background: rgba(0, 0, 0, .25); font-size: 10px; font-weight: 700; }
#place {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: "Yuji Syuku", "Hiragino Mincho ProN", serif;
  font-size: clamp(17px, 5.4vw, 24px);
  line-height: 1.25;
}
.nobori {
  grid-area: nobori;
  align-self: stretch;
  position: relative;
  width: clamp(34px, 11vw, 48px);
  max-height: 280px;
  margin: 6px 0 4px;
  border-left: 3px solid var(--sumi);
}
.nobori span {
  position: absolute;
  inset: 0 0 12% 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--sumi);
  border-left: 0;
  background: var(--nobori, #9b9184);
  color: #fff;
  writing-mode: vertical-rl;
  font-family: "Yuji Syuku", "Hiragino Mincho ProN", serif;
  font-size: clamp(15px, 4.6vw, 21px);
  letter-spacing: .2em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
  transition: background-color .2s;
}
.counter {
  grid-area: counter;
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}
.cake {
  position: relative;
  width: min(78cqw, 96cqh, 230px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cake-bg);
  box-shadow: 0 0 0 2px rgba(43, 33, 24, .5), 0 8px 0 rgba(43, 33, 24, .18);
}
.cake::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 35%, rgba(255, 220, 160, .35), transparent 30%),
    radial-gradient(circle at 70% 65%, rgba(120, 50, 10, .25), transparent 35%);
}
/* ---------- 正解すると割れる ---------- */
.cake { --cake-bg: radial-gradient(circle at 50% 50%, #e9a24d 0 52%, #d0782a 66%, #a8541a 74%, #f1c27a 76% 82%, #e3a95d 88%, #c27a34 100%); }
.cake .half, .cake .core { position: absolute; inset: 0; pointer-events: none; }
.cake .half { border-radius: 50%; background: var(--cake-bg); box-shadow: 0 0 0 2px rgba(43, 33, 24, .5); transition: transform .28s cubic-bezier(.2, 1.4, .4, 1); }
.cake .half.left { clip-path: inset(-10% 50% -10% -10%); }
.cake .half.right { clip-path: inset(-10% -10% -10% 50%); }
.cake .half .stamp { transform: rotate(var(--turn, 0deg)); }
.cake.cracked > .stamp, .cake.cracked > .steam { visibility: hidden; }
.cake.cracked { background: transparent; box-shadow: none; }
.cake.cracked::before { display: none; }
.cake.cracked .half.left { transform: translateX(-16%) rotate(-10deg); }
.cake.cracked .half.right { transform: translateX(16%) rotate(10deg); }
/* 断面。皮の内側に中身が詰まっている */
.cake .core {
  inset: 6% 34%;
  border: 3px solid #e8b46a;
  border-radius: 45%;
  background: var(--filling, #4a1f24);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .15);
  transform: scaleX(.2);
  opacity: 0;
  transition: transform .28s ease-out, opacity .15s;
}
.cake.cracked .core { transform: scaleX(1); opacity: 1; }
.cake[data-filling="tsubu"] { --filling: radial-gradient(circle at 30% 30%, #7a3a44 0 7%, transparent 8%) 0 0 / 34% 22%, radial-gradient(circle at 70% 70%, #6b2f38 0 8%, transparent 9%) 0 0 / 30% 26%, #4a1f24; }
.cake[data-filling="koshi"] { --filling: #3b1a1f; }
.cake[data-filling="shiro"] { --filling: #efe2c6; }
.cake[data-filling="custard"] { --filling: radial-gradient(circle at 40% 30%, #fbe39a, transparent 50%), #f1c24a; }

.stamp {
  position: absolute;
  inset: 18%;
  color: var(--brown);
  transform: rotate(var(--turn, 0deg));
}
.stamp svg, .mini-cake svg { display: block; }
.stamp svg { width: 100%; height: 100%; }
.mini-cake svg { width: 68%; height: 68%; }
:is(.stamp, .mini-cake) svg * { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
:is(.stamp, .mini-cake) svg .fill { fill: currentColor; stroke: none; }
.btn svg { flex: none; }
.filling {
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 2px 8px;
  border: 1.5px dashed var(--muted);
  border-radius: 999px;
  background: rgba(255, 255, 255, .6);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.filling:empty { display: none; }
.bubble {
  grid-area: bubble;
  position: relative;
  margin: 0;
  padding: 6px 12px;
  border: 2px solid var(--sumi);
  border-radius: 14px;
  background: #fffaf0;
  text-align: center;
  font-size: clamp(14px, 4.2vw, 17px);
  font-weight: 700;
  line-height: 1.35;
}
.bubble::before {
  content: "";
  position: absolute;
  left: 18px;
  top: -9px;
  width: 14px;
  height: 14px;
  border-left: 2px solid var(--sumi);
  border-top: 2px solid var(--sumi);
  background: #fffaf0;
  transform: rotate(45deg);
}
.timer { grid-area: timer; margin: 0 -10px -10px; background: rgba(43, 33, 24, .12); }
.timer span { display: block; height: 100%; background: rgba(43, 33, 24, .55); transform-origin: left; }
.timer span.low { animation: blink .5s steps(2, end) infinite; }

/* 隠れた手がかり */
.hide-place #place { color: rgba(255, 248, 232, .55); }
.hide-nobori .nobori span { color: transparent; text-shadow: none; background: repeating-linear-gradient(45deg, #b3a997 0 6px, #a39985 6px 12px); }
.hide-line .bubble { color: var(--muted); }
.steam { position: absolute; inset: -6%; pointer-events: none; opacity: 0; transition: opacity .2s; }
.hide-stamp .steam { opacity: 1; }
.steam i {
  position: absolute;
  width: 55%;
  height: 55%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 68%);
  filter: blur(3px);
  animation: steam 3.2s ease-in-out infinite;
}
.steam i:nth-child(1) { left: 6%; top: 18%; }
.steam i:nth-child(2) { left: 40%; top: 6%; animation-delay: -1.1s; }
.steam i:nth-child(3) { left: 24%; top: 40%; animation-delay: -2.2s; }

/* ---------- 戦績・選択肢 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0; }
.stats div { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 3px 4px; border-bottom: 1.5px solid var(--line); }
.stats dt { color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.stats dd { margin: 0; font-size: 18px; font-weight: 900; line-height: 1.2; white-space: nowrap; }
.message { margin: 0; min-height: 1.4em; text-align: center; font-size: 15px; font-weight: 900; }

.choices, .actions { display: grid; gap: 8px; }
.choice, .btn {
  min-height: 46px;
  border: 2px solid var(--sumi);
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--sumi);
  transition: transform .08s, box-shadow .08s;
}
.choice:active, .btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--sumi); }
.choice {
  padding: 6px 12px;
  background: #fffaf0;
  font-size: 19px;
  letter-spacing: .04em;
}
.choice.right { background: #dcebd3; border-color: #2f5f2a; color: #1d3f19; }
.choice.wrong { background: #f3d2cc; border-color: var(--shu); color: #7a1a12; }
.choice:disabled { cursor: default; }
.actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  text-decoration: none;
  font-size: 15px;
}
.btn-main { background: var(--shu); color: #fff; font-size: 19px; letter-spacing: .08em; }
.btn-main:disabled { opacity: .5; }
.actions .btn-main { flex-direction: column; gap: 0; padding: 6px 4px; font-size: 17px; letter-spacing: .02em; line-height: 1.2; white-space: nowrap; }
.btn small { font-size: 11px; font-weight: 700; letter-spacing: 0; opacity: .9; }
.btn-hard { background: var(--sumi); }
.btn-wide { grid-column: 1 / -1; }
/* ---------- ドパガキモード ---------- */
:root { --rainbow: linear-gradient(90deg, #ff004c, #ff8a00, #ffe600, #2bff00, #00e5ff, #3d5afe, #d500f9, #ff004c); }
.btn-dopa { border-color: transparent; background: linear-gradient(#170c28, #170c28) padding-box, var(--rainbow) border-box; background-size: 100% 100%, 200% 100%; color: #fff; animation: rainbow 2s linear infinite; }
.choice.glow {
  border: 3px solid transparent;
  background: linear-gradient(#fffaf0, #fffaf0) padding-box, var(--rainbow) border-box;
  background-size: 100% 100%, 200% 100%;
  box-shadow: 0 3px 0 var(--sumi), 0 0 16px rgba(255, 0, 200, .55);
  animation: rainbow 1.2s linear infinite;
}
.choice.glow.right { background: linear-gradient(#dcebd3, #dcebd3) padding-box, var(--rainbow) border-box; background-size: 100% 100%, 200% 100%; }
body.dopa .scene { border-color: transparent; background: linear-gradient(#efe2c4, #e4d2ab) padding-box, var(--rainbow) border-box; background-size: 100% 100%, 200% 100%; animation: rainbow 3s linear infinite; }
.level { margin-left: 3px; padding: 0 4px; border-radius: 3px; background: var(--paper-2); font-size: 9px; }
.text-btn { margin-top: 8px; padding: 6px; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.btn-x { background: #fffaf0; color: var(--sumi); font-size: 14px; }
/* 共有メニューがない環境で、投稿文をコピーしたことを知らせる */
.snackbar {
  position: fixed; z-index: 100; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px);
  padding: 12px 18px; border: 2px solid var(--sumi); border-radius: 8px; background: #fffaf0; color: var(--sumi);
  box-shadow: 0 3px 0 var(--sumi); font-size: 14px; font-weight: 900;
  pointer-events: none;
}
.snackbar:empty { display: none; }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  background: rgba(43, 33, 24, .5);
  overflow-y: auto;
}
.panel {
  position: relative;
  width: min(100%, 460px);
  padding: 14px;
  border: 3px double var(--sumi);
  border-radius: 10px;
  background: var(--paper);
  text-align: center;
  animation: rise .25s ease-out;
}
.panel-title { margin: 0; font-family: "Yuji Syuku", "Hiragino Mincho ProN", serif; font-weight: 400; font-size: 24px; line-height: 1.3; }
.panel-lead { margin: 4px 0 10px; color: var(--muted); font-size: 12px; font-weight: 700; line-height: 1.5; }
.panel .btn { width: 100%; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.cards[data-count="1"] { grid-template-columns: minmax(0, 240px); justify-content: center; }
.cards[data-count="10"] { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.card { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; padding: 8px 5px; border: 1.5px solid var(--line); border-radius: 8px; background: #fbf4e2; }
.card-top { display: flex; align-items: center; gap: 6px; }
.swatch { flex: none; width: 12px; height: 44px; border: 1.5px solid var(--sumi); border-left-width: 3px; background: var(--nobori); }
.card b { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.card dl { display: grid; gap: 2px; width: 100%; margin: 0; text-align: left; }
.card dl div { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px; align-items: baseline; }
.card dt { padding: 0 3px; border-radius: 3px; background: var(--paper-2); color: var(--muted); font-size: 9px; font-weight: 700; white-space: nowrap; }
.card dd { margin: 0; font-size: 11px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.card.fresh { border-color: var(--shu); border-width: 2px; }
.card.fresh b { font-size: 19px; }
.card.fresh dd { font-size: 13px; }
.card.fresh dt { font-size: 11px; }
.mini-cake {
  width: 58px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--brown);
  background: radial-gradient(circle, #e9a24d 0 55%, #c27a34 72%, #f1c27a 78%, #c27a34 100%);
}
.card.fresh .mini-cake { width: 86px; }
.card.fresh .swatch { height: 64px; width: 16px; }
.answer { display: grid; justify-content: center; grid-template-columns: minmax(0, 260px); margin: 8px 0; }
.result-score { margin: 0; font-size: 24px; font-weight: 900; line-height: 1.3; color: var(--shu); }
.result-score:not([data-best=""])::after { content: attr(data-best); display: block; font-size: 13px; color: #2f5f2a; }
.result-rank { margin: 2px 0 6px; font-family: "Yuji Syuku", "Hiragino Mincho ProN", serif; font-size: 18px; }
.truth { margin: 0 0 10px; color: var(--muted); font-size: 10.5px; line-height: 1.5; text-align: left; }
/* 自動で閉じるダイアログは、閉じるまでの残り時間を下の線で見せる */
.overlay.auto .panel::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 6px; height: 4px; border-radius: 2px; background: var(--rainbow); transform-origin: left; animation: autoclose 1s linear forwards; }
@keyframes autoclose { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.menu-panel { text-align: left; }
.menu-close { position: absolute; top: 4px; right: 6px; width: 40px; height: 40px; border: 0; background: none; font-size: 24px; cursor: pointer; }
.menu-label { margin: 10px 0 6px; color: var(--muted); font-size: 12px; letter-spacing: .1em; }
.menu-label:first-of-type { margin-top: 0; }
.howto { margin: 0 0 10px; padding-left: 1.4em; font-size: 13px; line-height: 1.6; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 6px 8px;
  border: 1.5px solid var(--sumi);
  border-radius: 8px;
  background: #fffaf0;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}
#bookBtn { width: 100%; }
.sound-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 4px; }
.menu-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.menu-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 12px; font-size: 12px; }
.menu-links a { padding: 4px 0; color: var(--muted); }
.menu-reset { margin-left: auto; padding: 4px 8px; border: 1px solid var(--shu); border-radius: 6px; background: none; color: var(--shu); font-size: 12px; cursor: pointer; }

/* X内ブラウザなど、縦が短い画面 */
@media (max-height: 600px) {
  .app { gap: 5px; }
  .scene { row-gap: 4px; padding-top: 6px; grid-template-rows: auto minmax(0, 1fr) auto 5px; }
  .sign { padding: 2px 12px; }
  #place { font-size: 18px; }
  .bubble { padding: 4px 10px; font-size: 14px; }
  .choice { min-height: 40px; font-size: 17px; }
  .choices { gap: 6px; }
  .stats div { padding: 1px 4px; }
  .stats dd { font-size: 15px; }
  .message { font-size: 13px; }
  .panel { padding: 10px; }
  .panel-title { font-size: 20px; }
  .mini-cake { width: 48px; }
  .swatch { height: 36px; }
}
@media (max-width: 360px) {
  .actions .btn-main { font-size: 15px; }
  .btn small { font-size: 9.5px; }
  .stats dt { font-size: 10px; }
  .stats div { gap: 3px; }
  .card dd { font-size: 10px; }
  .card b { font-size: 12px; overflow-wrap: normal; word-break: keep-all; }
}

@keyframes rainbow { to { background-position: 0 0, 200% 0; } }
@keyframes blink { 50% { opacity: .25; } }
@keyframes rise { from { transform: translateY(8px); opacity: .4; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes steam { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(12%, -8%) scale(1.2); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
