/* =========================================================
 * irochigai（色ちがい探し） スタイル
 * 和紙の生成り色の上に、だるまを並べる。盤面の地は色の見え方が偏らないよう無彩色に近づける
 * ========================================================= */
:root {
  --font-jp: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  --font-mincho: Georgia, "Times New Roman", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-bg: #f3eee3;
  --c-paper: #fbf8f1;
  --c-board: #f6f5f2;
  --c-ink: #2b2420;
  --c-dim: #7a6f64;
  --c-line: rgba(43, 36, 32, 0.14);
  --c-shu: #c84f0c;
  --c-shu-l: #eb6101;
  --c-ai: #1d5d7e;
  --c-ai-l: #2c7fa8;
  --c-gold: #c8962e;
  --c-gold-l: #e8b23a;
  --c-red: #c4302b;
  /* ランキング（sgr-*） */
  --c-sgr-text: #2b2420;
  --c-sgr-dim: #7a6f64;
  --c-sgr-line: rgba(43, 36, 32, 0.16);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-jp);
  color: var(--c-ink);
  background-color: var(--c-bg);
  /* 和紙のごく薄いむら（画像を使わない） */
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(255, 255, 255, 0.55), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(214, 200, 172, 0.25), transparent 60%);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button { font-family: inherit; }

/* ===== レイアウト =====
   共通ヘッダー(--sgh-top)とフッター広告(--ad-space)のぶんだけ内側に収める */
#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ===== 上部バー ===== */
#topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  height: 46px;
  padding: 0 12px;
}

#logo {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--c-ink);
}

.logo-b { color: var(--c-shu-l); }

.mode-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--c-shu);
  white-space: nowrap;
}

.mode-time .mode-badge { background: var(--c-ai); }
.is-title .mode-badge,
.is-result .mode-badge { visibility: hidden; }

#topbar-buttons {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--c-line);
  border-radius: 10px;
  background: var(--c-paper);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  color: var(--c-ink);
  touch-action: manipulation;
}

.icon-btn:hover { border-color: rgba(43, 36, 32, 0.35); }
.icon-btn:focus-visible { outline: 3px solid var(--c-ai-l); outline-offset: 1px; }

/* ===== ステージ ===== */
#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
}

.play-col {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  grid-template-areas: "hud" "bar" "board" "info";
  align-content: center;
  row-gap: 8px;
  padding: 4px 12px 4px;
}

/* ===== HUD ===== */
#hud {
  grid-area: hud;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.hud-cell--last { align-items: flex-end; }

.hud-label {
  font-size: 11px;
  color: var(--c-dim);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.hud-value {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-lives {
  display: flex;
  gap: 2px;
  height: 24px;
  align-items: center;
}

.life {
  width: 22px;
  height: 22px;
  color: var(--c-shu-l);
  transition: color 0.3s, opacity 0.3s, transform 0.3s;
}

.life svg { width: 100%; height: 100%; display: block; }

.life.is-lost {
  color: #ddd5c6;
  opacity: 0.55;
  transform: rotate(-24deg) translateY(2px);
}

/* 時間ゲージ */
#bar {
  grid-area: bar;
  height: 8px;
  border-radius: 999px;
  background: rgba(43, 36, 32, 0.1);
  overflow: hidden;
}

#bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--c-ai), var(--c-ai-l));
  transform-origin: left center;
  transition: background-color 0.3s;
  will-change: transform;
}

#bar-fill.is-low { background: linear-gradient(90deg, var(--c-red), #e0583a); }

/* ===== 盤面 ===== */
#board-area {
  grid-area: board;
  position: relative;
  min-height: 0;
  height: 300px; /* js の layoutBoard() が盤面の大きさに合わせる */
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  --bs: 300px;
  --n: 3;
  width: var(--bs);
  height: var(--bs);
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  gap: calc(var(--bs) * 0.01);
  padding: calc(var(--bs) * 0.022);
  background: var(--c-board);
  border: 1px solid var(--c-line);
  border-radius: 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 8px 22px rgba(70, 50, 30, 0.1);
  touch-action: manipulation;
}

#board.is-hidden { visibility: hidden; }

.tile {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 5%;
  border: 0;
  border-radius: 14%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tile svg {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 88%;
  pointer-events: none;
  transition: translate 0.15s, opacity 0.2s;
}

.tile:focus { outline: none; }
.tile:focus-visible { box-shadow: 0 0 0 3px var(--c-ai-l) inset; }

@media (hover: hover) {
  .tile:hover svg { translate: 0 -3%; }
}

.is-in .tile svg {
  animation: pop 0.3s cubic-bezier(0.3, 1.45, 0.5, 1) both;
  animation-delay: var(--d, 0ms);
}

@keyframes pop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.tile.is-hit svg { animation: hop 0.42s ease-out both; }

@keyframes hop {
  0% { transform: none; }
  35% { transform: translateY(-14%) scale(1.1) rotate(-7deg); }
  70% { transform: translateY(0) scale(0.97) rotate(3deg); }
  100% { transform: none; }
}

/* まちがえたら、だるまらしく起き上がりこぼしのようにゆれる */
.tile.is-miss svg { animation: wobble 1s ease-out both; }

@keyframes wobble {
  0% { transform: rotate(0); }
  12% { transform: rotate(22deg); }
  30% { transform: rotate(-15deg); }
  48% { transform: rotate(9deg); }
  66% { transform: rotate(-5deg); }
  84% { transform: rotate(2deg); }
  100% { transform: rotate(0); }
}

.tile.is-answer::after {
  content: "";
  position: absolute;
  inset: 1%;
  border-radius: 50%;
  border: 3px solid var(--c-gold-l);
  box-shadow: 0 0 0 4px rgba(232, 178, 58, 0.28), 0 0 18px rgba(232, 178, 58, 0.55);
  animation: answer 0.9s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes answer {
  from { transform: scale(0.94); opacity: 0.75; }
  to { transform: scale(1.04); opacity: 1; }
}

.is-solved .tile:not(.is-hit) svg { opacity: 0.55; }

.board-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(43, 36, 32, 0.86);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

.board-banner.is-show { animation: bannerShow 1.1s ease-out both; }

@keyframes bannerShow {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.9); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(0.98); }
}

/* 一時停止（盤面の上に重ねる） */
#screen-paused {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.paused-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 26px 30px;
  border: 1px solid var(--c-line);
  border-radius: 18px;
  background: var(--c-paper);
  color: var(--c-ink);
  box-shadow: 0 10px 30px rgba(70, 50, 30, 0.16);
  cursor: pointer;
}

.paused-title { font-size: 22px; font-weight: 800; }
.paused-hint { font-size: 13px; color: var(--c-dim); }

/* ===== 盤面の下の案内・答え合わせ ===== */
#info {
  grid-area: info;
  height: 104px;
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  overflow: hidden;
}

.info-msg {
  margin: 0;
  font-size: 15px;
  color: var(--c-dim);
}

.info-msg.is-ok { color: var(--c-ink); font-weight: 700; animation: msgIn 0.25s ease-out both; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.info-colors {
  width: 100%;
  animation: msgIn 0.25s ease-out both;
  cursor: pointer;
}

.info-head {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 800;
  color: var(--c-red);
}

.sw-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.sw {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  text-align: left;
}

.sw-chip {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(43, 36, 32, 0.25);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

.sw-chip--odd { box-shadow: 0 0 0 3px rgba(232, 178, 58, 0.6); }

.sw-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.sw-text b { font-size: 14px; white-space: nowrap; }
.sw-text small { font-size: 11px; color: var(--c-dim); white-space: nowrap; }
.sw-text code { font-family: var(--font-num); font-size: 11px; color: var(--c-dim); }

.sw-vs { color: var(--c-dim); font-size: 16px; }

.info-skip {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--c-dim);
}

/* ===== 演出 ===== */
#floats {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 6;
}

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-num);
  font-weight: 800;
  font-size: 18px;
  white-space: nowrap;
  text-shadow: 0 1px 0 #fff, 0 0 6px rgba(255, 255, 255, 0.9);
  animation: floatUp 0.95s ease-out both;
}

.float.is-pts { color: var(--c-shu); }
.float.is-miss { color: var(--c-red); font-family: var(--font-jp); font-size: 16px; }

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.06); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 3px solid var(--c-gold-l);
  transform: translate(-50%, -50%) scale(0.6);
  animation: ring 0.6s ease-out both;
}

@keyframes ring {
  from { opacity: 1; transform: translate(-50%, -50%) scale(0.6); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}

.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  animation: spark 0.6s ease-out both;
}

@keyframes spark {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

/* ===== 画面（タイトル・リザルト） ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10px 12px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* タイトル・リザルトを出している間は盤面を隠す（背景の和紙をそのまま見せる） */
.is-title .play-col,
.is-result .play-col { visibility: hidden; }

.panel {
  width: 100%;
  max-width: 500px;
  margin: auto;
  padding: 20px 18px 18px;
  border: 1px solid var(--c-line);
  border-radius: 22px;
  background: var(--c-paper);
  box-shadow: 0 10px 30px rgba(70, 50, 30, 0.1);
  text-align: center;
}

.title-en {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--c-dim);
}

.title-ja {
  margin: 2px 0 8px;
  font-family: var(--font-mincho);
  font-size: clamp(36px, 11vw, 48px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.04em;
}

.demo-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 2px 0 2px;
}

.demo-daruma {
  width: clamp(48px, 15vw, 64px);
  aspect-ratio: 1;
  padding: 3px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.demo-daruma svg {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 88%;
  animation: sway 2.6s ease-in-out infinite;
}

.demo-daruma:nth-child(2) svg { animation-delay: -0.5s; }
.demo-daruma:nth-child(3) svg { animation-delay: -1.1s; }
.demo-daruma:nth-child(4) svg { animation-delay: -1.7s; }
.demo-daruma:nth-child(5) svg { animation-delay: -2.2s; }
.demo-daruma.is-wobble svg { animation: wobble 1s ease-out both; }
.demo-daruma.is-found svg { animation: hop 0.42s ease-out both; }
.demo-daruma.is-found { box-shadow: 0 0 0 3px var(--c-gold-l) inset; border-radius: 50%; }
.demo-daruma:focus-visible { outline: 3px solid var(--c-ai-l); }

@keyframes sway {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

.demo-caption {
  margin: 0 0 10px;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--c-dim);
}

.title-catch {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.7;
}

.title-catch b { color: var(--c-shu); white-space: nowrap; }

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px 12px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18), 0 8px 18px rgba(70, 50, 30, 0.16);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  touch-action: manipulation;
}

.mode-card:hover { filter: brightness(1.06); }
.mode-card:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 4px 10px rgba(70, 50, 30, 0.16); }
.mode-card:focus-visible { outline: 3px solid var(--c-ink); outline-offset: 2px; }
.mode-card--life { background: linear-gradient(160deg, #e2620f, #b8430a); }
.mode-card--time { background: linear-gradient(160deg, #2a77a0, #174d6b); }

.mode-card__name { font-size: 19px; font-weight: 800; letter-spacing: 0.04em; }
.mode-card__desc { font-size: 12px; opacity: 0.95; line-height: 1.4; }
.mode-card__best { font-size: 11px; opacity: 0.88; line-height: 1.4; }

.title-sub-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.title-note {
  margin: 14px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--c-dim);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:focus-visible { outline: 3px solid var(--c-ai-l); outline-offset: 2px; }

.btn-primary {
  background: var(--c-shu);
  color: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}

.btn-primary:hover { filter: brightness(1.07); }

.btn-sub {
  padding: 9px 14px;
  font-size: 13px;
  background: var(--c-paper);
  border-color: var(--c-line);
  color: var(--c-ink);
}

.btn-sub:hover { border-color: rgba(43, 36, 32, 0.35); }

.sub-count {
  font-family: var(--font-num);
  font-size: 11px;
  color: var(--c-dim);
}

/* リザルト */
.result-title {
  margin: 0;
  font-family: var(--font-mincho);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.result-mode {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--c-dim);
}

.result-new {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--c-gold);
}

.result-score-row {
  margin: 4px 0 10px;
  font-family: var(--font-num);
  font-weight: 800;
}

#result-score { font-size: 46px; color: var(--c-shu); }
.result-unit { margin-left: 4px; font-size: 18px; font-family: var(--font-jp); }

.judge {
  margin: 0 0 12px;
  padding: 12px 12px 10px;
  border: 2px solid rgba(200, 150, 46, 0.55);
  border-radius: 16px;
  background: linear-gradient(180deg, #fffaf0, #fbf3e2);
}

.judge-label { margin: 0; font-size: 11px; color: var(--c-dim); letter-spacing: 0.1em; }
.judge-title { margin: 2px 0 0; font-family: var(--font-mincho); font-size: 24px; font-weight: 800; }
.judge-stars { margin: 0; font-size: 18px; letter-spacing: 0.12em; color: var(--c-gold-l); }
.judge-text { margin: 4px 0 6px; font-size: 13px; line-height: 1.5; }
.judge-de { margin: 0; font-size: 12px; color: var(--c-dim); }
.judge-de b { font-family: var(--font-num); font-size: 15px; color: var(--c-ink); }
.judge.is-none .judge-stars { color: #d5ccbb; }

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.rstat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(43, 36, 32, 0.045);
  font-weight: 700;
  font-size: 15px;
}

.rstat-label { font-size: 10.5px; font-weight: 400; color: var(--c-dim); }

.fresh { margin: 0 0 12px; }
.fresh-title { margin: 0 0 6px; font-size: 13px; }
.fresh-title b { color: var(--c-shu); }

.fresh-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fresh-list li {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 4px;
  border: 1px solid var(--c-line);
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
}

.chip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(43, 36, 32, 0.25);
}

.result-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.result-buttons .btn-primary { flex: 1 1 100%; max-width: 320px; }

/* ===== モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2147482600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + var(--sgh-top, 0px));
  padding-bottom: calc(16px + max(var(--ad-space, 0px), env(safe-area-inset-bottom, 0px)));
  background: rgba(40, 30, 20, 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-box {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px 18px;
  border-radius: 18px;
  background: var(--c-paper);
  box-shadow: 0 16px 50px rgba(40, 30, 20, 0.35);
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}

.modal-box:focus { outline: none; }

.modal-box--wide { width: min(680px, 100%); }

.modal-title {
  margin: 0 0 12px;
  font-family: var(--font-mincho);
  font-size: 22px;
}

.howto {
  margin: 0 0 16px;
  padding-left: 1.2em;
  text-align: left;
  font-size: 14px;
  line-height: 1.7;
}

.howto li + li { margin-top: 6px; }
.howto b { color: var(--c-shu); }

.zukan-lead { margin: 0; font-size: 13px; }
.zukan-count { margin: 2px 0 6px; font-size: 13px; }
.zukan-count b { font-family: var(--font-num); font-size: 15px; white-space: nowrap; }

.zukan-meter {
  height: 8px;
  margin: 0 0 12px;
  border-radius: 999px;
  background: rgba(43, 36, 32, 0.1);
  overflow: hidden;
}

#zukan-meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-shu-l), var(--c-gold-l));
  transform-origin: left center;
}

.zukan-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.zk {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 4px;
  border: 1px solid var(--c-line);
  border-radius: 12px;
  background: #fff;
}

.zk-pic {
  flex: none;
  width: 40px;
  height: 40px;
  color: #ddd5c6;
}

.zk-pic svg { width: 100%; height: 100%; display: block; }
.zk.is-locked { background: rgba(255, 255, 255, 0.5); }
.zk.is-locked .zk-pic { opacity: 0.6; }

.zk-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.zk-name { font-size: 14px; }
.zk-yomi { font-size: 10.5px; color: var(--c-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zk-hex { font-family: var(--font-num); font-size: 10.5px; color: var(--c-dim); white-space: nowrap; }
.zk.is-locked .zk-name { color: var(--c-dim); }

/* ===== フッター ===== */
#footer {
  flex: none;
  padding: 3px 8px 5px;
  text-align: center;
  font-size: 11px;
  line-height: 1.5;
  color: var(--c-dim);
}

html:not(.has-ad-banner) #footer { padding-bottom: max(5px, env(safe-area-inset-bottom, 0px)); }

#footer a { color: inherit; }

/* ===== 横長で背が低い画面（スマホ横向き等）: 盤面の右に HUD と案内を並べる ===== */
@media (max-height: 560px) and (min-aspect-ratio: 5/4) {
  #topbar { height: 40px; max-width: 980px; }
  .play-col {
    max-width: 980px;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 250px);
    grid-template-rows: auto auto 1fr;
    align-content: stretch;
    grid-template-areas: "board hud" "board bar" "board info";
    column-gap: 14px;
  }
  #hud { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 8px; }
  .hud-cell--last { align-items: flex-start; }
  #info { height: auto; justify-content: flex-start; padding-top: 8px; }
  .sw-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .sw-vs { display: none; }
  #footer { padding-top: 1px; padding-bottom: 2px; }
  .screen { padding-top: 6px; }
}

@media (max-width: 360px) {
  #logo { font-size: 18px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .mode-card__name { font-size: 17px; }
  .hud-value { font-size: 17px; }
  .result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .demo-daruma svg { animation: none; }
  .is-in .tile svg { animation-duration: 0.01s; }
}

/* ===== 全国ランキング（共通モジュール sgr-*） ===== */
.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(40, 30, 20, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-hidden { display: none !important; }

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--c-paper);
  color: var(--c-sgr-text);
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(40, 30, 20, 0.4);
  -webkit-user-select: text;
  user-select: text;
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
  font-family: var(--font-mincho);
}

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: 1px solid var(--c-sgr-line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(200, 79, 12, 0.05);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: var(--c-shu);
  border-color: transparent;
  color: #fff;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--c-shu);
}

.sgr-form { display: flex; gap: 8px; }

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid var(--c-sgr-line);
  border-radius: 8px;
  background: #fff;
  color: var(--c-sgr-text);
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder { color: var(--c-sgr-dim); }

.sgr-name:focus {
  outline: none;
  border-color: var(--c-shu-l);
  box-shadow: 0 0 8px rgba(235, 97, 1, 0.25);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: var(--c-shu);
  color: #fff;
  cursor: pointer;
}

.sgr-submit:hover { filter: brightness(1.08); }
.sgr-submit:disabled { opacity: 0.5; cursor: default; }

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--c-red);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-sgr-dim);
}

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.sgr-row:nth-child(even) { background: rgba(43, 36, 32, 0.045); }

.sgr-row.sgr-row-me {
  background: var(--c-shu);
  color: #fff;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: bold;
  flex-shrink: 0;
}

.sgr-rank-top1 { color: #c98d1c; }
.sgr-rank-top2 { color: #8a93a6; }
.sgr-rank-top3 { color: #b0703a; }
.sgr-row-me .sgr-rank { color: #fff; }

.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sgr-row-score {
  font-weight: bold;
  font-family: var(--font-num);
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid var(--c-sgr-line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(43, 36, 32, 0.04);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-close:hover { border-color: var(--c-shu-l); }

.sgr-cta {
  margin: 0 0 12px;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-gold);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, #f3c552, #e8962a);
  color: #2a1a00;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(232, 150, 42, 0.35);
}

.sgr-cta-btn:hover { filter: brightness(1.06); }

.sgr-cta-link {
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: #fff;
  border: 1px solid var(--c-line);
  color: var(--c-ink);
  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; }
}
