/* ==========================================================================
   ティッシュ出しきり（tissue-dashikiri）
   あたたかい部屋の色。クリーム・ピンク・水色
   ========================================================================== */
:root {
  --navy: #fff1e2;
  --ink: #4a3530;
  --snow: #4a3530;
  --snow-dim: #7d6259;
  --gold: #ffcf4a;
  --red: #ff5a6e;
  --pink: #ff7fa3;
  --cyan: #2b9fd6;
  --green: #1fa866;
  --panel: rgba(255, 252, 247, 0.94);
  --line: rgba(120, 84, 70, 0.24);
  --sgh-top: 0px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy);
  color: var(--snow);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  overflow: hidden;
  background: var(--navy);
}

/* ---------- ゲーム画面（キャンバス） ---------- */
#stage {
  position: absolute;
  inset: 0;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
#stage:active { cursor: grabbing; }
#cv, #fx { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
#fx { pointer-events: none; }   /* 3D の上に重ねる 2D（ひっぱりメーター） */
.nogl {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(86%, 420px); margin: 0; padding: 16px 18px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.94); color: var(--ink); font-weight: 700; line-height: 1.7; text-align: center;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: calc(8px + env(safe-area-inset-left, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.hud-chip {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 8px rgba(90, 50, 30, 0.12);
}
.hud-chip b { font-size: 17px; font-weight: 900; }
.hud-chip small { font-size: 11px; font-weight: 700; color: var(--snow-dim); }
#hud-best { margin-left: auto; }
#hud .icon-btn { pointer-events: auto; }

.icon-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--snow);
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:focus-visible, .btn:focus-visible, .mode-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

#hud-time {
  position: absolute;
  top: calc(52px + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font-weight: 900;
  font-style: italic;
  font-size: 54px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 3px 0 var(--ink), 0 0 14px rgba(74, 53, 48, 0.55);
}
#hud-time small { font-size: 20px; margin-left: 4px; }
#hud-time.done { color: var(--gold); }

#bar {
  position: absolute;
  top: calc(114px + env(safe-area-inset-top, 0px));
  left: 50%;
  width: min(300px, 70%);
  height: 10px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(74, 53, 48, 0.28);
  border: 2px solid #fff;
  pointer-events: none;
}
#bar-fill {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink), var(--gold));
  transform-origin: left center;
  transform: scaleX(0);
}
#bar-ghost {
  position: absolute;
  top: -13px;
  left: 0;
  width: 0;
  height: 0;
  margin-left: -6px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 9px solid var(--ink);
}
#split {
  position: absolute;
  top: calc(132px + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font-size: 20px;
  font-weight: 900;
  font-style: italic;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 2px 0 var(--ink);
  animation: splitin 1.3s ease-out both;
}
#split.fast { color: #8dffbe; }
#split.slow { color: #ffb1b9; }
@keyframes splitin {
  0% { transform: translateY(8px) scale(0.8); opacity: 0; }
  12% { transform: translateY(0) scale(1.1); opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#banner {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: 10px 26px;
  border-radius: 18px;
  background: var(--panel);
  border: 2px solid #fff;
  box-shadow: 0 8px 26px rgba(90, 50, 30, 0.3);
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}
#banner b { display: block; font-size: 46px; font-weight: 900; font-style: italic; color: var(--pink); animation: pop 0.3s cubic-bezier(0.2, 1.6, 0.4, 1); }
#banner.go { background: var(--pink); }
#banner.go b { color: #fff; }
#banner.tear { background: var(--red); color: #fff; top: 56%; }
#banner.tear b { color: #fff; font-size: 30px; }
#banner.fin { background: var(--gold); }
#banner.fin b { color: var(--ink); font-size: 36px; }

#prompt {
  position: absolute;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(90, 50, 30, 0.14);
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(74, 53, 48, 0.4);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#title-overlay { background: linear-gradient(180deg, rgba(255, 241, 226, 0.1), rgba(255, 241, 226, 0.5)); }
.overlay-box {
  position: relative;
  width: min(400px, 100%);
  margin: auto;
  padding: 20px 18px 16px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 44px rgba(90, 50, 30, 0.3);
  text-align: center;
}
.overlay-title { margin: 0 0 10px; font-size: 22px; font-weight: 900; }
.overlay-text { margin: 0 0 14px; font-size: 14px; color: var(--snow-dim); line-height: 1.6; }

#title-head { margin-bottom: 8px; }
#logo-kicker {
  display: inline-block;
  margin: 0 0 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 127, 163, 0.16);
  color: #e0527c;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
#logo {
  margin: 0;
  font-size: clamp(24px, 8.2vw, 38px);
  white-space: nowrap;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: var(--pink);
  text-shadow: 0 2px 0 #fff, 0 4px 0 rgba(74, 53, 48, 0.16);
}
#logo-en { margin: 4px 0 0; font-size: 12px; font-weight: 900; letter-spacing: 0.42em; color: var(--cyan); padding-left: 0.42em; }
#tagline { margin: 8px 0 12px; font-size: 14px; line-height: 1.6; color: var(--snow-dim); }
#tagline b { color: var(--ink); }

/* モード選択 */
#mode-list { display: grid; gap: 8px; margin-bottom: 10px; }
.mode-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid #fff;
  background: linear-gradient(180deg, #ffe58a, var(--gold));
  box-shadow: 0 4px 0 #c79412;
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.08s;
}
#btn-mode-roll { background: linear-gradient(180deg, #bfe9ff, #8fd3f7); box-shadow: 0 4px 0 #4b9cc6; }
.mode-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #c79412; }
#btn-mode-roll:active { box-shadow: 0 2px 0 #4b9cc6; }
.mode-ico { position: relative; width: 46px; height: 46px; flex-shrink: 0; }
/* 箱ティッシュ（CSS だけで描く） */
.mode-ico-tissue::before {
  content: "";
  position: absolute;
  left: 3px; right: 3px; bottom: 5px; height: 20px;
  border-radius: 4px;
  background: #6cc5b4;
  border: 2px solid var(--ink);
}
.mode-ico-tissue::after {
  content: "";
  position: absolute;
  left: 13px; bottom: 23px; width: 20px; height: 19px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 9px 12px 2px 2px / 14px 10px 2px 2px;
  transform: rotate(-6deg);
}
/* トイレットペーパー */
.mode-ico-roll::before {
  content: "";
  position: absolute;
  left: 5px; top: 5px; width: 30px; height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle, #b98d62 0 4px, var(--ink) 4px 6px, #fff 6px);
  border: 2px solid var(--ink);
}
.mode-ico-roll::after {
  content: "";
  position: absolute;
  left: 23px; top: 19px; width: 14px; height: 23px;
  background: #fff;
  border: 2px solid var(--ink);
  border-top: none;
  border-radius: 0 0 3px 3px;
}
.mode-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mode-txt b { font-size: 17px; font-weight: 900; white-space: nowrap; }
.mode-txt small { font-size: 12px; font-weight: 700; opacity: 0.8; }
.mode-best { flex-shrink: 0; font-size: 13px; font-weight: 900; font-variant-numeric: tabular-nums; padding: 3px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.7); white-space: nowrap; }

.btn {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.08s;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  background: linear-gradient(180deg, #ffe58a, var(--gold));
  color: var(--ink);
  border-color: #fff;
  box-shadow: 0 4px 0 #c79412;
}
.btn-primary:active { box-shadow: 0 2px 0 #c79412; }
.btn-sub { background: rgba(120, 84, 70, 0.08); color: var(--snow); font-size: 14px; padding: 11px 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

#title-box #btn-sound, #title-box #btn-restart { position: absolute; top: 10px; right: 10px; }

.howto-head { margin: 10px 0 2px; font-size: 14px; font-weight: 900; text-align: left; color: #e0527c; }
.howto {
  margin: 4px 0 8px;
  padding: 0 0 0 1.4em;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  color: var(--snow-dim);
}
.howto li { margin-bottom: 4px; }
.howto b, .howto-note b { color: var(--ink); }
.howto .c-red { color: var(--red); }
.howto-note { margin: 6px 0 12px; padding: 9px 12px; border-radius: 12px; background: rgba(120, 84, 70, 0.07); text-align: left; font-size: 12.5px; line-height: 1.6; color: var(--snow-dim); }

#footer { margin-top: 4px; font-size: 11px; line-height: 1.6; color: var(--snow-dim); }
#footer a { color: inherit; }

/* ---------- 結果 ---------- */
#result-rank-name { font-size: 15px; font-weight: 900; color: var(--cyan); letter-spacing: 0.06em; }
#result-score { font-size: 60px; font-weight: 900; line-height: 1.1; color: var(--pink); font-variant-numeric: tabular-nums; }
#result-score small { font-size: 24px; margin-left: 4px; }
#result-new { margin: 2px 0 8px; font-size: 15px; font-weight: 900; color: var(--green); animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
#result-why { margin: 2px 0 8px; font-size: 13px; font-weight: 800; color: var(--snow-dim); line-height: 1.5; }
#result-list { list-style: none; margin: 8px 0 14px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#result-list li { padding: 7px 4px; border-radius: 10px; background: rgba(120, 84, 70, 0.08); display: flex; flex-direction: column; gap: 2px; }
#result-list span { font-size: 11px; color: var(--snow-dim); font-weight: 700; }
#result-list b { font-size: 16px; font-weight: 900; }

@media (max-width: 380px) {
  .hud-chip { padding: 5px 9px; font-size: 11.5px; }
  .hud-chip b { font-size: 15px; }
  #hud .icon-btn { width: 34px; height: 34px; font-size: 14px; }
  .mode-txt b { font-size: 15px; }
  .mode-btn { gap: 8px; padding: 9px 10px; }
}
@media (max-height: 620px) {
  .overlay-box { padding: 14px 14px 12px; }
  #tagline { margin: 4px 0 8px; font-size: 13px; }
  #result-score { font-size: 46px; }
  #hud-time { font-size: 40px; top: calc(48px + env(safe-area-inset-top, 0px)); }
  #bar { top: calc(94px + env(safe-area-inset-top, 0px)); }
  #split { top: calc(108px + env(safe-area-inset-top, 0px)); font-size: 17px; }
}
@media (max-height: 440px) {
  #logo-kicker, #logo-en, #tagline { display: none; }
  #logo { font-size: 26px; }
  #mode-list { grid-template-columns: 1fr 1fr; }
  .mode-btn { padding: 7px 8px; gap: 6px; }
  .mode-ico { display: none; }
  .mode-txt b { font-size: 14px; }
  .btn { padding: 9px 12px; margin-bottom: 6px; }
  #hud-time { font-size: 32px; top: calc(10px + env(safe-area-inset-top, 0px)); }
  #bar { top: calc(48px + env(safe-area-inset-top, 0px)); width: min(240px, 40%); }
  #split { top: calc(62px + env(safe-area-inset-top, 0px)); }
  #result-list { display: none; }
  .howto { font-size: 12px; line-height: 1.45; }
}
@media (min-width: 768px) {
  .hud-chip { font-size: 15px; padding: 8px 14px; }
  .hud-chip b { font-size: 20px; }
  #hud-time { font-size: 68px; }
  #bar { top: calc(130px + env(safe-area-inset-top, 0px)); }
  #split { top: calc(150px + env(safe-area-inset-top, 0px)); font-size: 24px; }
  #prompt { font-size: 17px; }
}
@media (min-width: 900px) {
  /* 広い画面では、うしろの箱やロールが見えるようにタイトルの箱を右へ寄せる */
  #title-overlay { justify-content: flex-end; padding-right: 5vw; }
  #title-overlay .overlay-box { margin: auto 0; }
}
@media (prefers-reduced-motion: reduce) {
  #banner b, #result-new, #split { 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(74, 53, 48, 0.6);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fffaf3;
  color: var(--snow);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 16px 44px rgba(90, 50, 30, 0.4);
}
.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: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  background: rgba(120, 84, 70, 0.08);
  color: var(--snow);
  cursor: pointer;
}
.sgr-tab-active { background: var(--gold); color: var(--ink); }
.sgr-register-msg { margin: 0 0 6px; font-size: 14px; font-weight: 800; color: #e0527c; text-align: center; }
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.sgr-name:focus { outline: 3px solid var(--cyan); outline-offset: 0; }
.sgr-submit {
  border: 1px solid #fff;
  border-radius: 10px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
}
.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(--snow-dim); text-align: center; }
.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  border-top: 1px solid var(--line);
}
.sgr-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; font-size: 14px; }
.sgr-row:nth-child(even) { background: rgba(120, 84, 70, 0.06); }
.sgr-row.sgr-row-me { background: var(--gold); color: var(--ink); 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: #e0527c; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.sgr-row.sgr-row-me .sgr-row-score { color: var(--ink); }
.sgr-close {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  background: rgba(120, 84, 70, 0.09);
  color: var(--snow);
  cursor: pointer;
}
.sgr-cta { margin: 0 0 12px; text-align: center; }
.sgr-cta-msg { margin: 0 0 6px; font-size: 14px; font-weight: 900; color: var(--green); }
.sgr-cta-btn {
  border: 1px solid #fff;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 #c79412;
}
.sgr-cta-link {
  border: none;
  background: none;
  color: var(--cyan);
  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; }
}
