/* ==========================================================
   灰の旅人 - style.css
   配色方針: セピア/羊皮紙(生成り×茶)＋石造りダンジョン(グレー×暗褐色)。
   ドラクエ的な「濃紺×金縁」は使わない。
   ========================================================== */

:root {
  /* --- カラーパレット(一元定義) --- */
  --color-parchment: #ece0c4;
  --color-parchment-dark: #d8c79f;
  --color-ink: #3a2f22;
  --color-ink-soft: #5b4a35;
  --color-wood: #6b4a2f;
  --color-wood-dark: #4a3220;
  --color-stone: #6e6a63;
  --color-stone-dark: #3c3934;
  --color-stone-darker: #24221f;
  --color-accent: #a8471f;
  --color-accent-soft: #c97a3a;
  --color-hp: #7a2e1d;
  --color-hp-bar: #b5502b;
  --color-mp: #35505a;
  --color-mp-bar: #4d7c8a;
  --color-danger: #8a1f1f;
  --color-safe: #4a6b3d;

  --font-main: "DotGothic16", "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;

  --radius-panel: 4px;
}

* { box-sizing: border-box; }

/* ---------------- ドット絵スプライト共通(Kenney Tiny Dungeon, CC0) ---------------- */
.sprite-pixel {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-main);
  color: var(--color-ink);
  background: var(--color-stone-darker);
}

body {
  background-image:
    radial-gradient(ellipse at top, #3d3a34 0%, #201e1b 70%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  max-height: 860px;
  background: var(--color-stone-dark);
  overflow: hidden;
  box-shadow: 0 0 0 6px var(--color-wood-dark), 0 0 40px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
}

@media (min-width: 500px) {
  #app { height: 860px; border-radius: var(--radius-panel); }
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
}
.screen.active { display: flex; }

/* ---------------- タイトル / エンディング ---------------- */

#screen-title, #screen-ending {
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(20,18,16,0.4), rgba(20,18,16,0.75)),
    repeating-linear-gradient(45deg, #2b2825 0px, #2b2825 12px, #333029 12px, #333029 24px);
  padding: 24px;
}

.title-panel {
  background: var(--color-parchment);
  border: 3px solid var(--color-wood-dark);
  border-radius: var(--radius-panel);
  box-shadow: inset 0 0 0 2px var(--color-parchment-dark), 0 8px 24px rgba(0,0,0,0.5);
  padding: 32px 24px;
  text-align: center;
  width: 100%;
  max-width: 360px;
}

.title-hero-sprite {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 12px;
}

.ending-visual {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 18px;
  margin-bottom: 12px;
}
.ending-boss-sprite {
  width: 84px;
  height: 84px;
  filter: grayscale(0.7) brightness(0.6);
  opacity: 0.75;
  transform: rotate(8deg);
}
.ending-hero-sprite {
  width: 72px;
  height: 72px;
}

.game-title {
  font-size: 2.4rem;
  letter-spacing: 0.15em;
  color: var(--color-ink);
  margin: 0 0 4px;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.15);
}

.game-subtitle {
  margin: 0 0 20px;
  color: var(--color-ink-soft);
  letter-spacing: 0.1em;
  font-size: 0.85rem;
}

.flavor-text {
  color: var(--color-ink-soft);
  line-height: 1.8;
  margin: 0 0 28px;
  font-size: 0.95rem;
}

.ending-text {
  color: var(--color-ink);
  line-height: 2;
  font-size: 1.05rem;
  margin: 0 0 10px;
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.version-text {
  margin: 24px 0 0;
  font-size: 0.7rem;
  color: var(--color-ink-soft);
  opacity: 0.7;
}

/* ---------------- 共通ボタン ---------------- */

.btn {
  font-family: var(--font-main);
  font-size: 1rem;
  padding: 12px 20px;
  border: 2px solid var(--color-wood-dark);
  border-radius: var(--radius-panel);
  cursor: pointer;
  background: var(--color-wood);
  color: #f4ead2;
  box-shadow: 0 3px 0 var(--color-wood-dark);
  transition: transform 0.05s ease;
  letter-spacing: 0.05em;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--color-wood-dark); }
.btn:focus-visible { outline: 3px solid var(--color-accent-soft); outline-offset: 2px; }

.btn-primary { background: var(--color-accent); border-color: #6b2a10; box-shadow: 0 3px 0 #6b2a10; }
.btn-secondary { background: var(--color-stone); border-color: var(--color-stone-dark); box-shadow: 0 3px 0 var(--color-stone-dark); }
.btn-danger { background: var(--color-danger); border-color: #4a0f0f; box-shadow: 0 3px 0 #4a0f0f; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }

/* ---------------- マップ画面 ---------------- */

.hud {
  background: linear-gradient(180deg, var(--color-wood), var(--color-wood-dark));
  color: #f4ead2;
  padding: 8px 12px;
  border-bottom: 3px solid var(--color-wood-dark);
  flex-shrink: 0;
}
.hud-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
.hud-area { margin-top: 4px; font-size: 0.8rem; opacity: 0.85; }
.hud-item b { color: #ffe6b0; font-weight: normal; }

.map-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 1px;
  background: var(--color-stone-darker);
  padding: 4px;
  min-height: 0;
}

.tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  min-width: 0;
  min-height: 0;
}

.tile-V { background: #b79a63; }
.tile-I { background: #c9a659; }
.tile-S { background: #c9a659; }
.tile-P { background: #8fa15c; }
.tile-F { background: #3f5a3a; }
.tile-C { background: #52504c; }
.tile-B { background: #3a2028; box-shadow: inset 0 0 8px 2px #8a1f1f; }
.tile-W {
  background: repeating-linear-gradient(135deg, #514c44, #514c44 4px, #3a352f 4px, #3a352f 8px);
  box-shadow: inset 0 0 0 1px #201e1b;
}

.tile-icon { pointer-events: none; }

.tile-icon-img {
  width: 72%;
  height: 72%;
  object-fit: contain;
  pointer-events: none;
  filter: grayscale(0.4) brightness(0.75);
}

.tile.player::after {
  content: "";
  position: absolute;
  inset: 10%;
  background-image: url("assets/sprites/hero.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 1px rgba(0,0,0,0.7));
}

.toast {
  position: absolute;
  left: 50%;
  top: 68px;
  transform: translateX(-50%);
  background: rgba(20, 18, 16, 0.92);
  color: #f4ead2;
  padding: 8px 16px;
  border-radius: var(--radius-panel);
  border: 1px solid var(--color-wood);
  font-size: 0.8rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 20;
  max-width: 85%;
  text-align: center;
}
.toast.show { opacity: 1; }

.dpad {
  flex-shrink: 0;
  padding: 10px 16px 16px;
  background: var(--color-stone-dark);
  border-top: 2px solid var(--color-stone-darker);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.dpad-mid { display: flex; gap: 4px; align-items: center; }
.dpad-btn {
  width: 52px;
  height: 52px;
  font-size: 1.1rem;
  background: var(--color-stone);
  color: #f4ead2;
  border: 2px solid var(--color-stone-darker);
  border-radius: var(--radius-panel);
  box-shadow: 0 3px 0 var(--color-stone-darker);
  touch-action: manipulation;
}
.dpad-btn:active { transform: translateY(2px); box-shadow: none; }
.dpad-center { background: var(--color-wood); font-size: 1.3rem; }

/* ---------------- 戦闘画面 ---------------- */

#screen-battle {
  background:
    linear-gradient(180deg, rgba(20,18,16,0.2), rgba(20,18,16,0.6)),
    repeating-linear-gradient(45deg, #35322c 0px, #35322c 14px, #3d3a33 14px, #3d3a33 28px);
}

.battle-field {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.combatants {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  width: 100%;
  padding: 0 12px;
}

.player-area {
  flex-shrink: 0;
  padding-bottom: 22px;
}

.player-battle-sprite {
  width: 64px;
  height: 64px;
  filter: drop-shadow(0 6px 4px rgba(0,0,0,0.5));
}

.monster-area {
  text-align: center;
  padding: 16px;
  min-width: 0;
}

.monster-visual {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 112px;
  margin-bottom: 8px;
}

.monster-visual img {
  width: 112px;
  height: 112px;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.5));
}

.monster-visual img.monster-sprite-large {
  width: 160px;
  height: 160px;
}

.monster-visual .monster-emoji-fallback {
  font-size: 5rem;
  line-height: 1;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.5));
}

.monster-name {
  color: #f4ead2;
  font-size: 1.1rem;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.hpbar-frame {
  width: 220px;
  height: 14px;
  background: var(--color-stone-darker);
  border: 2px solid var(--color-wood-dark);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto;
}
.hpbar-fill {
  height: 100%;
  background: linear-gradient(180deg, var(--color-hp-bar), var(--color-hp));
  width: 100%;
  transition: width 0.3s ease;
}

.battle-log {
  flex-shrink: 0;
  background: var(--color-parchment);
  color: var(--color-ink);
  border-top: 3px solid var(--color-wood-dark);
  border-bottom: 1px solid var(--color-parchment-dark);
  padding: 10px 14px;
  font-size: 0.85rem;
  line-height: 1.6;
  height: 108px;
  overflow-y: auto;
}
.battle-log p { margin: 0 0 4px; }

.player-battle-status {
  flex-shrink: 0;
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 8px;
  background: var(--color-wood-dark);
  color: #f4ead2;
  font-size: 0.85rem;
}

.battle-panel {
  flex-shrink: 0;
  padding: 12px;
  background: var(--color-stone-dark);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-height: 132px;
}
.battle-panel .btn { width: 100%; }
.battle-panel.list {
  display: flex;
  flex-direction: column;
}

/* ---------------- モーダル(宿屋・道具屋・確認) ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 8, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.show { display: flex; }

.modal-box {
  background: var(--color-parchment);
  border: 3px solid var(--color-wood-dark);
  border-radius: var(--radius-panel);
  padding: 20px;
  width: 100%;
  max-width: 340px;
  color: var(--color-ink);
}
.modal-box h2 {
  margin: 0 0 12px;
  font-size: 1.2rem;
  border-bottom: 2px solid var(--color-parchment-dark);
  padding-bottom: 8px;
}
.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--color-parchment-dark);
  font-size: 0.9rem;
}
.modal-row:last-of-type { border-bottom: none; }
.modal-row .btn { padding: 8px 12px; font-size: 0.85rem; }
.modal-buttons {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}
.modal-buttons .btn { flex: 1; }
.modal-note {
  font-size: 0.8rem;
  color: var(--color-ink-soft);
  margin: 4px 0 0;
}

.item-icon {
  width: 18px;
  height: 18px;
  vertical-align: -4px;
  margin-right: 4px;
}

.btn-icon {
  width: 15px;
  height: 15px;
  vertical-align: -2px;
  margin-right: 5px;
}

/* ---------------- スクロールバー(細め) ---------------- */
.battle-log::-webkit-scrollbar { width: 6px; }
.battle-log::-webkit-scrollbar-thumb { background: var(--color-parchment-dark); border-radius: 3px; }
