:root {
  --bg: #17121e;
  --panel: #241b2e;
  --fg: #d8d8e0;
  --dim: #6a6a7a;
  --accent: #c9a227;
  --player: #ffd54a;
  --monster: #ff5a5a;
  --item: #5ad17a;
  --ally: #7ab8ff;
  --wall: #8a8a99;
  --floor: #45455a;
  --stairs: #4ad6e0;
  --mem: #2c2c3a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 8px;
}

.mutebtn {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 10;
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: rgba(20, 20, 31, 0.82);
  border: 1px solid #2a2a3a;
  border-radius: 10px;
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
}
.mutebtn:active { filter: brightness(1.4); }

/* ---- 共通スクリーン ---- */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 16px;
}
.hidden { display: none !important; }

.title {
  font-size: clamp(40px, 12vw, 72px);
  letter-spacing: 0.1em;
  margin: 0;
  color: var(--player);
  text-shadow: 0 0 18px rgba(255, 213, 74, 0.35);
}
.subtitle { color: var(--dim); margin: -6px 0 6px; letter-spacing: 0.3em; }
.story { line-height: 1.9; font-size: 15px; color: var(--fg); }
.legend { line-height: 1.8; font-size: 13px; color: var(--dim); }
h2 { color: var(--accent); font-weight: 600; margin: 6px 0; }

.big-btn {
  margin-top: 8px;
  padding: 14px 32px;
  font-size: 18px;
  color: #1a1a10;
  background: var(--player);
  border: none;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.big-btn:active { transform: translateY(1px); filter: brightness(0.92); }

/* ---- プレイ画面 ---- */
#game {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#statusbar {
  font-size: 13px;
  color: var(--fg);
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 10px;
  white-space: nowrap;
  overflow-x: auto;
}
#statusbar .hp { color: var(--item); }
#statusbar .warn { color: var(--monster); }
#statusbar .barrier { color: var(--stairs); }

#map {
  display: block;
  margin: 0 auto;
  align-self: center;
  background: #07070d;
  border-radius: 8px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  user-select: none;
  touch-action: none;
}
#map .c { display: inline; }
.k-player { color: var(--player); font-weight: 700; }
.k-monster { color: var(--monster); font-weight: 700; }
.k-item { color: var(--item); }
.k-ally { color: var(--ally); font-weight: 700; }
.k-wall { color: var(--wall); }
.k-floor { color: var(--floor); }
.k-stairs { color: var(--stairs); font-weight: 700; }
.k-mem { color: var(--mem); }
.k-dark { color: transparent; }

#log {
  font-size: 13px;
  color: var(--dim);
  min-height: 3.2em;
  line-height: 1.5;
  padding: 0 4px;
}
#log .latest { color: var(--fg); }

/* ---- 操作 ---- */
#controls {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 6px;
}
#dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  margin: 0 auto;
  width: 100%;
}
.dbtn {
  aspect-ratio: 1 / 1;
  font-size: 24px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid #2a2a3a;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.dbtn:active { background: #20203040; filter: brightness(1.6); }
.dbtn.wait { color: var(--dim); font-size: 18px; }

#actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.abtn {
  flex: 1;
  max-width: 160px;
  padding: 12px 8px;
  font-size: 15px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid #2a2a3a;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
}
.abtn:active { filter: brightness(1.4); }

/* ---- quick-bar (式神/アイテム ワンタップ) ---- */
#quickbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 2px 2px;
  scrollbar-width: none;
}
#quickbar::-webkit-scrollbar { display: none; }
.qbtn {
  flex: 0 0 auto;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--ally);
  background: var(--panel);
  border: 1px solid #2a3a5a;
  border-radius: 10px;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
}
.qbtn:active { filter: brightness(1.5); }
.qbtn .qn { margin-left: 5px; color: var(--dim); font-size: 11px; }

/* ---- 持ち物 ---- */
#inv-list { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 360px; }
.inv-item {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid #2a2a3a;
  border-radius: 10px;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.inv-item:active { filter: brightness(1.4); }
.inv-empty { color: var(--dim); }
