/* ヨイショ餅つき - Yoisho Mochitsuki */

:root {
  --cream: #fff6e3;
  --paper: #fffbf2;
  --ink: #2b1d14;
  --ink-dim: #6e5a4a;
  --red: #d7263d;
  --red-d: #a8172b;
  --indigo: #1f3a68;
  --gold: #f2b134;
  --wood: #8a5a34;
  --green: #4f9a5c;
  --kohaku: repeating-linear-gradient(90deg, var(--red) 0 22px, #fffaf0 22px 44px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(242, 177, 52, 0.22), transparent 60%),
    var(--cream);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  touch-action: manipulation;
  color: inherit;
}

#app {
  min-height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex: none;
}
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.icon-btn:focus-visible, .btn:focus-visible, .start-btn:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: 2px;
}

/* ===================== ホーム ===================== */

#screen-home {
  flex: 1;
  width: min(580px, 100%);
  margin: 0 auto;
  padding: 14px 16px 8px;
  display: flex;
  flex-direction: column;
}

#home-head {
  position: relative;
  text-align: center;
  padding: 6px 0 4px;
}
#home-head-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
#logo-kicker {
  display: inline-block;
  margin: 6px 0 0;
  padding: 3px 12px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  border-radius: 6px;
  transform: rotate(-2deg);
}
#logo {
  margin: 4px 0 6px;
  line-height: 1.02;
  font-weight: 900;
  letter-spacing: 0.02em;
}
#logo span {
  display: block;
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
  text-shadow: 5px 5px 0 var(--ink);
}
.logo-a {
  font-size: clamp(38px, 11vw, 56px);
  color: var(--red);
  transform: rotate(-3deg);
}
.logo-b {
  font-size: clamp(52px, 16vw, 82px);
  color: #fff;
}
#tagline {
  margin: 8px 0 4px;
  font-size: 14.5px;
  line-height: 1.65;
  font-weight: 700;
}
#tagline b { color: var(--red); }

#home-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.mode-card {
  position: relative;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 14px 14px 14px;
  overflow: hidden;
}
.mode-main { padding-top: 22px; }
.mode-main::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 9px;
  background: var(--kohaku);
  border-bottom: 2px solid var(--ink);
}
.mode-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.mode-emoji {
  font-size: 30px;
  line-height: 1;
  flex: none;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffe9c7;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
}
.mode-name {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 900;
}
.mode-desc {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-dim);
}
.mode-desc b { color: var(--ink); }

.start-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 14px 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--red);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.06em;
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(43, 29, 20, 0.55);
}
.start-btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.best-chip {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-shadow: none;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
}

.howto {
  margin: 8px 0 0;
  padding-left: 1.4em;
  font-size: 13.5px;
  line-height: 1.7;
}
.howto li { margin-bottom: 4px; }
.howto b { background: linear-gradient(transparent 60%, rgba(242, 177, 52, 0.6) 60%); }

.waza {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.waza li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-dim);
}
.waza b { color: var(--ink); }
.waza-emoji {
  flex: none;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
}

#footer {
  margin-top: auto;
  padding: 18px 0 14px;
  text-align: center;
  font-size: 12px;
  line-height: 1.8;
  color: var(--ink-dim);
}
#footer a { color: var(--ink); }

/* ===================== ゲーム画面 ===================== */

#screen-game {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  min-height: 320px;
  padding: 8px 10px 6px;
  gap: 6px;
}

#game-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
#hud-usu {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
#hud-usu-no {
  flex: none;
  font-weight: 900;
  font-size: 15px;
  background: var(--red);
  color: #fff;
  padding: 3px 9px;
  border: 2px solid var(--ink);
  border-radius: 8px;
}
#hud-prog {
  position: relative;
  flex: 1;
  min-width: 40px;
  height: 14px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}
#hud-prog-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #f6ecd8, #fff 60%, #ffe28a);
  border-right: 2px solid rgba(43, 29, 20, 0.35);
  transition: width 0.18s ease-out;
}
#hud-miss {
  flex: none;
  display: flex;
  gap: 3px;
}
#hud-miss i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
}
#hud-miss i.on { background: #8e8e8e; }
#hud-miss.bump { animation: miss-shake 0.45s; }
@keyframes miss-shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}
#hud-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
  flex: none;
  min-width: 4.4em;
}
.hud-label { font-size: 9.5px; font-weight: 800; letter-spacing: 0.1em; color: var(--ink-dim); }
#hud-score-val { font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 3px solid var(--ink);
  border-radius: 16px;
  overflow: hidden;
  background: #d9bf8f;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
  outline: none;
}
#stage:focus-visible { box-shadow: 0 0 0 3px var(--indigo); }
#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hint {
  flex: none;
  text-align: center;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--ink-dim);
  min-height: 1.4em;
}

/* お知らせ（臼の番号など） */
#toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  max-width: calc(100% - 24px);
  padding: 6px 16px 7px;
  background: rgba(255, 251, 242, 0.95);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  pointer-events: none;
  text-align: center;
}
#toast b { font-size: 17px; font-weight: 900; color: var(--red); }
#toast span { font-size: 12.5px; font-weight: 800; }
#toast.show { animation: toast-in 0.3s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes toast-in {
  from { transform: translate(-50%, -14px) scale(0.9); opacity: 0; }
  to { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* 説明カード・一時停止 */
#card, #pause-ov {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(43, 29, 20, 0.45);
}
#card-box, #pause-box {
  position: relative;
  width: min(360px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 18px 16px 16px;
  text-align: center;
  animation: pop-in 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
  cursor: default;
}
#card-box::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 9px;
  background: var(--kohaku);
  border-bottom: 2px solid var(--ink);
}
@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
#card-kicker { font-size: 12.5px; font-weight: 900; letter-spacing: 0.12em; color: var(--red); margin-top: 4px; }
#card-emoji { font-size: 44px; line-height: 1.2; margin: 2px 0; }
#card-title { font-size: 22px; font-weight: 900; margin-bottom: 8px; }
#card-desc {
  margin: 0 0 14px;
  padding: 0 0 0 1.2em;
  text-align: left;
  font-size: 13.5px;
  line-height: 1.7;
}
#card-desc li { margin-bottom: 4px; }
#card-desc li:only-child { list-style: none; margin-left: -1.2em; }
#card-desc b { background: linear-gradient(transparent 60%, rgba(242, 177, 52, 0.6) 60%); }
#pause-title { font-size: 22px; font-weight: 900; margin-top: 2px; }
#pause-box p { margin: 6px 0 14px; font-size: 13px; color: var(--ink-dim); }
.pause-btns { display: flex; gap: 10px; justify-content: center; }

/* ===================== ボタン ===================== */

.btn {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn-primary { background: var(--red); color: #fff; }
.btn-sub { background: #fff; color: var(--ink); }

/* ===================== 結果 ===================== */

#result-overlay, #howto-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + var(--sgh-top, 0px));
  padding-bottom: calc(16px + var(--ad-space, 0px));
  background: rgba(43, 29, 20, 0.55);
}
#result-box, #howto-box {
  position: relative;
  width: min(380px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 6px 6px 0 var(--ink);
  padding: 22px 18px 18px;
  text-align: center;
  animation: pop-in 0.32s cubic-bezier(0.2, 1.4, 0.4, 1);
}
#result-box::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 10px;
  background: var(--kohaku);
  border-bottom: 2px solid var(--ink);
}
#result-kicker { font-size: 12px; font-weight: 900; letter-spacing: 0.16em; color: var(--ink-dim); }
#result-title { font-size: 26px; font-weight: 900; color: var(--red); margin-top: 2px; }
#result-reason { font-size: 13px; font-weight: 800; margin-top: 2px; }
#result-score { margin: 8px 0 2px; font-weight: 900; }
#result-value { font-size: 46px; font-variant-numeric: tabular-nums; }
.result-unit { font-size: 18px; margin-left: 4px; }
#result-best {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 12px;
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  animation: best-glow 1s infinite alternate;
}
@keyframes best-glow {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}
#result-list {
  list-style: none;
  margin: 8px 0 14px;
  padding: 8px 12px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  font-size: 14px;
}
#result-list li {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(43, 29, 20, 0.25);
}
#result-list li:last-child { border-bottom: none; }
#result-buttons { display: flex; gap: 10px; justify-content: center; }

#howto-box { text-align: left; }
#howto-box h2 { margin: 0 0 6px; font-size: 20px; text-align: center; }
#howto-box .btn { display: block; margin: 14px auto 0; }

@media (max-height: 560px) {
  #logo-kicker { margin-top: 0; }
  .logo-b { font-size: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  #toast.show, #card-box, #pause-box, #result-box, #howto-box, #result-best { animation: none; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden { display: none !important; }

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(43, 29, 20, 0.6);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 18px 16px;
  box-shadow: 6px 6px 0 var(--ink);
}
.sgr-title { margin: 0; font-size: 20px; font-weight: 900; text-align: center; }
.sgr-tabs { display: flex; gap: 6px; justify-content: center; }
.sgr-tab {
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.sgr-tab-active { background: var(--gold); }
.sgr-register-msg { margin: 0 0 6px; font-size: 14px; font-weight: 800; color: var(--red); text-align: center; }
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.sgr-name:focus { outline: 3px solid var(--gold); outline-offset: 0; }
.sgr-submit {
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--red);
  color: #fff;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
.sgr-submit:disabled { opacity: 0.5; cursor: default; }
.sgr-error { margin: 4px 0 0; font-size: 12px; font-weight: 700; color: var(--red); }
.sgr-status { margin: 0; font-size: 13px; color: var(--ink-dim); text-align: center; }
.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  border-top: 2px dashed rgba(43, 29, 20, 0.25);
}
.sgr-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 14px; }
.sgr-row:nth-child(even) { background: rgba(215, 38, 61, 0.07); }
.sgr-row.sgr-row-me { background: var(--gold); font-weight: 800; }
.sgr-rank { width: 2em; text-align: right; font-weight: 900; flex-shrink: 0; }
.sgr-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sgr-row-score { font-weight: 900; color: var(--red); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.sgr-row.sgr-row-me .sgr-row-score { color: var(--ink); }
.sgr-close {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
.sgr-close:active, .sgr-cta-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.sgr-cta { margin: 0 0 12px; text-align: center; }
.sgr-cta-msg { margin: 0 0 6px; font-size: 14px; font-weight: 900; color: var(--red); }
.sgr-cta-btn {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}
.sgr-cta-link {
  border: none;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
