:root {
  --brown: #8a5a34;
  --brown-soft: #d9b48f;
  --bg: #fdf6ee;
  --text-muted: #9c8b7a;
}
* { box-sizing: border-box; }
/* スマホ縦画面前提のゲーム。max-width指定が無いと、PCの広い画面で#grid-viewportの
   幅(=セルサイズの計算元)がそのまま巨大になり、岩が数百pxの正方形になって
   ほとんど画面外にはみ出す事故になっていた(セルサイズ = ビューポート幅÷7)。 */
html { display: flex; justify-content: center; background: #d8cdbf; }
body {
  margin: 0;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  position: relative;
  font-family: "M PLUS Rounded 1c", sans-serif;
  background: var(--bg);
  color: #3a2c1e;
  overscroll-behavior: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.hidden { display: none !important; }

.sound-controls { position: absolute; top: 8px; right: 8px; z-index: 60; display: flex; gap: 4px; }
.mute-btn { border: none; background: #fff; border-radius: 999px; width: 34px; height: 34px; font-size: 16px; }

.site-footer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 55;
  background: #fff8ef; border-top: 1px solid var(--brown-soft);
  padding: 6px 10px; font-size: 11px; text-align: center;
}
.footer-links a, .footer-meta a { color: var(--text-muted); text-decoration: none; }
.version-link { border-bottom: 1px dotted currentColor; }
.copyright { color: var(--text-muted); }

.screen { min-height: 100vh; padding: 24px 16px 100px; display: flex; align-items: center; justify-content: center; }
.panel { max-width: 420px; width: 100%; text-align: center; }
.hero-emoji { font-size: 48px; }
.title { font-size: 22px; margin: 4px 0; }
.lead { font-size: 13px; color: #5a4632; }

.link-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 10px 0; }
.rules-link, .link-row .home-link, .share-button {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px;
  border: 2px solid var(--brown-soft); border-radius: 999px; background: #fff;
  color: var(--brown); font-size: 12px; font-weight: 700; text-decoration: none;
}

.field { display: block; margin: 12px 0; font-size: 12px; text-align: left; }
.field input { width: 100%; padding: 10px; border-radius: 10px; border: 2px solid var(--brown-soft); font-size: 14px; margin-top: 4px; }

.primary-button {
  width: 100%; padding: 12px; border-radius: 999px; border: none; background: var(--brown);
  color: #fff; font-size: 16px; font-weight: 700; margin-top: 10px;
}
.secondary-button {
  padding: 10px 16px; border-radius: 999px; border: 2px solid var(--brown-soft); background: #fff; color: var(--brown);
}
.join-error { color: #c0392b; font-size: 12px; margin-top: 6px; }

.ranking-block { margin-top: 20px; text-align: left; }
.ranking-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.ranking-list { list-style: decimal; padding-left: 20px; font-size: 13px; margin: 0; }

/* .screenの既定(align-items:center; justify-content:center)は「中身をぎゅっと真ん中に
   寄せる」タイトル画面向けの設定で、ゲーム画面に効くと#grid-viewportが横幅0まで
   縮んでしまう(cs=0pxになり盤面が消える事故が実際に起きた)。ゲーム画面は
   幅いっぱいに広げる必要があるので上書きする。 */
/* min-height:100vhのまま(上の.screen由来)だと、内容がその分だけ縦に伸びて
   スクロールが発生し、画面全体が実際のスマホ画面より大きく見える事故になっていた。
   ゲーム画面はちょうど1画面に収める。 */
#screen-game { height: 100vh; min-height: 0; box-sizing: border-box; flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 8px 8px 54px; display: flex; overflow: hidden; }

/* 地上パート(画面比率 地上3:地下7)。 */
/* 空の色だけで地面の概念が無く、キャラクターが浮いて見えていたため、
   はっきりした地面(茶色の帯)を敷いて、キャラクター・スポットがその上に
   立っているように見せる。 */
#ground-panel {
  flex: 3; min-height: 0; position: relative; border-radius: 10px; margin-bottom: 4px; overflow: hidden;
  background: linear-gradient(#a8d8ea 0%, #a8d8ea 62%, #7fb86a 62%, #6aa858 100%);
}
#ground-panel::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 38%; z-index: 0;
  background: #8a6a4a; border-top: 4px solid #6f5238;
}
#ground-scene { z-index: 1; }
/* 絶対位置(%指定)で組んでいたところ、コンテナの高さ計算タイミングによって
   要素が枠外に飛ぶ事故が起きたため、素直なflexレイアウトに変更した。 */
#ground-scene { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; }
#ground-char-row { flex: 1; display: flex; align-items: flex-end; padding-bottom: 4px; }
.ground-char-canvas { width: 48px; height: 48px; transition: margin-left .45s ease, opacity .3s; display: block; }
#ground-char { margin-left: 22%; }
#ground-char2 { margin-left: 4px; } /* ぽんすけ。地下に降りたら隠す */
#ground-char2.hidden { opacity: 0; pointer-events: none; }
#spots-row { display: flex; justify-content: space-around; align-items: flex-end; padding-bottom: 6px; }
/* カゴ置き場とお店の間に垂れたロープの先のカゴ(スケッチのU字型)。
   状態(surface/descending/atRow/ascending)に応じて見た目を変える。 */
#basket-rope { width: 2px; height: 30px; background: #8a6a4a; margin-bottom: 8px; }
#basket-cage {
  width: 26px; height: 18px; margin: 30px 0 0 -12px; border: 3px solid #8a6a4a; border-top: none;
  border-radius: 0 0 6px 6px; background: rgba(217, 178, 122, .5); transition: opacity .3s;
}
#basket-cage.moving { opacity: .5; }
.spot { width: 70px; text-align: center; font-size: 22px; cursor: pointer; }
.spot-icon { width: 40px; height: 40px; }
.spot-icon-box {
  width: 40px; height: 40px; margin: 0 auto; border-radius: 8px; background: #d9534f;
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: bold;
}
.spot-label { font-size: 9px; color: #333; font-weight: bold; background: rgba(255,255,255,.75); border-radius: 6px; padding: 1px 4px; display: inline-block; }
#obstacle-mark {
  position: absolute; top: 8px; left: 20%; cursor: pointer; z-index: 6; display: none;
  background: #6b4a2f; color: #fff; font-size: 11px; font-weight: bold; border-radius: 999px; padding: 3px 10px;
}

.ground-menu {
  position: absolute; left: 4px; right: 4px; bottom: 4px; z-index: 2; background: rgba(255,255,255,.96);
  border-radius: 10px; padding: 8px; font-size: 11px; display: flex; flex-direction: column; gap: 4px;
  max-height: 82%; overflow-y: auto; box-shadow: 0 -2px 8px rgba(0,0,0,.2);
}
.ground-menu h4 { margin: 0 0 2px; font-size: 12px; display: flex; justify-content: space-between; }
.ground-menu .close-btn { font-size: 11px; background: #eee; border: none; border-radius: 5px; padding: 1px 8px; }
.shop-btn, .action-btn { background: #fff; border: 1px solid #999; border-radius: 6px; padding: 6px; font-size: 11px; text-align: left; }
.shop-btn:disabled, .action-btn:disabled { opacity: .4; }

.not-started-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.5); color: #fff; display: none;
  flex-direction: column; align-items: center; justify-content: center; text-align: center; font-size: 13px; padding: 0 16px; z-index: 5;
}
.not-started-overlay.visible { display: flex; }
.not-started-overlay .small { font-size: 11px; margin-top: 4px; }
#hud { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pill { background: #fff; border: 1px solid var(--brown-soft); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.hud-quit-button { border: none; background: #eee; border-radius: 999px; padding: 3px 10px; font-size: 12px; }

/* セルサイズ(--cs)はmain.jsが「画面幅÷7」で計算してsetする(プロトタイプと同じ方式)。
   grid-template-columnsだと狭い画面で列が折り返し/クリップされる事故があったため、
   固定px幅のflex行に変更した。 */
#grid-viewport { flex: 7; overflow: hidden; position: relative; }
.grid-row { display: flex; }
.cell {
  width: var(--cs); height: var(--cs); flex: 0 0 var(--cs);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cs) * 0.45); cursor: pointer; box-sizing: border-box;
  border: 1px solid rgba(0,0,0,0.1);
}
.cell.empty { background: transparent; border-color: transparent; }
.cell.rock-stone { background: #b8b0a4; }
.cell.rock-copper { background: #c9814f; }
.cell.rock-iron { background: #8c8f96; }
.cell.rock-gold { background: #e6bd3a; }
.cell.rock-diamond { background: #7fd6e0; }
.cell.player { background: #ff9dbb !important; }
.cell.basket { background: #f0d9a0 !important; }
/* プレイヤーの3Dモデル。.cellの上に絶対配置で重ね、main.jsが座標(--cs基準)を
   更新する。cellそのものはヒットテスト用に薄いピンクのまま残す。 */
.mine-player-canvas { position: absolute; width: var(--cs); height: var(--cs); pointer-events: none; z-index: 3; transition: left .12s linear, top .12s linear; }

.dpad { position: absolute; right: 16px; bottom: 100px; display: grid; grid-template-columns: 44px 44px 44px; grid-template-rows: 44px 44px; gap: 4px; }
.dpad-btn { border: none; border-radius: 10px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); font-size: 18px; }
.dpad-btn[data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad-btn[data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad-btn[data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad-btn[data-dir="right"] { grid-column: 3; grid-row: 2; }

.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: #fff; border-radius: 16px; padding: 24px; text-align: center; width: 280px; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-score { margin: 12px 0; font-size: 16px; }
.modal-buttons { display: flex; gap: 8px; flex-direction: column; }

.legal-modal { position: absolute; inset: 0; background: rgba(0,0,0,.6); z-index: 100; }
.legal-modal-box { position: absolute; inset: 4% 5%; background: #fff; border-radius: 12px; overflow: hidden; }
.legal-modal-frame { width: 100%; height: 100%; border: none; }
.legal-modal-close { position: absolute; top: 8px; right: 8px; border: none; background: #eee; border-radius: 999px; width: 32px; height: 32px; z-index: 1; }
