/* =========================================================
 * 犬の散歩（sanpo） スタイル
 * ========================================================= */
: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;
  --c-text: #2b2620;
  --c-dim: #7a6f63;
  --c-accent: #c8682a;
  --c-accent-deep: #a2501b;
  --c-leaf: #5b7f3a;
  --c-panel: rgba(255, 251, 244, 0.93);
  --c-line: rgba(60, 45, 30, 0.14);
  --shadow: 0 10px 30px rgba(30, 20, 10, 0.28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  font-family: var(--font-jp);
  color: var(--c-text);
  background: #9db7c9;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

/* ===== レイアウト（共通ヘッダー --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;
}

/* ゲーム独自の見出し行は画面に出さない（h1 は検索エンジン向けに残し、ボタンは共通ヘッダーのメニューから呼ぶ） */
#topbar {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
#logo {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fff4e6;
}
#topbar-buttons { display: flex; gap: 6px; }
.icon-btn {
  width: 34px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:focus-visible { outline: 2px solid #ffd39b; outline-offset: 2px; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #8aa6b8;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
  cursor: grab;
}
#view.grabbing { cursor: grabbing; }
#view.petting { cursor: pointer; }

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.32) 100%);
}

#vignette.flash { background: rgba(255, 255, 255, 0.55); transition: none; }
#vignette { transition: background 0.3s ease; }

#footer {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 5px 10px;
  padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px) * 0);
  font-size: 11px;
  color: #e9dfd3;
  background: #3a2e22;
}
#footer a { color: #ffd39b; }

/* ===== 読み込み中 ===== */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: radial-gradient(circle at 50% 40%, #c9d8c2, #8ea58a);
  color: #33402c;
  z-index: 40;
  transition: opacity 0.6s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.paw-spin { font-size: 38px; animation: paw 1.2s ease-in-out infinite; }
@keyframes paw {
  0%, 100% { transform: translateY(0) rotate(-10deg); }
  50% { transform: translateY(-8px) rotate(10deg); }
}
#loading-text { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: 0.08em; }

/* ===== 画面（オーバーレイ） ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.screen > * { pointer-events: auto; }

.title-card {
  width: min(400px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: var(--c-panel);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.title-en {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4em;
  color: var(--c-accent);
}
.title-ja {
  margin: 2px 0 2px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #3b2a1c;
}
.title-catch { margin: 0 0 12px; font-size: 13px; color: var(--c-dim); }

.field { margin: 0 0 11px; }
.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--c-dim);
}
.field-note { margin: 6px 0 0; font-size: 12px; color: var(--c-dim); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 5px 11px;
  border: 1.5px solid var(--c-line);
  border-radius: 999px;
  background: #fff;
  color: var(--c-text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.chip:active { transform: scale(0.96); }
.chip[aria-checked="true"] {
  border-color: var(--c-accent);
  background: #fbe6d4;
  color: #6a3510;
}
.chip:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.chip-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex: none;
}

#dog-name {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1.5px solid var(--c-line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
  -webkit-user-select: text;
  user-select: text;
}
#dog-name:focus { outline: none; border-color: var(--c-accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid #ffd39b; outline-offset: 2px; }
.btn-primary {
  width: 100%;
  margin-top: 4px;
  background: linear-gradient(180deg, #d9792f, var(--c-accent-deep));
  color: #fff;
  box-shadow: 0 4px 0 #7b3a10;
  letter-spacing: 0.06em;
}
.btn-primary:disabled { filter: grayscale(0.7) brightness(1.1); cursor: wait; }
.btn-sub { background: #efe5d9; color: var(--c-text); }
#title-record { margin: 10px 0 0; font-size: 12px; color: var(--c-dim); text-align: center; }

/* ===== 散歩中の表示 ===== */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud-top {
  position: absolute;
  top: 8px;
  left: calc(8px + env(safe-area-inset-left, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.hud-card {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 12px;
  background: rgba(30, 24, 18, 0.42);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
#hud-mood { color: #ff9eaa; letter-spacing: 0.05em; }
#hud-stats { font-variant-numeric: tabular-nums; }
#hud-status {
  position: absolute;
  left: 50%;
  top: 48px;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(30, 24, 18, 0.38);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s;
}
#hud-status.show { opacity: 1; }

#actions {
  position: absolute;
  right: calc(8px + env(safe-area-inset-right, 0px));
  bottom: 10px;
  display: grid;
  grid-template-columns: repeat(4, 58px);
  gap: 6px;
  pointer-events: auto;
}
.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 54px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 251, 244, 0.86);
  color: var(--c-text);
  font: inherit;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s, background 0.2s;
  touch-action: manipulation;
}
.act:active { transform: scale(0.94); }
.act:focus-visible { outline: 3px solid var(--c-accent); outline-offset: 1px; }
.act[disabled] { opacity: 0.45; cursor: default; }
.act.on { background: #fbe0c6; }
.act-ic { font-size: 21px; line-height: 1; }
.act-tx { font-size: 10.5px; font-weight: 800; letter-spacing: 0.02em; white-space: nowrap; }

#joy {
  position: absolute;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: 18px;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.35);
  pointer-events: auto;
  touch-action: none;
  opacity: 0.85;
}
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
@media (hover: hover) and (pointer: fine) {
  #joy { display: none; }
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 140px;
  transform: translate(-50%, 10px);
  max-width: calc(100% - 32px);
  padding: 9px 16px;
  border-radius: 12px;
  background: rgba(30, 24, 18, 0.78);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 35;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== 散歩の記録 ===== */
#screen-result { justify-content: center; background: rgba(20, 14, 8, 0.25); }
.result-card {
  width: min(380px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px;
  border-radius: 18px;
  background: var(--c-panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.result-title { margin: 0 0 4px; font-size: 22px; font-weight: 900; color: #3b2a1c; }
#result-sub { margin: 0 0 12px; font-size: 13px; color: var(--c-dim); }
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}
.result-stats div { padding: 9px 6px; border-radius: 12px; background: #fff; border: 1px solid var(--c-line); }
.result-stats dt { font-size: 11px; font-weight: 800; color: var(--c-dim); }
.result-stats dd { margin: 3px 0 0; font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }
#r-total { margin: 0 0 12px; font-size: 12px; color: var(--c-dim); }
.result-buttons { display: grid; gap: 8px; }
.result-buttons .btn { width: 100%; margin: 0; }

/* ===== モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2147483100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 14, 8, 0.5);
}
.modal-box {
  width: min(460px, 100%);
  max-height: calc(100% - 20px);
  overflow-y: auto;
  padding: 18px;
  border-radius: 18px;
  background: #fffaf3;
  box-shadow: var(--shadow);
}
.modal-title { margin: 0 0 10px; font-size: 19px; font-weight: 900; }
.howto { margin: 0 0 14px; padding-left: 1.2em; font-size: 13.5px; line-height: 1.7; }
.howto li { margin-bottom: 4px; }
input[type="range"] { width: 100%; accent-color: var(--c-accent); }

/* ===== スマホ縦 ===== */
@media (max-width: 640px) {
  .screen { align-items: flex-end; justify-content: center; padding: 8px; }
  .title-card { max-height: 60%; padding: 12px 12px 0; border-radius: 16px; }
  .title-en { display: none; }
  .title-ja { font-size: 21px; margin: 0; }
  .title-catch { margin: 0 0 6px; font-size: 12px; }
  .field { margin-bottom: 7px; }
  .field-label { margin-bottom: 3px; }
  .field-name { display: flex; align-items: center; gap: 10px; }
  .field-name .field-label { margin: 0; flex: none; }
  #dog-name { height: 34px; }
  .chip { min-height: 31px; padding: 3px 9px; font-size: 12.5px; }
  #btn-start { position: sticky; bottom: 0; z-index: 2; margin-top: 2px; }
  /* 犬種は横にスクロールして選ぶ（11 種あるので縦に積まない） */
  #breed-chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #breed-chips::-webkit-scrollbar { display: none; }
  #breed-chips .chip { flex: none; scroll-snap-align: start; }
  #title-record { margin: 0; padding: 8px 0 10px; background: var(--c-panel); position: sticky; bottom: 0; }
  /* 操作ボタンは画面の一番下に 1 列で並べ、犬（画面の中央）に重ねない */
  #actions {
    left: calc(6px + env(safe-area-inset-left, 0px));
    right: calc(6px + env(safe-area-inset-right, 0px));
    bottom: 6px;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
  }
  .act { height: 46px; border-radius: 11px; }
  .act-ic { font-size: 18px; }
  .act-tx { font-size: 9.5px; letter-spacing: 0; }
  #joy { width: 88px; height: 88px; bottom: 62px; left: calc(10px + env(safe-area-inset-left, 0px)); opacity: 0.7; }
  #joy-knob { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  #toast { bottom: 64px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .title-card { max-height: 100%; }
  /* 横向きのスマホでは右端に 2 列で縦に並べる */
  #actions { left: auto; right: calc(6px + env(safe-area-inset-right, 0px)); bottom: 6px; grid-template-columns: repeat(2, 50px); gap: 4px; }
  .act { height: 42px; }
  #joy { bottom: 12px; width: 84px; height: 84px; }
  #toast { bottom: 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; }
}
