/* ============================================================
   一筆 - Hitofude  和紙×墨×朱のスタイル
   ============================================================ */

:root {
  --washi: #f6f1e3;
  --washi-deep: #ece4d0;
  --ink: #2a241f;
  --ink-soft: #6b6157;
  --line-pale: #d8cdb6;
  --shu: #c73e2e;      /* 朱色 */
  --shu-deep: #a52f22;
  --gold: #b08d3c;
  --radius: 14px;
  --serif: Georgia, "Times New Roman", serif, "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255,255,255,.55), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(176,141,60,.10), transparent 50%),
    radial-gradient(ellipse at 70% 30%, rgba(199,62,46,.05), transparent 45%),
    var(--washi);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  /* 上のセーフエリアは共通ヘッダー（--sgh-top）が、下は広告があるとき --ad-space が含むので二重に空けない */
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
html.has-ad-banner #app { padding-bottom: 0; }

/* ---------- ヘッダー ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
}

#logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

#logo {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .02em;
  margin-right: 0;
  line-height: 1;
  padding-left: 2px;
}

#level-badge {
  font-family: var(--serif);
  font-size: 14px;
  color: var(--washi);
  background: var(--ink);
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

#level-badge:active { transform: scale(.96); }

#topbar-buttons { display: flex; gap: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  font-size: 19px;
  line-height: 1;
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(42,36,31,.14);
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
}

.icon-btn:active { transform: scale(.94); }

/* ---------- ステータスバー ---------- */
#status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 18px 4px;
}

#status-level {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

#status-count {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  white-space: nowrap;
  min-width: 44px;
  text-align: right;
}

#progress-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(42,36,31,.12);
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--shu), #e0684f);
  transition: width .18s ease;
}

/* ---------- 盤面 ---------- */
#board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* サイズはJSがインラインで指定する。絶対配置にして
   canvas が親のレイアウト幅を固定してしまわないようにする */
#board {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  touch-action: none;
  outline: none;
  border-radius: var(--radius);
}

#board:focus-visible {
  box-shadow: 0 0 0 3px rgba(199,62,46,.45);
}

/* ---------- ツールバー ---------- */
#toolbar {
  display: flex;
  gap: 10px;
  padding: 6px 14px 10px;
}

.tool-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255,255,255,.6);
  border: 1px solid rgba(42,36,31,.16);
  border-radius: 12px;
  padding: 11px 6px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(42,36,31,.08);
}

.tool-btn:active { transform: translateY(1px); box-shadow: none; }

.tool-btn:disabled {
  opacity: .4;
  pointer-events: none;
}

.tool-icon { font-size: 16px; }

/* ---------- 汎用ボタン ---------- */
.btn {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  cursor: pointer;
  width: 100%;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  color: var(--washi);
  background: linear-gradient(180deg, #d9503c, var(--shu-deep));
  box-shadow: 0 3px 0 #7e2317;
}

.btn-sub {
  color: var(--ink);
  background: rgba(42,36,31,.08);
}

.btn-danger-sub {
  color: var(--shu-deep);
  background: rgba(199,62,46,.10);
  font-size: 14px;
  padding: 10px 14px;
}

/* ---------- 結果オーバーレイ ---------- */
#result-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(42,36,31,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in .25s ease;
}

#result-box {
  width: min(86vw, 340px);
  background: var(--washi);
  border-radius: 18px;
  padding: 30px 24px 24px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  animation: pop-in .35s cubic-bezier(.2, 1.6, .4, 1);
}

#result-stamp {
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 46px;
  font-weight: 700;
  color: var(--shu);
  border: 4px solid var(--shu);
  border-radius: 50%;
  transform: rotate(-8deg);
  animation: stamp-in .5s cubic-bezier(.2, 1.8, .4, 1) .15s backwards;
}

#result-title {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: .12em;
}

#result-sub {
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink-soft);
  margin: 6px 0 18px;
}

#result-buttons {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ---------- モーダル ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(42,36,31,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  padding: 18px;
  animation: fade-in .2s ease;
}

.modal-box {
  width: min(92vw, 420px);
  max-height: min(84dvh, 620px);
  overflow-y: auto;
  background: var(--washi);
  border-radius: 18px;
  padding: 22px 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  animation: pop-in .3s cubic-bezier(.2, 1.5, .4, 1);
}

.modal-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .18em;
  text-align: center;
  margin-bottom: 16px;
}

.menu-section { margin-bottom: 18px; }

.menu-caption {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: .12em;
  margin-bottom: 8px;
  border-left: 3px solid var(--shu);
  padding-left: 8px;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  padding: 7px 2px;
}

.howto {
  list-style: none;
  font-size: 13.5px;
  line-height: 1.75;
  color: #453d35;
}

.howto li {
  padding-left: 16px;
  position: relative;
  margin-bottom: 5px;
}

.howto li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--shu);
}

/* トグルスイッチ */
.toggle {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  border: none;
  background: rgba(42,36,31,.22);
  position: relative;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
}

.toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: left .2s;
}

.toggle.on { background: var(--shu); }
.toggle.on .knob { left: 23px; }

/* ステージ選択 */
#level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.lv-btn {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255,255,255,.65);
  border: 1px solid rgba(42,36,31,.16);
  border-radius: 10px;
  cursor: pointer;
}

.lv-btn:active { transform: scale(.94); }

.lv-btn .lv-mark {
  font-size: 10px;
  line-height: 1;
  color: var(--shu);
}

.lv-btn.cleared { background: rgba(199,62,46,.10); border-color: rgba(199,62,46,.35); }

.lv-btn.current { outline: 2px solid var(--shu); outline-offset: 1px; }

.lv-btn.locked {
  color: rgba(42,36,31,.3);
  background: rgba(42,36,31,.05);
  cursor: default;
  pointer-events: none;
}

/* ---------- トースト ---------- */
#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(86px + env(safe-area-inset-bottom) + var(--ad-space, 0px));
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(42,36,31,.92);
  color: var(--washi);
  font-size: 14px;
  font-family: var(--serif);
  padding: 10px 20px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  animation: toast-in .25s ease;
}

/* ---------- フッター ---------- */
#footer {
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  padding: 4px 0 8px;
  line-height: 1.7;
}

#footer a { color: var(--ink-soft); }

/* ---------- ユーティリティ ---------- */
.hidden { display: none !important; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(.85); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes stamp-in {
  from { opacity: 0; transform: rotate(-8deg) scale(2.2); }
  to { opacity: 1; transform: rotate(-8deg) scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 横長画面（PC等）ではやや広く */
@media (min-width: 900px) and (min-height: 700px) {
  #logo { font-size: 30px; }
  .tool-btn { font-size: 16px; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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; }
}
