/* ══════════════════════════════════════════════════
   パズルエンジン共通CSS（crossword.html・suiri.html で共有）
   このファイルより後（各HTML側の<head>内、このlinkタグの次）に、
   エンジン固有の追加・上書きCSSを<style>で置くこと。
   ══════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* 画像・動画の保存防止（iOS長押しメニュー・ドラッグ選択を抑制） */
img, video {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
}

/* ── CSS カスタムプロパティ ── */
:root {
  /* レイアウト */
  --cell:      46px;
  --num-fs:    0.8rem;
  --inp-fs:    1.25rem;
  --clue-fs:   0.82rem;
  --grid-cols: 10;
  --grid-rows: 15;
  --grid-gaps: 9;  /* COLS-1 */
  --grid-w: calc(var(--grid-cols) * var(--cell) + var(--grid-gaps) * 2px + 6px);
  --display-rows: 15; /* デスクトップでのグリッド表示領域の基準行数（実際のROWSに関わらず固定。パズルごとに表示エリアの高さが変わらないようにするための定数） */

  /* テーマカラー（puzzle_***.js の PUZZLE_THEME で上書きされる） */
  --color-primary:       #0077b6;
  --color-primary-rgb:   0, 119, 182;
  --color-primary-d:     #005f8e;
  --color-primary-l:     #0096c7;
  --color-primary-l-rgb: 0, 150, 199;
  --color-primary-2:     #00b4d8;
  --color-primary-dk:    #023e8a;
  --color-accent:        #f77f00;
  --color-accent-l:      #ffd060;
  --bg-body:             linear-gradient(170deg, #b8e8f8 0%, #d6f3fc 35%, #fff9e2 100%);
}

body {
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Meiryo', sans-serif;
  background: var(--bg-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: #1a3a4a;
  padding: 20px 12px 0;
  padding-top: calc(52px + 24px); /* ヘッダー高さ + 本文との余白 */
}

/* ── グリッド↔映像 切り替えボタン ── */
#video-toggle-btn {
  display: none; /* JS で block に切り替え */
  position: fixed;
  bottom: 76px; /* パズル終了後はキーボードが常に非表示になるため、ヒント欄のみの高さに合わせる */
  left: 50%;
  transform: translateX(-50%);
  z-index: 660;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 28px;
  font-size: 0.92rem;
  font-weight: bold;
  letter-spacing: .06em;
  box-shadow: 0 4px 16px rgba(0,80,160,.35);
  cursor: pointer;
  white-space: nowrap;
}
#video-toggle-btn:hover { background: var(--color-primary-d); }
@media (min-width: 901px) {
  #video-toggle-btn { bottom: 20px; }
}

/* ── ページトップボタン（スマホ・タブレットのみ） ── */
#to-top-btn {
  display: none; /* JS で flex に切り替え */
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 300;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(var(--color-primary-l-rgb),.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(var(--color-primary-rgb),.35);
  transition: transform .2s, background .18s;
  padding: 0;
  font-size: 0; /* 文字非表示 */
}
#to-top-btn::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 10px solid #fff;
  margin-top: 2px; /* 視覚的中央補正 */
}
#to-top-btn:hover  { background: rgba(var(--color-primary-rgb),.95); }
#to-top-btn:active { transform: scale(.92); }

/* ── サイトフッター ── */
#site-footer {
  margin-top: auto;
  padding: 18px 16px;
  text-align: center;
  font-size: .82rem;
  color: rgba(26,58,74,.75);
  letter-spacing: .06em;
  border-top: 1px solid rgba(var(--color-primary-rgb),.1);
}
#site-footer a {
  color: inherit;
  text-decoration: underline;
}
#site-footer a:hover { color: var(--color-primary); }

/* ── サイトヘッダー ── */
#site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 700;
  background: var(--color-primary);
  border-bottom: 1px solid var(--color-primary-dk);
  box-shadow: 0 2px 16px rgba(var(--color-primary-rgb),.3);
}
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
}
.site-name {
  font-family: 'Yomogi', sans-serif;
  font-size: 1.6rem;
  letter-spacing: .1em;
  color: #fff;
  text-decoration: none;
}
.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 8px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: inherit;
  font-weight: normal;
}
.hamburger:hover { background: rgba(255,255,255,.15); }
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .22s ease, opacity .22s ease;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
#nav-menu {
  background: rgba(255,255,255,.96);
  border-top: 1px solid rgba(var(--color-primary-rgb),.12);
}
#nav-menu[hidden] { display: none; }
#nav-menu ul { list-style: none; padding: 6px 0; }
#nav-menu li a {
  display: block;
  padding: 13px 24px;
  color: #1a3a4a;
  text-decoration: none;
  font-size: .95rem;
  letter-spacing: .04em;
}
#nav-menu li a:hover { background: rgba(var(--color-primary-rgb),.07); color: var(--color-primary); }
.nav-cleared-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 1rem;
  line-height: 1;
  vertical-align: middle;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
#nav-menu .nav-note {
  padding: 8px 24px 10px;
  font-size: .8rem;
  color: #999;
  border-top: 1px solid rgba(var(--color-primary-rgb),.08);
}

/* ── パズルタイトルバー（スマホのみ表示） ── */
#puzzle-title-bar { text-align: center; margin-bottom: 20px; }
#puzzle-title-logo {
  max-height: 56px; width: auto;
  display: block; margin: 0 auto;
  -webkit-mask-image:
    linear-gradient(to right,  transparent 0%, black 12%, black 88%, transparent 100%),
    linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right,  transparent 0%, black 12%, black 88%, transparent 100%),
    linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
  mask-composite: intersect;
}
#puzzle-title-bar h1 {
  font-family: 'Yomogi', sans-serif;
  font-size: 2.6rem;
  letter-spacing: .12em;
  background: linear-gradient(120deg, var(--title-from, #c84800) 0%, var(--title-mid, #8a5200) 45%, var(--title-to, #004e80) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  -webkit-text-stroke: 4px white;
  paint-order: stroke fill;
  filter: drop-shadow(0 2px 10px rgba(0,0,0,.18));
}

/* ── レイアウト ── */
.puzzle-area {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
}

.grid-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── GRID ── */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), var(--cell));
  grid-template-rows:    repeat(var(--grid-rows), var(--cell));
  gap: 2px;
  background: var(--color-primary);
  border: 3px solid var(--color-primary-dk);
  flex-shrink: 0;
}

.cell {
  width: var(--cell); height: var(--cell);
  background: #f0fbff;
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.cell.black { background: #1a3a4a; }

/* グリッド背景装飾画像（GRID_BG_IMAGE指定時のみ付与される .has-bg-image）。
   白マスだけ半透明にして画像を薄く透かし、黒マスは従来通り不透明に保つ */
.grid.has-bg-image {
  background-image: var(--grid-bg-image);
  background-size: cover;
  background-position: center;
}
.grid.has-bg-image .cell:not(.black) { background: rgba(240, 251, 255, 0.65); }
/* 背景画像の上でも文字・マス番号の視認性を確保するため、くっきりした白縁取り＋濃色の文字色で対応
   （テーマカラーが背景画像と同系色で埋もれる場合があるため、マス番号は固定の濃色にする） */
.grid.has-bg-image .cell input,
.grid.has-bg-image .cell .num {
  text-shadow:
    -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff,
    0 0 3px #fff, 0 0 3px #fff;
}
.grid.has-bg-image .cell .num { color: #1a3a4a; }
/* 上の半透明背景が選択中マス・単語ハイライト等の配色を上書きしてしまうため、同等以上の詳細度で復元する */
.grid.has-bg-image .cell.word-hi { background: #bae6fd; }

/* iOS type=search の装飾を除去 */
.cell input[type="search"]::-webkit-search-decoration,
.cell input[type="search"]::-webkit-search-cancel-button,
.cell input[type="search"]::-webkit-search-results-button,
.cell input[type="search"]::-webkit-search-results-decoration { display: none; }

.cell input {
  width: 100%; height: 100%;
  border: none; outline: none;
  text-align: center;
  font-family: inherit;
  font-size: var(--inp-fs);
  font-weight: bold;
  color: #1a3a4a;
  background: transparent;
  caret-color: var(--color-accent);
  padding: 0;
  cursor: pointer;
}
.cell.word-hi       { background: #bae6fd; }
.cell input:focus   { background: #7dd3fc !important; }
.cell.correct input { background: #bbf7d0 !important; color: #166534; }
.cell.wrong   input { background: #fecdd3 !important; color: #9f1239; }

.cell .num {
  position: absolute;
  top: 2px; left: 3px;
  font-size: var(--num-fs);
  color: var(--color-primary);
  line-height: 1;
  pointer-events: none;
  font-weight: normal;
}


/* ── アクティブ問題 ── */
#active-clue {
  margin-top: 10px;
  padding: 12px 16px 14px;
  background: linear-gradient(145deg, #e9f6ff 0%, #fffdf0 100%);
  border: 1.5px solid rgba(var(--color-primary-rgb),.2);
  border-top: 3px solid var(--color-primary-l);
  border-radius: 10px;
  width: var(--grid-w);
  max-width: 100%;
  height: 10em;
  overflow-y: auto;
  font-size: 1.05rem;
  line-height: 1.7;
  box-shadow: 0 4px 16px rgba(var(--color-primary-rgb),.12), 0 1px 3px rgba(0,0,0,.06);
  color: #1a3a4a;
}
#active-clue:empty {
  border-top-color: rgba(var(--color-primary-rgb),.2);
  background: rgba(255,255,255,.4);
}
#active-clue .ac-num {
  display: inline-block;
  font-weight: bold;
  color: #fff;
  background: var(--color-primary-l);
  border-radius: 4px;
  padding: 0 6px;
  margin-right: 8px;
  font-size: .92em;
  line-height: 1.6;
  white-space: nowrap;
  vertical-align: .05em;
}
/* イラストヒント */
#active-clue .clue-img-active,
#mobile-clue-bar .clue-img-active {
  display: block;
  max-height: 5.5em;
  max-width: 100%;
  border-radius: 6px;
  object-fit: contain;
  margin: 4px auto 0;
}
#active-clue .clue-img-active,
#mobile-clue-bar .clue-img-active { cursor: pointer; }
.clue-img-tap-hint {
  font-size: 0.72rem;
  color: #888;
  margin-left: 6px;
  vertical-align: middle;
}
#active-clue.img-hint-expanded {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
/* デスクトップ: 画像ヒント表示中（JS で height を直接制御） */
@media (min-width: 901px) {
  #active-clue.img-hint-expanded .clue-img-active {
    flex: 1;
    min-height: 0;
    align-self: center;
    max-height: none;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    border-radius: 8px;
    margin: 0;
  }
}

/* ── 操作一覧コラム（操作説明＋ロゴをまとめる縦列） ── */
.manual-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  align-self: flex-start;
}

#manual {
  width: max-content;
  white-space: nowrap;
}

/* ── パズルロゴ（デスクトップ・タブレット） ── */
#puzzle-logo {
  width: max-content;
}
#puzzle-logo-img {
  -webkit-mask-image:
    linear-gradient(to right,  transparent 0%, black 12%, black 88%, transparent 100%),
    linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right,  transparent 0%, black 12%, black 88%, transparent 100%),
    linear-gradient(to bottom, transparent 0%, black 15%, black 85%, transparent 100%);
  mask-composite: intersect;
}
.logo-title {
  font-family: 'Yomogi', sans-serif;
  font-size: 1.5rem;
  letter-spacing: .12em;
  line-height: 1.75;
  background: linear-gradient(120deg, var(--title-from, #c84800) 0%, var(--title-mid, #8a5200) 45%, var(--title-to, #004e80) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  -webkit-text-stroke: 3px white;
  paint-order: stroke fill;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.15));
}

/* ── CLUES ── */
.clues-wrapper {
  display: flex;
  flex-direction: row;
  gap: 16px;
  width: 720px;    /* ヒントの文字数に関わらず枠幅を一定にする（内容依存の伸縮をしない） */
  max-width: 100%;
  align-items: flex-start;
}

.clues {
  flex: 1;
  min-width: 0;
  height: calc(var(--grid-rows) * (var(--cell) + 2px) + 4px);
  overflow-y: auto;
}

.clues h2 {
  font-size: 1rem;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-2));
  color: #fff;
  padding: 4px 10px;
  border-radius: 3px;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.clues dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; }
.clues dt {
  font-weight: bold;
  font-size: var(--clue-fs);
  color: #555;
  text-align: right;
  padding-top: 1px;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation; /* タップ遅延を除去 */
}
.clues dd { font-size: var(--clue-fs); line-height: 1.45; color: #222; cursor: pointer; touch-action: manipulation; }
.clues dt:hover, .clues dd:hover { background: #e0f0f8; }
.clues dt.clue-active { color: #fff; background: var(--color-accent); border-radius: 3px; }
.clues dd.clue-active { background: #ffe0b3; border-radius: 3px; }

/* ── ボーナス：隠し文字ハイライト ── */
@keyframes bonus-reveal {
  0%   { transform: scale(1);    background: #fff;    box-shadow: none; }
  40%  { transform: scale(1.35); background: #fff200; box-shadow: 0 0 18px rgba(255,200,0,.9); }
  100% { transform: scale(1);    background: #ffd700; box-shadow: inset 0 0 0 2px var(--color-accent); }
}
@keyframes bonus-pulse {
  0%   { background: #ffd700; box-shadow: inset 0 0 0 2px var(--color-accent); }
  100% { background: #ffb700; box-shadow: inset 0 0 0 2px #e05c00; }
}
.cell.bonus-cell {
  animation: bonus-reveal .65s ease forwards,
             bonus-pulse  .9s ease-in-out .65s infinite alternate;
}
.cell.bonus-cell input { color: #7a3000; font-weight: bold; }

/* 演出中は操作ブロック */
.bonus-animating .grid,
.bonus-animating .clues,
.bonus-animating #clear-btn { pointer-events: none; user-select: none; }
.bonus-animating #clear-btn {
  opacity: 0.4;
  background: #aaa;
  color: #fff;
  cursor: not-allowed;
}

/* ── 全問正解 お祝い演出（英語・シネマティック） ── */
@keyframes celeb-bg-in  { from { opacity:0; } to { opacity:1; } }
@keyframes celeb-bg-out { from { opacity:1; } to { opacity:0; } }
@keyframes letter-fall {
  0%   { opacity:0; transform:translateY(-70px) scale(1.3); }
  60%  { transform:translateY(6px) scale(.96); }
  80%  { transform:translateY(-3px) scale(1.01); }
  100% { opacity:1; transform:translateY(0) scale(1); }
}
@keyframes shimmer-sweep {
  from { background-position: -200% center; }
  to   { background-position:  200% center; }
}
@keyframes sub-rise {
  from { opacity:0; transform:translateY(18px); letter-spacing:.35em; }
  to   { opacity:1; transform:translateY(0);    letter-spacing:.22em; }
}
@keyframes celeb-out { from { opacity:1; } to { opacity:0; transform:scale(1.04); } }

#celeb-overlay {
  position: fixed; inset: 0; z-index: 700;
  background: rgba(0,8,32,.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
  pointer-events: none;
}
#celeb-overlay[hidden] { display: none; }
#celeb-overlay.in  { animation: celeb-bg-in  .4s ease forwards; }
#celeb-overlay.out { animation: celeb-out .6s ease forwards; }

#celeb-main {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 1px;
}

.celeb-letter {
  display: inline-block;
  opacity: 0;
  font-family: 'Impact', 'Arial Black', 'Arial', sans-serif;
  font-size: clamp(1.9rem, 7.5vw, 4.6rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: linear-gradient(90deg,
    #fff4a0 0%, #ffd700 25%, #fffbe0 50%, #ffd700 75%, #fff4a0 100%
  );
  background-size: 250% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  /* ノティカ等の明るい背景と重なっても輪郭が潰れないよう、影を二重にして縁取りを強める */
  filter: drop-shadow(0 3px 12px rgba(0,0,0,.75)) drop-shadow(0 0 5px rgba(0,0,0,.85));
}
.celeb-letter.in {
  animation:
    letter-fall .5s cubic-bezier(.22,1,.36,1) both,
    shimmer-sweep 2.4s linear 1s infinite;
}

#celeb-sub {
  position: relative;
  z-index: 1;
  font-size: clamp(.8rem, 3vw, 1.2rem);
  color: rgba(255,255,220,.88);
  letter-spacing: .35em;
  text-transform: uppercase;
  opacity: 0;
  /* ノティカ（明るい色のコート等）が背後に重なっても読めるよう、常に濃い影を敷く */
  text-shadow: 0 2px 8px rgba(0,0,0,.95), 0 0 5px rgba(0,0,0,.9), 0 0 14px rgba(0,0,0,.7);
}
#celeb-sub.in { animation: sub-rise .65s cubic-bezier(.22,1,.36,1) forwards; }

#celeb-share {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(0,8,32,.55);
  opacity: 0;
  /* 親(#celeb-overlay)がpointer-events:noneのため、ボタン自体は明示的に有効化する */
  pointer-events: none;
}
#celeb-share.in {
  pointer-events: auto;
  animation: celeb-share-rise .5s cubic-bezier(.22,1,.36,1) forwards;
}
@keyframes celeb-share-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.celeb-share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,.35);
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.celeb-share-btn:hover  { transform: translateY(-2px); box-shadow: 0 5px 14px rgba(0,0,0,.4); }
.celeb-share-btn:active { transform: translateY(0); }
.celeb-share-btn:disabled { opacity: .7; cursor: default; transform: none; }
.celeb-share-x    { background: #2f3336; border: 1.5px solid rgba(255,255,255,.5); }
.celeb-share-line { background: #06c755; }
.celeb-share-copy { background: rgba(0,0,0,.45); border: 1.5px solid rgba(255,255,255,.6); }

/* ── ボーナス動画オーバーレイ（form内に absolute 配置） ── */
#grid-video-overlay[hidden] { display: none !important; }
@keyframes grid-video-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#grid-video-overlay.in { animation: grid-video-in .4s ease forwards; }

/* ── ボーナスパネル（オーバーレイ） ── */
#bonus-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,40,80,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
}
#bonus-overlay[hidden] { display: none; }
#bonus-panel {
  background: linear-gradient(145deg, #e9f6ff 0%, #fffdf0 100%);
  border: 2px solid var(--color-primary-l);
  border-radius: 16px;
  padding: 28px 24px 24px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,80,160,.3);
}
#bonus-challenge-label {
  font-size: 1.25rem;
  font-weight: bold;
  letter-spacing: .1em;
  color: #fff;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  border-radius: 10px;
  padding: 8px 20px;
  display: block;
  margin-bottom: 14px;
  box-shadow: 0 3px 10px rgba(0,100,180,.3);
}
#bonus-panel h3 {
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-bottom: 6px;
}
#bonus-panel .bonus-desc {
  font-size: .88rem;
  color: #1a3a4a;
  margin-bottom: 16px;
  line-height: 1.6;
}
#bonus-panel .bonus-chars {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
}
.bonus-char-box {
  width: 38px; height: 38px;
  border: 2px solid var(--color-primary-l);
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: bold;
  color: var(--color-primary);
}
#bonus-answer-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 1.1rem;
  font-family: inherit;
  border: 2px solid var(--color-primary-l);
  border-radius: 8px;
  text-align: center;
  letter-spacing: .2em;
  color: #1a3a4a;
  margin-bottom: 12px;
  box-sizing: border-box;
}
#bonus-answer-input:focus { outline: none; border-color: var(--color-accent); }
/* iOS type=search の装飾を除去 */
#bonus-answer-input[type="search"]::-webkit-search-decoration,
#bonus-answer-input[type="search"]::-webkit-search-cancel-button,
#bonus-answer-input[type="search"]::-webkit-search-results-button,
#bonus-answer-input[type="search"]::-webkit-search-results-decoration { display: none; }
#bonus-submit-btn {
  padding: 10px 32px;
  background: var(--color-primary-l);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background .18s;
}
#bonus-submit-btn:hover { background: var(--color-primary); }
#bonus-result {
  margin-top: 12px;
  font-size: .95rem;
  font-weight: bold;
  min-height: 1.4em;
  line-height: 1.8;
}
#bonus-result.ok  { color: var(--color-primary); }
#bonus-result.ng  { color: #e05c3a; }
.bonus-correct-answer {
  display: block;
  font-size: 1.6rem;
  letter-spacing: .2em;
  color: var(--color-primary-dk);
  margin: 4px 0;
}
#bonus-quit-btn {
  display: block;
  margin: 14px auto 0;
  padding: 7px 20px;
  background: none;
  border: 1.5px solid rgba(26,58,74,.3);
  border-radius: 6px;
  color: rgba(26,58,74,.55);
  font-size: .82rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .18s, border-color .18s, color .18s, padding .18s;
}
#bonus-quit-btn:hover { border-color: #e05c3a; color: #e05c3a; }
#bonus-quit-btn.next-btn {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  border: none;
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  padding: 11px 36px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,100,180,.35);
  letter-spacing: .08em;
}
#bonus-quit-btn.next-btn:hover { background: linear-gradient(135deg, var(--color-primary-d), var(--color-primary-l)); }

/* パズル終了後ロック（グリッド閲覧・ヒント選択・ハイライトは可能、編集はJS側で禁止／最初からプレイボタンは常に有効） */
.puzzle-ended .grid { opacity: .85; }
.puzzle-ended #flick-keyboard { opacity: .5; pointer-events: none; }

button {
  padding: 9px 24px;
  font-size: .95rem;
  font-family: inherit;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}
#clear-btn {
  display: block;
  margin-top: 10px;
  background: #e05c3a;
  color: #fff;
  letter-spacing: .08em;
  box-shadow: 0 2px 8px rgba(224,92,58,.35);
  transition: background .18s, box-shadow .18s, transform .1s;
}
#clear-btn:hover {
  background: #c74828;
  box-shadow: 0 4px 12px rgba(224,92,58,.45);
}
#clear-btn:active {
  transform: scale(.97);
  box-shadow: 0 1px 4px rgba(224,92,58,.3);
}


/* ═══════════════════════════════════════════
   レスポンシブ対応
   ─────────────────────────────────────────
   デスクトップ大 : ≥ 1025px   cell=46px  横並び
   デスクトップ小 : 901-1024px  cell=42px  横並び
   タブレット     : 601-900px   cell=36px  縦並び
   スマホ大       : 481-600px   cell=30px  縦並び
   スマホ小       : ≤ 480px     cell=auto  縦並び
   ═══════════════════════════════════════════ */

/* デスクトップ（>900px）ではロゴを左列に表示、パズルタイトルバーは非表示 */
@media (min-width: 901px) {
  #puzzle-title-bar { display: none; }
  /* グリッドの行数（実際のROWS）に関わらず、表示エリアの高さは常に --display-rows（15行）基準で確保する。
     これにより行数の少ないパズルでもページ全体のレイアウト・縦の比率が変わらない。
     .grid-col は justify-content:center で、実グリッドをこの確保領域の中央に配置し、
     余った上下の余白はデザイン用の余白として残す（実グリッドが15行を超える場合は min-height なので伸びる）。
     manual-col を残り全て埋める。 */
  .manual-col { height: calc(var(--display-rows) * (var(--cell) + 2px) + 4px); }
  /* ドット柄はページ全体ではなく、15×10の確保領域（.grid-col）内だけに限定する */
  .grid-col   {
    min-height: calc(var(--display-rows) * (var(--cell) + 2px) + 4px);
    justify-content: center;
    background-image: radial-gradient(circle, rgba(var(--color-primary-rgb), .35) 2.2px, transparent 2.2px);
    background-size: 20px 20px;
  }
  .clues      { min-height: calc(var(--display-rows) * (var(--cell) + 2px) + 4px); }
  #active-clue { flex: 1; height: auto; min-height: 8em; }
}

/* デスクトップ小 */
@media (max-width: 1024px) {
  :root { --cell: 42px; --num-fs: 0.76rem; --inp-fs: 1.15rem; }
}

/* デスクトップ小：ヒント列を少し狭く */
@media (max-width: 1024px) {
  .clues-wrapper { max-width: 560px; }
}

/* タブレット・狭いデスクトップ（≤900px）：縦並びに切替 */
@media (max-width: 900px) {
  /* マスをビューポート幅から流動計算（最大36px）
     padding 12px*2=24px、grid内余白 9*2+6=24px → cell=(100vw-48px)/10
     ※ さらに安全マージンとして16px多く差し引いている（スクロールバー幅・端数丸め対策。
       余白ゼロぴったりの計算だと横スクロールバー分などでグリッド右端が見切れることがあるため） */
  :root {
    --cell: min(36px, calc((90vw - 40px) / 10));
    --num-fs: clamp(0.6rem, 1.8vw, 0.7rem);
    --inp-fs: clamp(0.8rem, 2.4vw, 1rem);
    --clue-fs: clamp(0.72rem, 1.95vw, 0.78rem);
  }
  .puzzle-area   { flex-direction: column; align-items: center; }
  /* align-items:stretch でタテ/ヨコの各枠を clues-wrapper の幅（=グリッド幅）いっぱいに広げる
     （ベースの align-items:flex-start のままだと、ヒントの文字数分の幅にしかならない） */
  .clues-wrapper { flex-direction: column; max-width: var(--grid-w); width: 100%; gap: 12px; align-items: stretch; }
  .clues         { max-height: none; overflow-y: visible; }
  .manual-col    { width: 100%; order: 3; }
  #manual        { display: none; }
  #puzzle-logo   { display: none; }
  #input-mode-toggle-btn { margin: 10px 0 0; } /* 幅が狭い時はグリッド直下へ移動（JS側で付け替え） */
  #puzzle-title-bar h1 { font-size: 1.3rem; }
  /* モバイルでは #active-clue を非表示（#mobile-clue-bar が代替） */
  #active-clue { display: none !important; }
  /* フロートバー(ヒント+フリックキーボード)分の余白をページ下部に確保
     ※ #flick-keyboard の実高さが変わったらここも合わせて調整すること */
  body { padding-bottom: 13em; }
  /* PC(非タッチ)はウィンドウ幅を狭めてもフリックキーボードを表示しないため、余白はヒント欄分のみでよい */
  html:not(.is-touch) body { padding-bottom: 6em; }
}

/* ── モバイル・タブレット専用フロートバー（ヒント表示＋フリックキーボード） ──
   #mobile-input-bar（ヒント欄）はウィンドウ幅のみで表示切替（PC でウィンドウを狭めた
   場合も表示される）。#flick-keyboard は html.is-touch（<head>内の早期スクリプトで
   付与）がある場合のみ表示・動作する。ネイティブキーボード抑制（readOnly等）は
   JS側で isTouchDevice のみを条件に行う（役割の対応関係は崩さない） */
#mobile-input-bar {
  display: none; /* デスクトップでは非表示 */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 150;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 3px solid var(--color-primary-l);
  box-shadow: 0 -4px 20px rgba(var(--color-primary-rgb),.18);
  /* キーボード開閉時のスムーズな追従（transform はコンポジタースレッドで処理） */
  will-change: transform;
  transition: transform 0.12s ease-out;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (max-width: 900px) {
  #mobile-input-bar { display: block; }
}
#mobile-clue-bar {
  padding: 10px 16px;
  font-size: 0.95rem;
  line-height: 1.7;
  color: #1a3a4a;
  min-height: 2.8em;
}
#mobile-clue-bar.clue-hint {
  color: #aaa;
  font-size: 0.85rem;
}
/* キーボード表示中: バーはキーボード上端に接するため、
   ホームインジケーター用の safe-area 余白は不要 */
#mobile-input-bar.kb-open {
  padding-bottom: 0;
}

/* ローマ字/カナ入力切替ボタン: 物理キーボード前提の機能のため、タッチ端末では幅にかかわらず常に非表示 */
html.is-touch #input-mode-toggle-btn { display: none !important; }

/* ── フリックキーボード本体 ── */
/* PC(非タッチ)ではウィンドウ幅にかかわらず常に非表示・無効化する */
html:not(.is-touch) #flick-keyboard { display: none !important; }
/* 単語未選択（閉じるボタン押下時 含む）のときは非表示 */
#flick-keyboard.fk-hidden { display: none; }
#flick-keyboard {
  position: relative; /* .fk-preview（フリック中の文字プレビュー）の絶対配置の基準にする */
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-auto-rows: 48px; /* 行ごとに内容の高さが違っても揃うよう固定 */
  gap: 4px;
  padding: 4px 6px 6px;
  border-top: 1px solid rgba(var(--color-primary-rgb),.15);
}
.fk-key {
  position: relative;
  min-width: 0;
  min-height: 42px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary-l);
  color: #fff;
  font-size: 1.05rem;
  font-weight: bold;
  font-family: inherit;
  touch-action: none; /* フリック中のページスクロールを抑止 */
  user-select: none;
  overflow: hidden;
  white-space: normal; /* button の UA デフォルト white-space:pre を上書き（幅が狭い列でラベルを折り返すため） */
}
.fk-key:active, .fk-key.fk-pressed {
  background: var(--color-primary-d);
}
.fk-key.fk-wide { font-size: 0.85rem; }
.fk-subnote { display: block; font-size: 0.55rem; font-weight: normal; opacity: .85; margin-top: 1px; word-break: break-all; }
.fk-key.fk-nav { background: var(--color-primary-2); display: flex; align-items: center; justify-content: center; }
.fk-key.fk-action { background: var(--color-primary-dk); }
.fk-nav-icon { width: 22px; height: 22px; }
.fk-preview {
  position: absolute;
  transform: translate(-50%, calc(-100% - 4px));
  background: var(--color-primary-dk);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 1.1rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  z-index: 20;
}

/* ── イラストヒント モーダル ── */
#img-hint-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
}
#img-hint-modal[hidden] { display: none; }
#img-hint-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.72);
  touch-action: manipulation; /* タップ遅延を除去（遅延中に focus() のユーザー操作扱いが切れるのを防ぐ） */
}
#img-hint-modal-box {
  position: relative;
  z-index: 1;
  padding: 10px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  max-width: 88vw;
  max-height: 82vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#img-hint-modal-img {
  display: block;
  max-width: 100%;
  max-height: calc(82vh - 28px);
  border-radius: 8px;
}
#img-hint-modal-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #e0e0e0;
  background: #fff;
  font-size: 1rem;
  font-weight: bold;
  color: #444;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  touch-action: manipulation;
}

/* スマホ（padding が 5vw*2 に変わるので計算式も更新。90vw = 100vw - 5vw*2 と一致する）
   ※ こちらも安全マージンとして16px多く差し引いている（理由は上の≤900pxブロックと同じ） */
@media (max-width: 600px) {
  :root {
    --cell: min(36px, calc((90vw - 40px) / 10));
    --num-fs: clamp(0.58rem, 3.6vw, 0.66rem);
    --inp-fs: clamp(0.78rem, 5.9vw, 0.96rem);
    --clue-fs: clamp(0.7rem, 4.2vw, 0.76rem);
  }
  body  { padding: 14px 5vw 6em; padding-top: calc(52px + 14px); }
  .clues-wrapper { flex-direction: column; }
  #puzzle-title-bar h1 { font-size: 1.2rem; }
  button    { padding: 8px 16px; font-size: .85rem; }
  #active-clue   { padding: 8px 12px; font-size: .88rem; }
}




/* ── ナビメニュー：現在のパズル ── */
#nav-menu li a.nav-current {
  color: var(--color-primary);
  font-weight: bold;
  background: rgba(var(--color-primary-rgb), .07);
}

/* ── マスコット「ノティカ」: 全問正解セレブレーション演出への登場 ──
   CONGRATULATIONS!の文字の背後に、大きく中央配置の背景として表示する。
   動画素材が縦長(480x854)のためその比率を維持し、画面に収まる範囲で最大化する。
   #celeb-mascot（canvas合成フォールバック）と#celeb-mascot-webm（WebMアルファ）は
   どちらか一方だけがJS側で表示され、見た目は共通のスタイルを使う */
#celeb-mascot,
#celeb-mascot-webm {
  position: absolute;
  /* ノティカの縦の見た目の範囲がテキスト・SNSボタンの帯を内包し、演出全体の見た目上の範囲を
     ほぼ決めてしまっているため、ノティカ自身を画面中央(50%)に置くことで演出全体が画面中央に来るようにする
     （文字・ボタン側は#celeb-overlayのjustify-content:centerで元々中央寄せなので、両者の中心を揃える） */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
  width: min(68vw, 320px);
  height: auto;
  aspect-ratio: 480 / 854;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  /* 文字・SNSボタンとの重なりで両方とも見えづらくなっていたため、
     サイズを縮小しつつ上寄りに配置して、テキスト帯との重なりを減らす */
  filter: drop-shadow(0 8px 28px rgba(0,0,0,.6));
  /* 動画の四隅を楕円状に丸くカットし、長方形のフレームであることを目立たなくする */
  border-radius: 32% / 22%;
}
/* 中央寄せの translate(-50%,-50%) を維持したまま登場アニメーションさせる
   （通常の letter-fall をそのまま使うと中央寄せのtransformが上書きされてしまうため専用に用意） */
@keyframes mascot-fall-in {
  0%   { opacity: 0; transform: translate(-50%, -50%) translateY(-70px) scale(1.3); }
  60%  { transform: translate(-50%, -50%) translateY(6px) scale(.96); }
  80%  { transform: translate(-50%, -50%) translateY(-3px) scale(1.01); }
  100% { opacity: 1; transform: translate(-50%, -50%) translateY(0) scale(1); }
}
#celeb-mascot.in,
#celeb-mascot-webm.in {
  animation: mascot-fall-in .55s cubic-bezier(.22,1,.36,1) both;
}

/* ── マスコット「ノティカ」ゲーム中リアクション（common/mascot-reaction.js） ──
   全身を、ボタン/バーの上に立たせる（縦横比は動画の 400x696 に合わせてある）。
   ・デスクトップ: 操作パネル下のボタン群の上に立つ（縦位置はJSがボタン位置に合わせて設定）
   ・≤900px: フロートバー（ヒント欄）の上端の左側に立つ（バーの子として置かれ、キーボード開閉にも追従する） */
#mascot-reaction {
  --mr-w: 140px;
  position: absolute;
  z-index: 0;
  width: var(--mr-w);
  height: calc(var(--mr-w) * 696 / 400);
  pointer-events: none;
  opacity: 0;
  transition: opacity .5s ease;
}
#mascot-reaction.ready { opacity: 1; }
#mascot-reaction.ready.mr-dodge { opacity: .12; transition-duration: .2s; } /* 入力中のマスと重なる間だけ薄くする */
#mascot-reaction canvas { display: block; width: 100%; height: 100%; }
/* つかんで動かせる範囲（キャラの胴体あたり。左右の透明な余白は下のマス等の操作を邪魔しないよう外す） */
#mascot-reaction .mr-grip { position: absolute; top: 0; bottom: 0; left: 18%; right: 18%; pointer-events: auto; touch-action: none; cursor: grab; -webkit-touch-callout: none; user-select: none; }
#mascot-reaction .mr-grip:active { cursor: grabbing; }
#mascot-reaction.mr-dodge .mr-grip { pointer-events: none; }
/* 動かした後は画面固定。下部バー（z-index:150〜650）より奥に置き、キーボードやツールバーのボタンを覆って押せなくならないようにする */
#mascot-reaction.mr-free { position: fixed; z-index: 140; transform: none; right: auto; bottom: auto; }
#mascot-reaction-decoders { position: fixed; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
#mascot-reaction-decoders video { width: 1px; height: 1px; }
html.bonus-animating #mascot-reaction,
html.puzzle-ended #mascot-reaction,
html.cleared #mascot-reaction { display: none; }

@media (min-width: 901px) {
  .manual-col { position: relative; }
  .manual-col #clear-btn,
  .manual-col .mode-toolbar { position: relative; z-index: 1; } /* ノティカの下端をボタン群の陰に隠す */
  #mascot-reaction.mr-desktop { left: 50%; transform: translateX(-50%); }
}
@media (max-width: 900px) {
  #mascot-reaction.mr-free { --mr-w: 84px; }
  #mobile-input-bar > #mascot-reaction,
  .mode-toolbar > #mascot-reaction { --mr-w: 84px; left: 10px; bottom: calc(100% + 3px); } /* 右側は#to-top-btnと被るため左に置く */
}