/* 和水・八神巡り - やさしいデザイン */

:root {
  --ink: #3d2b1f;
  --ink-light: #6b5344;
  --paper: #faf6f0;
  --paper-dark: #ede5d8;
  --accent: #c0713a;
  --accent-dark: #9a5a2e;
  --accent-light: #e6c9a8;
  --accent-glow: rgba(192, 113, 58, 0.18);
  --r: 12px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 4px rgba(60, 40, 20, 0.10);
  --shadow: 0 2px 12px rgba(60, 40, 20, 0.13);
  --shadow-lg: 0 6px 24px rgba(60, 40, 20, 0.20);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  background: linear-gradient(160deg, #1a1410 0%, #2a1d14 100%);
  color: var(--ink);
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* あそびかた・設定ページ用（スクロール可能） */
html.page-settings,
body.page-settings {
  overflow-y: auto !important;
  overflow-x: hidden;
  height: auto !important;
  min-height: 100%;
  background: var(--paper);
}
body.page-settings .wrap {
  height: auto !important;
  min-height: auto;
  overflow: visible;
  justify-content: flex-start;
  padding: 1rem 0 2rem;
}

.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  padding: 0.5rem 0;
  overflow: hidden;
}

/* ===== ゲーム画面コンテナ ===== */
.game-screen {
  flex: 0 0 auto;
  position: relative;
  margin: 0 auto;
  background: #0a0806;
  border: 2px solid var(--accent-light);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: 0 0 32px rgba(192, 113, 58, 0.12);
}

#canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ===== スタート画面（論理480x720をtransformでスケール） ===== */
.start-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 480px;
  height: 720px;
  transform-origin: 0 0;
  transform: scale(var(--game-scale, 1));
  background: linear-gradient(180deg, rgba(10,8,4,0.96) 0%, rgba(26,18,10,0.98) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.start-overlay.hidden { display: none; }

.start-title {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--paper);
  margin: 0 0 0.2rem;
  letter-spacing: 0.1em;
  text-shadow: 0 2px 16px rgba(192, 113, 58, 0.5);
}
.start-subtitle {
  font-size: 1.1rem;
  color: var(--accent-light);
  margin: 0 0 3rem;
  letter-spacing: 0.18em;
  opacity: 0.85;
}
.start-menu {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

/* ===== ボタン共通 ===== */
.btn {
  display: block;
  width: 100%;
  max-width: 300px;
  padding: 0.85rem 1.2rem;
  font-size: 1.15rem;
  font-family: inherit;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: none;
  border-radius: var(--r);
  cursor: pointer;
  margin: 0.2rem auto;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  letter-spacing: 0.04em;
  min-height: 48px;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover,
.btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: var(--shadow-sm);
}
.btn:focus-visible {
  outline: 3px solid var(--accent-light);
  outline-offset: 2px;
}

.start-btn {
  font-size: 1.5rem;
  padding: 1rem 2rem;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #d4853f 0%, var(--accent-dark) 100%);
  box-shadow: 0 4px 24px rgba(192, 113, 58, 0.4);
  min-height: 56px;
}
.start-btn:hover,
.start-btn:focus-visible {
  box-shadow: 0 6px 32px rgba(192, 113, 58, 0.55);
}

.btn-sub {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
  color: var(--ink);
  border: 2px solid var(--accent-light);
}
.btn-sub:hover,
.btn-sub:focus-visible {
  border-color: var(--accent);
  background: linear-gradient(180deg, #fff 0%, var(--paper) 100%);
}

/* ===== ゲームオーバー／クリア画面（論理480x720をtransformでスケール） ===== */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 480px;
  height: 720px;
  transform-origin: 0 0;
  transform: scale(var(--game-scale, 1));
  background: linear-gradient(180deg, var(--paper) 0%, #f0e8dc 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2rem 1.5rem;
  overflow-y: auto;
}
.overlay.hidden { display: none; }

.overlay-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-dark);
  margin: 0.5rem 0 0.3rem;
  letter-spacing: 0.06em;
}
.overlay-score {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.2rem;
  color: var(--ink);
}

/* 名前入力 */
.name-form {
  margin-bottom: 1.2rem;
  width: 100%;
  max-width: 300px;
}
.overlay.view-only .name-form { display: none; }
.overlay.view-only .overlay-score { display: none; }

.name-form label {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--ink-light);
  font-weight: 500;
}
#playerName {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font-size: 1.2rem;
  font-family: inherit;
  border: 2px solid var(--accent-light);
  border-radius: var(--r);
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#playerName::placeholder { color: #bbb; }
#playerName:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ランキング */
.overlay-ranking {
  width: 100%;
  max-width: 300px;
  margin: 0.5rem 0;
}
.overlay-ranking-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--ink-light);
}
.ranking-list {
  font-size: 1rem;
  max-height: 200px;
  overflow-y: auto;
  border: 2px solid var(--paper-dark);
  border-radius: var(--r);
  background: #fff;
}
.ranking-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #f0ece4;
  min-height: 36px;
}
.ranking-item:last-child { border-bottom: none; }
.ranking-item:nth-child(1) { background: #fff8e0; }
.ranking-item:nth-child(2) { background: #f8f5f0; }
.ranking-item:nth-child(3) { background: #f5e6d3; }

.ranking-rank {
  font-weight: 700;
  min-width: 2.2rem;
  color: var(--accent-dark);
}
.ranking-name {
  flex: 1;
  margin: 0 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ranking-score {
  font-weight: 700;
  text-align: right;
  color: var(--ink);
}

/* ランキング空状態のテキスト */
.howto-text {
  padding: 1rem;
  text-align: center;
  color: var(--ink-light);
  font-size: 0.95rem;
}

.overlay-settings {
  margin: 0.5rem 0 0;
  font-size: 1rem;
}
.overlay-settings a { color: var(--accent); }

.footer-link {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--accent-light);
  letter-spacing: 0.05em;
}
.footer-link a { color: var(--accent-light); }
