/* =========================================================
   BICHIKU / style.css
   ========================================================= */

:root {
  --ink:        #4A2F22;
  --ink-soft:   #8A6B57;
  --cream:      #FFF7E8;
  --cream-deep: #FFEFD2;
  --paper:      #FFFDF7;
  --red:        #FF5A4E;
  --orange:     #FF9B2F;
  --yellow:     #FFD24A;
  --pink:       #FFB9AE;
  --green:      #8FBF6E;
  --blue:       #6AAFE6;

  --shadow-1: 0 3px 0 var(--ink);
  --shadow-2: 0 5px 0 var(--ink);

  --radius: 20px;

  --font-en: "Fredoka", "M PLUS Rounded 1c", system-ui, sans-serif;
  --font-jp: "M PLUS Rounded 1c", system-ui, -apple-system, "Hiragino Maru Gothic ProN", sans-serif;
}

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

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--cream-deep);
  color: var(--ink);
  font-family: var(--font-jp);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-image:
    radial-gradient(circle at 50% 50%, rgba(255,155,47,.16) 2px, transparent 2.5px),
    radial-gradient(circle at 50% 50%, rgba(255,90,78,.12) 2px, transparent 2.5px);
  background-size: 34px 34px, 34px 34px;
  background-position: 0 0, 17px 17px;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; }

.app {
  height: 100vh; height: 100dvh;
  display: grid; place-items: center;
  padding: 0;
}

.frame {
  position: relative;
  width: min(100vw, 440px);
  height: 100vh; height: 100dvh;
  max-height: 920px;
  background: var(--cream);
  overflow: hidden;
}

@media (min-width: 520px) and (min-height: 600px) {
  .frame {
    height: min(100dvh - 24px, 880px);
    border: 3px solid var(--ink);
    border-radius: 32px;
    box-shadow: 0 10px 0 var(--ink), 0 22px 40px rgba(74,47,34,.25);
  }
}

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.screen.is-active { display: flex; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4em;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 800;
  letter-spacing: .02em;
  padding: .72em 1.2em;
  box-shadow: var(--shadow-2);
  transition: transform .06s ease, box-shadow .06s ease, background-color .12s ease;
  user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

.btn--play {
  background: var(--red); color: #FFF9F0;
  font-family: var(--font-en);
  font-size: 1.25rem; letter-spacing: .06em;
  padding: .8em 2.2em;
  text-shadow: 0 2px 0 rgba(74,47,34,.35);
}
.btn--sub { background: var(--yellow); font-size: .88rem; padding: .6em .95em; }
.btn--text {
  background: transparent; border-color: transparent; box-shadow: none;
  color: var(--ink-soft); font-size: .9rem; text-decoration: underline;
  text-underline-offset: 4px; padding: .4em .8em;
}
.btn--text:active { transform: none; box-shadow: none; }

.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.icon-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border: 3px solid var(--ink); border-radius: 50%;
  background: var(--paper); box-shadow: var(--shadow-1);
  font-size: 1.1rem; line-height: 1;
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn.is-ghost { border-color: transparent; background: none; box-shadow: none; }

/* タイトル画面 */
.screen--title {
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding-left: 16px; padding-right: 16px;
}

.title-top { padding-top: min(5vh, 36px); }

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--font-en); font-weight: 600;
  font-size: .72rem; letter-spacing: .24em;
  color: var(--ink-soft);
}

.logo {
  margin: 0;
  font-family: var(--font-en); font-weight: 700;
  font-size: clamp(3.4rem, 17vw, 4.6rem);
  line-height: .92; letter-spacing: .02em;
  color: var(--yellow);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink);
}
.logo-jp {
  margin: 14px 0 0;
  font-size: .82rem; letter-spacing: .5em;
  color: var(--ink-soft); text-indent: .5em;
}
.tagline {
  margin: 10px 0 0;
  font-size: 1rem; font-weight: 800;
  color: var(--ink);
}

.title-art {
  position: relative;
  width: 100%; height: 34%;
  min-height: 120px;
  display: flex; align-items: flex-end; justify-content: center;
  flex-wrap: wrap; gap: 0 2px;
}
.title-art img {
  width: var(--w); height: var(--w);
  object-fit: contain;
  margin: 0 -2px;
  animation: bob 2.6s ease-in-out infinite;
  animation-delay: var(--d);
}
.title-art .fallback {
  width: var(--w); height: var(--w);
  border-radius: 50%;
  border: 3px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
  margin: 0 -2px;
  animation: bob 2.6s ease-in-out infinite;
  animation-delay: var(--d);
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

.title-menu { display: flex; flex-direction: column; gap: 12px; align-items: center; width: 100%; }

.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 0 max(16px, env(safe-area-inset-bottom));
  color: var(--ink-soft);
}
.brand-mark {
  font-family: var(--font-en); font-weight: 700; font-size: .8rem;
  letter-spacing: .14em;
  border: 2px solid currentColor; border-radius: 999px;
  padding: 2px 10px;
}
.brand-name { font-size: .72rem; letter-spacing: .08em; }

/* シート画面 */
.screen--sheet { background: var(--cream); }

.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 3px dashed rgba(74,47,34,.18);
}
.sheet-head h2 {
  flex: 1; margin: 0; text-align: center;
  font-size: 1.15rem; letter-spacing: .08em;
}

.sheet-body { flex: 1; overflow-y: auto; padding: 18px 18px 8px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 18px max(18px, env(safe-area-inset-bottom)); display: grid; place-items: center; }

.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rules li {
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: 16px;
  box-shadow: var(--shadow-1);
  padding: 12px 14px;
  font-size: .95rem;
}
.rules li b { font-weight: 800; }
.rule-sub {
  display: inline-block;
  margin-top: 4px;
  font-size: .78rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.sheet-sub {
  margin: 22px 0 10px;
  font-size: .8rem; letter-spacing: .18em; color: var(--ink-soft);
  text-align: center;
}

.chain-chart {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 2px;
}
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 70px; padding: 6px 2px;
}
.chip img, .chip .fallback { width: 36px; height: 36px; object-fit: contain; }
.chip .fallback {
  border-radius: 50%; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
}
.chip span { font-size: .62rem; line-height: 1.2; text-align: center; }
.arrow { color: var(--orange); font-weight: 800; font-size: 1rem; }

.note {
  margin: 18px 0 0; padding: 12px 14px;
  border-radius: 14px; background: rgba(255,210,74,.28);
  font-size: .8rem; line-height: 1.7; text-align: center;
}

/* そなえ図鑑 */
.zukan-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 20px;
}
.zukan-card {
  display: flex;
  align-items: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow-1);
  padding: 10px 12px;
  gap: 12px;
}
.zukan-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.zukan-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.zukan-icon .fallback {
  width: 44px; height: 44px;
  border-radius: 50%; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
}
.zukan-info { flex: 1; min-width: 0; }
.zukan-title {
  font-size: .88rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 2px;
}
.zukan-desc {
  font-size: .75rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

/* ランキング */
.rank-note { margin: 0 0 12px; font-size: .78rem; color: var(--ink-soft); text-align: center; }
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rank-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: var(--shadow-1);
  padding: 10px 12px;
}
.rank-no {
  font-family: var(--font-en); font-weight: 700; font-size: .95rem;
  width: 28px; text-align: center; color: var(--ink-soft);
}
.rank-list li:nth-child(1) .rank-no { color: var(--red); font-size: 1.15rem; }
.rank-list li:nth-child(2) .rank-no,
.rank-list li:nth-child(3) .rank-no { color: var(--orange); }
.rank-name { flex: 1; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { font-family: var(--font-en); font-weight: 700; font-size: 1.05rem; }
.rank-empty {
  border: 3px dashed rgba(74,47,34,.25) !important;
  box-shadow: none !important; background: transparent !important;
  justify-content: center; text-align: center;
  font-size: .85rem; color: var(--ink-soft); padding: 26px 12px !important;
}

/* ゲーム画面 */
.screen--game { background: var(--cream); }

.hud {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
  padding: 8px 12px 6px;
  flex-shrink: 0;
}
.hud-cell { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.hud-score { align-items: flex-start; padding-left: 2px; }
.hud-best { align-items: flex-end; padding-right: 2px; }
.hud-value--best { font-size: 1.15rem; color: var(--ink-soft); }

.hud-label {
  font-family: var(--font-en); font-weight: 600;
  font-size: .6rem; letter-spacing: .18em; color: var(--ink-soft);
}
.hud-value {
  font-family: var(--font-en); font-weight: 700;
  font-size: 1.5rem; line-height: 1; letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.hud-score .hud-value { color: var(--red); }
.hud-value.is-bump { animation: bump .22s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.16); } 100% { transform: scale(1); } }

.next-box {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 3px solid var(--ink); border-radius: 14px;
  background: var(--paper); box-shadow: var(--shadow-1);
}
.next-box img { width: 32px; height: 32px; object-fit: contain; }
.next-box .fallback {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 800;
}

.hud-tools { display: flex; gap: 6px; margin-bottom: 4px; }
.tool-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 3px solid var(--ink); border-radius: 50%;
  background: var(--paper); box-shadow: var(--shadow-1);
  font-size: .72rem; line-height: 1; padding: 0;
}
.tool-btn:active { transform: translateY(3px); box-shadow: none; }

/* 盤面領域 */
.board-wrap {
  position: relative;
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 4px 10px max(14px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

#board {
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 400 / 700;
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow-2);
  background: var(--cream);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* 防災豆知識トースト */
.knowledge-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(74, 47, 34, 0.94);
  color: #FFFDF7;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(.2,1.3,.5,1), transform 0.25s cubic-bezier(.2,1.3,.5,1);
  z-index: 15;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  border: 2px solid var(--yellow);
  max-width: 90%;
  text-overflow: ellipsis;
  overflow: hidden;
}
.knowledge-toast.is-active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 連鎖表示 */
.fx-chain {
  position: absolute; top: 22%; left: 50%;
  transform: translate(-50%,-50%) scale(.6);
  font-family: var(--font-en); font-weight: 700; font-size: 2rem;
  color: var(--orange);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill;
  opacity: 0; pointer-events: none;
}
.fx-chain.is-on { animation: chainPop .8s ease-out; }
@keyframes chainPop {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(.5) rotate(-6deg); }
  25%  { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(3deg); }
  60%  { opacity: 1; transform: translate(-50%,-60%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%,-90%) scale(.95); }
}

/* 最高ランク・消去演出 */
.fx-max {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(255,210,74,.55), rgba(255,155,47,0) 62%);
  z-index: 10;
}
.fx-max.is-on { display: flex; animation: maxIn 2s ease-out forwards; }
.fx-max-jp {
  font-size: 1.6rem; font-weight: 800; color: var(--yellow);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  text-align: center;
}
.fx-max-en {
  font-family: var(--font-en); font-weight: 700; font-size: .8rem;
  letter-spacing: .18em; color: var(--ink);
}
@keyframes maxIn {
  0%   { opacity: 0; transform: scale(.7); }
  14%  { opacity: 1; transform: scale(1.06); }
  24%  { transform: scale(1); }
  78%  { opacity: 1; }
  100% { opacity: 0; }
}

/* オーバーレイ共通 */
.overlay {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  padding: 22px;
  background: rgba(74,47,34,.42);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  z-index: 20;
}
.overlay.is-active { display: flex; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: 100%; max-width: 330px;
  max-height: 100%; overflow-y: auto;
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: 26px;
  box-shadow: 0 8px 0 var(--ink);
  padding: 24px 20px 20px;
  text-align: center;
  animation: cardIn .22s cubic-bezier(.2,1.3,.5,1);
}
@keyframes cardIn { from { transform: translateY(14px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

.card-title { margin: 0 0 8px; font-size: 1.15rem; letter-spacing: .04em; }
.card-title--over {
  font-family: var(--font-en); font-weight: 700; font-size: 2rem;
  color: var(--red); letter-spacing: .06em;
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill;
  margin-bottom: 12px;
}
.card-text { margin: 0 0 16px; font-size: .82rem; line-height: 1.7; color: var(--ink-soft); }
.card-btns { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-top: 6px; }
.card-btns--row { flex-direction: row; justify-content: center; }
.card-btns--row .btn { flex: 1; }

.input {
  width: 100%;
  border: 3px solid var(--ink); border-radius: 14px;
  background: var(--cream);
  padding: .7em .9em;
  font-size: 1rem; font-weight: 700; text-align: center;
  margin-bottom: 8px;
}
.input:focus { outline: 3px solid var(--orange); outline-offset: 2px; }

.result {
  border: 3px dashed rgba(74,47,34,.22); border-radius: 18px;
  padding: 12px 14px; margin-bottom: 14px;
}
.result-rank-badge {
  background: var(--cream-deep);
  color: var(--ink);
  border: 2px solid var(--orange);
  border-radius: 12px;
  padding: 5px 10px;
  font-size: .78rem;
  font-weight: 800;
  margin-bottom: 10px;
  text-align: center;
}
.result-row { display: flex; align-items: baseline; justify-content: space-between; }
.result-row--sub { margin-top: 6px; }
.result-label { font-family: var(--font-en); font-weight: 600; font-size: .66rem; letter-spacing: .18em; color: var(--ink-soft); }
.result-score { font-family: var(--font-en); font-weight: 700; font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.result-best { font-family: var(--font-en); font-weight: 700; font-size: 1.1rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.result-new {
  margin: 8px 0 0; font-size: .78rem; font-weight: 800; color: var(--red);
  animation: bump .5s ease-out;
}

.tip {
  background: rgba(255,210,74,.3);
  border-radius: 16px; padding: 12px 14px; margin-bottom: 16px;
  text-align: left;
}
.tip-tag {
  display: inline-block; margin-bottom: 6px;
  font-size: .6rem; letter-spacing: .16em; font-weight: 800;
  color: var(--ink-soft);
}
.tip-text { margin: 0; font-size: .82rem; line-height: 1.7; }

/* 防災クイズモーダル */
.card--quiz {
  max-width: 360px;
  border-color: var(--orange);
}
.quiz-badge {
  display: inline-block;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0 6px;
}
.btn--quiz-opt {
  background: var(--paper);
  border: 2px solid var(--ink);
  font-size: 0.85rem;
  padding: 0.65em 0.8em;
  text-align: left;
  justify-content: flex-start;
  box-shadow: var(--shadow-1);
}
.btn--quiz-opt:hover {
  background: var(--cream-deep);
}
.quiz-feedback {
  margin-top: 10px;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.5;
  white-space: pre-line;
}
.quiz-feedback.is-correct { color: #2e7d32; }
.quiz-feedback.is-wrong { color: var(--red); }

/* アクセシビリティ */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-height: 620px) {
  .title-top { padding-top: 10px; }
  .logo { font-size: 2.8rem; -webkit-text-stroke-width: 5px; }
  .title-art { min-height: 70px; height: 24%; }
  .hud { padding: 4px 8px 2px; }
  .hud-value { font-size: 1.2rem; }
}
