/* =========================================================
   でんしゃすごろく３D 茨城編（ドット絵スタイル・斜め見下ろし）

   角丸・ぼかし・グラデーションを使わず、太い輪郭線と
   ずらした四角い影だけで、ドット絵ゲームの見た目にする。
   絵文字は使わず、絵はすべて自前のドット絵（pixelicons.js）。
   ========================================================= */

:root {
  --line: #241a12;      /* 輪郭線（すべての枠に使う濃い色） */
  --bg: #cfe0f2;
  --paper: #fdfbf4;     /* 紙・パネルの色 */
  --paper-2: #efe6d6;
  --ink: #241a12;
  --ink-weak: #7a6a58;

  --head: #2a4a8f;
  --head-d: #16295c;
  --blue: #2f6bd8;
  --blue-d: #17398a;
  --red: #e03a3a;
  --red-d: #8f1c1c;
  --green: #38a83a;
  --green-d: #1c6b1e;
  --gray: #a8a294;
  --gray-d: #6b6659;
  --gold: #f5c033;
  --gold-d: #a97c14;
  --purple: #a765e8;

  --plus: #1f7a2e;
  --minus: #c02626;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--ink);
  /* 端末にドットフォントが入っていれば使う。無ければ標準の書体にする */
  font-family: "DotGothic16", "PixelMplus12", "PixelMplus10", "Misaki Gothic", "美咲ゴシック",
               "k12x10", "Silkscreen", "Press Start 2P",
               -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-weight: 800;
  /* 文字のぼかし（アンチエイリアス）を切って、輪郭をドットらしく硬くする */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  font-smooth: never;
  text-rendering: geometricPrecision;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

/* 実行時に作ったドット文字の画像 */
.pixel-text {
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ドット絵アイコン（絵文字の代わり） */
.slot-emoji { font-size: inherit; }

.pixel-icon {
  display: inline-block;
  vertical-align: -0.15em;
  shape-rendering: crispEdges;
}

#app {
  display: grid;
  /* マップの行は minmax(0,1fr) にする。ただの 1fr だと最小サイズが「中身なり」に
     なり、SVG の viewBox（＝縦横比）が行の高さを押し広げてしまう。
     すると 高さが変わる → viewBox を測り直す → また高さが変わる、とぐるぐる回る。 */
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--paper);
}

/* ---------- ステータスバー ---------- */

#status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 8px;
  padding-top: max(7px, env(safe-area-inset-top));
  background: var(--head);
  border-bottom: 4px solid var(--line);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}

#calendar b { font-size: 14px; font-weight: 900; }
#calendar small { display: block; font-size: 10px; font-weight: 800; color: var(--gold); }

#goal {
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  font-weight: 900;
  padding: 4px 8px;
  background: var(--gold);
  border: 3px solid var(--line);
  color: var(--line);
}

.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  background: var(--paper);
  color: var(--line);
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--line);
}

.icon-btn:active { transform: translateY(3px); box-shadow: none; }

.icon-btn:disabled {
  opacity: .4;
  box-shadow: none;
  transform: none;
  cursor: default;
}

/* ---------- いまだれの番か ---------- */

.turn-badge {
  --player-color: var(--gray);
  min-height: 26px;   /* 名まえの長さで高さが変わり、マップが動くのを防ぐ */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 4px 8px;
  background: var(--player-color);
  border-bottom: 3px solid var(--line);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .35);
  white-space: nowrap;
}

.turn-badge b { font-size: 14px; }
.turn-badge.is-mine { animation: turn-mine 1s steps(2) infinite; }

@keyframes turn-mine {
  0%, 100% { box-shadow: inset 0 0 0 0 var(--gold); }
  50%      { box-shadow: inset 0 -4px 0 0 var(--gold); }
}

/* ---------- プレイヤー情報（4人） ---------- */

#players {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 5px 5px 3px;
}

#players[data-count="3"] { grid-template-columns: repeat(3, 1fr); }
#players[data-count="2"] { grid-template-columns: repeat(2, 1fr); }

.player-card {
  --player-color: #a8a294;
  min-width: 0;
  /* 中身が増えても高さが変わらないようにしておく。
     ここが伸び縮みすると、その下のマップの高さも動いてしまう */
  min-height: 74px;
  padding: 3px 2px;
  background: var(--paper-2);
  border: 3px solid var(--line);
  border-left: 6px solid var(--player-color);
  text-align: center;
  line-height: 1.2;
}

.player-card.is-current {
  background: var(--gold);
  box-shadow: 0 4px 0 var(--line);
}

.player-top   { font-size: 9px;  font-weight: 900; color: var(--ink-weak); }
.player-name  {
  font-size: 10px; font-weight: 900; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.player-money { font-size: 15px; font-weight: 900; color: var(--plus); }
.player-sub   { font-size: 9px;  font-weight: 900; color: var(--ink-weak); }
.player-sub small { font-size: 9px; font-weight: 900; display: block; }

.player-me {
  display: inline-block;
  margin-left: 2px;
  padding: 0 3px;
  background: var(--line);
  color: var(--gold);
  font-size: 8px;
}

.player-card.is-current .player-top,
.player-card.is-current .player-sub { color: var(--line); }

/* 所持金の表示（物件パネルなど） */
.wallet {
  margin-top: 8px;
  padding: 6px;
  background: var(--paper-2);
  border: 3px solid var(--line);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.wallet b { font-size: 15px; }
.wallet span { display: block; font-size: 11px; font-weight: 900; }
.wallet .is-left  { color: var(--ink-weak); }
.wallet .is-short { color: var(--minus); }

/* 総資産の割合バー */
.asset-bar {
  display: flex;
  height: 9px;
  margin: 0 5px 4px;
  border: 3px solid var(--line);
  background: var(--paper-2);
  overflow: hidden;
}

.asset-seg { transition: width .4s steps(8); }

/* ---------- マップ ---------- */

#board {
  position: relative;
  overflow: hidden;
  min-height: 0;      /* 中身（SVG）に高さを押し広げさせない */
  background: #2f86b8;
  border-top: 4px solid var(--line);
  border-bottom: 4px solid var(--line);
}

#map {
  position: absolute;  /* 箱の高さ計算から外して、レイアウトの堂々めぐりを断つ */
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

#map .token { transition: transform .16s steps(4); }
#map .token.is-current polygon:nth-of-type(3) { stroke: var(--gold); stroke-width: 4; }
#map .token.is-resting { opacity: .65; }

/* 目的地の合図。マス本体は光らせず、外側の枠とマーカーだけをゆっくり動かす */
#map .goal-flag { animation: goal-flag 1.4s steps(2) infinite; }
#map .goal-ring { animation: goal-ring 1.2s steps(2) infinite; }

/* SVGの拡大は原点(0,0)が基準になり、離れた場所ほど大きくずれる。上下の動きだけにする */
@keyframes goal-flag {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

@keyframes goal-ring {
  0%, 100% { stroke: #f5c033; stroke-width: 4; }
  50%      { stroke: #fbe4a4; stroke-width: 6; }
}

/* ヘッダーの目的地表示は、色を変えずに枠だけ静かに変える */
#goal.is-goal-blink { animation: goal-chip 1.2s steps(2) infinite; }

@keyframes goal-chip {
  0%, 100% { background: var(--gold); color: var(--line); }
  50%      { background: #fbe4a4;     color: var(--line); }
}

/* 位置は JS が動かす。ふわふわは内側の g にかける（同じ要素だと位置が消える） */
#map .tohoho { transition: transform .16s steps(4); }
#map .tohoho-float { animation: tohoho-float .7s steps(3) infinite; }

@keyframes tohoho-float {
  0%, 100% { transform: translateY(0); }
  33%      { transform: translateY(-4px); }
  66%      { transform: translateY(-8px); }
}

.map-tools { position: absolute; right: 6px; top: 6px; display: grid; gap: 5px; z-index: 4; }

/* ---------- エフェクト層 ---------- */

.fx-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}

/* 飛び出す金額 */
.fx-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 4px 10px;
  background: var(--paper);
  border: 3px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
  font-size: 20px;
  font-weight: 900;
  white-space: nowrap;
  animation: fx-popup 1.4s steps(14) forwards;
}

.fx-popup.tone-plus  { color: var(--plus); }
.fx-popup.tone-minus { color: var(--minus); }
.fx-popup.tone-gold  { color: var(--gold-d); background: var(--gold); }

@keyframes fx-popup {
  0%   { transform: translate(-50%, -20%) scale(.6); opacity: 1; }
  25%  { transform: translate(-50%, -60%) scale(1.15); opacity: 1; }
  40%  { transform: translate(-50%, -70%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -190%) scale(1); opacity: 0; }
}

/* キラキラ */
.fx-particle {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid var(--line);
  animation: fx-fly 1.1s steps(11) forwards;
}

.fx-particle.is-coin { background: var(--gold); }
.fx-particle.is-star { background: #fdfbf4; }
.fx-particle.is-dust { background: #9a8fc4; }

@keyframes fx-fly {
  0%   { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  30%  { transform: translate(calc(-50% + var(--dx) * .5), calc(-50% + var(--dy) * .5)) scale(1.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 40px)) scale(.5); opacity: 0; }
}

/* 紙吹雪 */
.fx-confetti {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 13px;
  border: 2px solid var(--line);
  animation: fx-fall 2.4s steps(24) forwards;
}

@keyframes fx-fall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110%) rotate(calc(var(--spin) * 720deg)); opacity: 1; }
}

/* 画面が光る */
.fx-flash {
  position: absolute;
  inset: 0;
  animation: fx-flash .45s steps(4) forwards;
}

.fx-flash.tone-gold   { background: #f5c033; }
.fx-flash.tone-red    { background: #e03a3a; }
.fx-flash.tone-white  { background: #ffffff; }
.fx-flash.tone-purple { background: #a765e8; }

@keyframes fx-flash {
  0%   { opacity: .55; }
  100% { opacity: 0; }
}

/* 手番が変わったとき、画面のふちがその人の色に光る */
.fx-turn-glow {
  position: absolute;
  inset: 0;
  border: 8px solid var(--glow, #fff);
  animation: fx-turn-glow .9s steps(6) forwards;
}

@keyframes fx-turn-glow {
  0%   { opacity: .85; }
  100% { opacity: 0; }
}

/* 中央のでかい文字 */
.fx-banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  background: var(--line);
  border: 4px solid var(--paper);
  color: var(--gold);
  font-size: 26px;
  font-weight: 900;
  white-space: nowrap;
  animation: fx-banner 1.3s steps(13) forwards;
}

.fx-banner.tone-red { color: #ff9a9a; }

@keyframes fx-banner {
  0%   { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  35%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -110%) scale(.9); opacity: 0; }
}

/* 横に流れる帯 */
.fx-ribbon {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  padding: 6px 0;
  background: var(--line);
  color: var(--gold);
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  animation: fx-ribbon 1.7s steps(17) forwards;
}

@keyframes fx-ribbon {
  0%   { transform: translateX(-100%); }
  20%  { transform: translateX(0); }
  80%  { transform: translateX(0); }
  100% { transform: translateX(100%); }
}

/* マップの揺れ */
#board.is-shaking     { animation: board-shake .3s steps(6) 1; }
#board.is-shaking-big { animation: board-shake-big .48s steps(8) 1; }

@keyframes board-shake {
  0%, 100% { transform: translate(0, 0); }
  25%      { transform: translate(-3px, 2px); }
  50%      { transform: translate(3px, -2px); }
  75%      { transform: translate(-2px, -3px); }
}

@keyframes board-shake-big {
  0%, 100% { transform: translate(0, 0); }
  20%      { transform: translate(-7px, 4px); }
  40%      { transform: translate(7px, -5px); }
  60%      { transform: translate(-5px, -6px); }
  80%      { transform: translate(5px, 3px); }
}

/* ---------- さいころ ---------- */

/* サイコロの置き場所。振っている間は右下、止まると左へ転がっていく */
.dice-slot {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;          /* 文字ウィンドウ（5）より手前。かならず見えるようにする */
  display: flex;
  flex-direction: column;   /* 上にサイコロ、下に「のこり◯」 */
  align-items: flex-start;
  gap: 4px;
  padding: 5px;
  background: rgba(36, 26, 18, .35);
  border: 3px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transform: translate(var(--dx, 12px), var(--dy, 12px));
  transition: transform .55s steps(11), opacity .15s steps(2);
}

.dice-slot.is-visible { opacity: 1; }

.dice-main { display: flex; align-items: center; gap: 6px; }
.dice-row { display: flex; gap: 5px; }

/* サイコロ1個の面（中身は16×16のドット絵。枠線はここで付ける） */
.die {
  display: block;
  line-height: 0;
  background: var(--paper);
  border: 4px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
}

.die .pixel-icon { display: block; }

/* サイコロが増えたときの「◯こ」表示 */
.dice-badge {
  display: grid;
  padding: 3px 7px;
  background: var(--gold);
  border: 3px solid var(--line);
  color: var(--line);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.dice-badge b { font-size: 17px; }
.dice-badge small { font-size: 11px; font-weight: 900; }

/* 放り上げて、2回バウンドして止まる */
.dice-slot.is-tossing .die { animation: dice-toss .82s steps(16) infinite; }

@keyframes dice-toss {
  0%   { transform: translateY(10px)   rotate(0deg)   scale(.75); }
  14%  { transform: translateY(-90px)  rotate(140deg) scale(1.15); }
  30%  { transform: translateY(-120px) rotate(280deg) scale(1.2); }
  46%  { transform: translateY(-46px)  rotate(420deg) scale(1.05); }
  56%  { transform: translateY(6px)    rotate(520deg) scale(1.1); }
  60%  { transform: translateY(10px)   rotate(540deg) scale(1.25) scaleY(.75); }
  70%  { transform: translateY(-50px)  rotate(640deg) scale(1); }
  84%  { transform: translateY(8px)    rotate(720deg) scale(1.15) scaleY(.85); }
  92%  { transform: translateY(-18px)  rotate(760deg) scale(1); }
  100% { transform: translateY(10px)   rotate(780deg) scale(1); }
}

/* 着地の踏ん張り */
.dice-slot.is-landed .die { animation: dice-land .34s steps(7) 1; }

@keyframes dice-land {
  0%   { transform: translateY(-30px) scale(1.1); }
  35%  { transform: translateY(0)     scale(1.3) scaleY(.7); }
  60%  { transform: translateY(-10px) scale(.92) scaleY(1.1); }
  80%  { transform: translateY(0)     scale(1.08) scaleY(.92); }
  100% { transform: translateY(0)     scale(1); }
}

/* 定位置へ転がっていくあいだ、コロコロ回す */
.dice-slot.is-moving .die { animation: dice-tumble .55s steps(11) 1; }

@keyframes dice-tumble {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(-360deg); }
}

/* 移動中の「のこり◯マス」表示。サイコロの真下に置く */
.dice-steps {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 2px 10px;
  background: var(--gold);
  border: 3px solid var(--line);
}

.dice-steps-label { font-size: 12px; font-weight: 900; color: var(--line); }
.dice-steps-num   { font-size: 24px; font-weight: 900; color: var(--line); }

/* ---------- パネル ---------- */

.panel {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 6px;
  z-index: 5;
  /* マップを塞がないよう、ひとことは画面の4割まで／一覧でも6割まで */
  max-height: 40%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
  background: var(--paper);
  border: 4px solid var(--line);
  box-shadow: 6px 6px 0 rgba(36, 26, 18, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s steps(2);
}

.panel.size-large { max-height: 62%; }

.panel.is-visible { opacity: 1; pointer-events: auto; }
.panel.tone-plus  { border-color: var(--plus); }
.panel.tone-minus { border-color: var(--minus); }

.panel-text {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.6;
  text-align: center;
  white-space: pre-line;
}

.tone-plus  .panel-text { color: var(--plus); }
.tone-minus .panel-text { color: var(--minus); }
.tone-rest  .panel-text { color: var(--ink-weak); }

.panel-head {
  padding: 3px;
  margin: -4px -4px 8px;
  background: var(--line);
  color: var(--paper);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.panel-note {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 900;
  color: var(--ink-weak);
  text-align: center;
}

/* リボン見出し */
.ribbon {
  margin: -4px -4px 10px;
  padding: 7px 10px;
  background: var(--red);
  border-bottom: 4px solid var(--line);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  text-align: center;
}

.ribbon-big { font-size: 15px; }

/* 物件カード */
.prop-name { margin: 4px 0 8px; font-size: 20px; font-weight: 900; text-align: center; }
.prop-info { display: flex; justify-content: center; gap: 10px; }
.prop-price, .prop-rate {
  padding: 3px 8px;
  border: 3px solid var(--line);
  font-size: 17px;
  font-weight: 900;
}
.prop-price { background: var(--red); color: #fff; }
.prop-rate  { background: var(--blue); color: #fff; }

/* 物件一覧 */
.props-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }

.props-list li {
  display: grid;
  grid-template-columns: 6em auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: var(--paper-2);
  border: 2px solid var(--line);
  font-size: 12px;
  font-weight: 900;
}

.props-dots { display: flex; gap: 3px; }
.dot { width: 11px; height: 11px; border: 2px solid var(--line); }
.props-mine { font-size: 11px; color: var(--ink-weak); text-align: right; }

/* カード */
.cards-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px 8px;
}

.card-tile {
  --c: #6b6659;
  flex: 0 0 94px;
  display: grid;
  gap: 2px;
  padding: 8px 5px;
  border: 4px solid var(--line);
  background: var(--c);
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--line);
}

.card-tile:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.card-tile.is-locked { opacity: .45; box-shadow: none; }
.card-icon { line-height: 0; }
.card-name { font-size: 13px; font-weight: 900; }
.card-desc { font-size: 10px; font-weight: 800; line-height: 1.3; }

/* だれかを選ぶタイル（いれかえカード） */
.who-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.who-tile {
  --c: #6b6659;
  display: grid;
  gap: 2px;
  padding: 8px 4px;
  border: 4px solid var(--line);
  background: var(--c);
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--line);
}

.who-tile:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.who-icon { line-height: 0; }
.who-name { font-size: 12px; font-weight: 900; }
.who-sub  { font-size: 9px; font-weight: 800; line-height: 1.3; }

/* 決算 */
.settle-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }

.settle-list li {
  --player-color: #a8a294;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--paper-2);
  border: 3px solid var(--line);
  border-left: 8px solid var(--player-color);
}

.settle-name { font-size: 12px; font-weight: 900; }
.settle-detail { font-size: 10px; font-weight: 800; color: var(--ink-weak); text-align: left; }
.settle-amount { font-size: 14px; font-weight: 900; color: var(--ink-weak); }
.settle-amount.is-plus { color: var(--plus); }

/* メニュー */
.menu-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.menu-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 3px solid var(--line);
  background: var(--paper-2);
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line);
}

.menu-list button:active { transform: translateY(4px); box-shadow: none; }
.menu-list button b { color: var(--blue-d); }

.menu-info {
  padding: 8px;
  background: var(--head);
  border: 3px solid var(--line);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

/* マスの凡例 */
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }

.legend-list li {
  display: grid;
  grid-template-columns: 30px 5em 1fr;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 900;
}

.legend-chip {
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  border: 3px solid;
  line-height: 0;
}

.legend-name { font-size: 12px; }
.legend-desc { color: var(--ink-weak); text-align: left; }

/* トースト */
.toast {
  position: absolute;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 7px 12px;
  background: var(--line);
  border: 3px solid var(--paper);
  color: var(--paper);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s steps(2);
}

.toast.is-visible { opacity: 1; }

/* ---------- 巨大ボタン（最大4つ） ---------- */

#controls {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 7px;
  padding: 8px;
  padding-bottom: max(9px, env(safe-area-inset-bottom));
  background: var(--paper);
}

.slot {
  --c: var(--blue);
  --c-d: var(--blue-d);
  display: grid;
  align-content: center;
  gap: 1px;
  min-height: 80px;
  padding: 5px 3px;
  border: 4px solid var(--line);
  background: var(--c);
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--c-d), 0 6px 0 4px var(--line);
  transition: none;
}

.slot:active { transform: translateY(6px); box-shadow: 0 0 0 4px var(--line); }
.slot[hidden] { display: none; }

.slot:disabled {
  --c: var(--gray);
  --c-d: var(--gray-d);
  color: var(--paper-2);
  cursor: default;
  transform: none;
}

.slot-icon  { line-height: 1.1; }
.slot-label { font-size: 16px; font-weight: 900; line-height: 1.2; }
.slot-sub   { font-size: 12px; font-weight: 900; line-height: 1.2; }

.tone-blue  { --c: var(--blue);  --c-d: var(--blue-d); }
.tone-red   { --c: var(--red);   --c-d: var(--red-d); }
.tone-green { --c: var(--green); --c-d: var(--green-d); }
.tone-gray  { --c: var(--gray);  --c-d: var(--gray-d); }
.tone-gold  { --c: var(--gold);  --c-d: var(--gold-d); color: var(--line); }

/* ボタンが1つのときは横長に */
#controls[data-count="1"] .slot {
  min-height: 62px; grid-auto-flow: column; justify-content: center; gap: 8px;
}
#controls[data-count="1"] .slot-label { font-size: 19px; }

/* 分かれ道は最大4つ。1列に並べるので、4つのときだけ文字を詰める */
#controls[data-count="4"] .slot { padding: 4px 1px; }
#controls[data-count="4"] .slot-label { font-size: 12px; }
#controls[data-count="4"] .slot-sub   { font-size: 10px; }

/* 方向ボタンは矢印を大きく、駅名は小さく */
#controls .slot[data-dir] .slot-icon  { line-height: 1; }
#controls .slot[data-dir] .slot-label { font-size: 12px; }
#controls .slot[data-dir] .slot-sub   { font-size: 10px; }

/* ---------- オーバーレイ ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow-y: auto;
  background: var(--head-d);
  transition: opacity .2s steps(3);
}

.overlay.is-hidden { opacity: 0; pointer-events: none; }

.overlay-inner {
  width: 100%;
  max-width: 380px;
  text-align: center;
  color: #fff;
}

.title-train { line-height: 0; margin-bottom: 4px; }

.title {
  margin: 0 0 6px;
  font-size: 38px;
  line-height: 1.15;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 4px 4px 0 var(--line);
}

.title-line { display: block; }
.title-line .pixel-text { filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, .5)); }

.subtitle {
  display: inline-block;
  margin: 0 0 14px;
  padding: 3px 12px;
  background: var(--paper);
  border: 3px solid var(--line);
  color: var(--line);
  font-size: 13px;
  font-weight: 900;
}

.lead { margin: 0 0 16px; font-size: 13px; line-height: 1.7; font-weight: 800; }
.lead b { color: var(--gold); }

.years { margin-bottom: 14px; }
.years-label { font-size: 11px; font-weight: 900; color: var(--gold); }
.years-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 6px; }

.year-chip {
  display: grid;
  padding: 8px 3px;
  border: 3px solid var(--line);
  background: var(--head);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--line);
}

.year-chip small { font-size: 9px; font-weight: 800; }
.year-chip.is-on { background: var(--gold); color: var(--line); }

.big-btn {
  width: 100%;
  min-height: 62px;
  margin-top: 10px;
  border: 4px solid var(--line);
  background: var(--red);
  color: #fff;
  font-family: inherit;
  font-size: 21px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--red-d), 0 6px 0 4px var(--line);
}

.big-btn small { display: block; font-size: 11px; font-weight: 800; }
.big-btn:active { transform: translateY(6px); box-shadow: 0 0 0 4px var(--line); }
.big-btn:disabled { background: var(--gray); box-shadow: 0 6px 0 var(--gray-d), 0 6px 0 4px var(--line); cursor: default; }
.big-btn.is-sub {
  background: var(--blue);
  box-shadow: 0 6px 0 var(--blue-d), 0 6px 0 4px var(--line);
  font-size: 18px;
}
.big-btn[hidden] { display: none; }

.text-btn {
  margin-top: 14px;
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--gold);
  font-family: inherit;
  font-size: 13px;
  font-weight: 900;
  text-decoration: underline;
  cursor: pointer;
}

/* 入力欄（名まえ・合言葉） */
.field { display: block; margin-bottom: 10px; text-align: left; }
.field-label { display: block; margin-bottom: 3px; font-size: 11px; font-weight: 900; color: var(--gold); }

.field input,
.field-more input {
  width: 100%;
  padding: 11px 10px;
  border: 4px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
}

.field-more {
  margin-bottom: 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 900;
}

.field-more summary { color: var(--gold); cursor: pointer; padding: 4px 0; }
.field-more input { margin-top: 6px; font-size: 13px; }
.field-help { margin: 6px 0 0; font-size: 10px; font-weight: 800; line-height: 1.6; color: #cfd8e8; }
.field-help code { background: rgba(0, 0, 0, .3); padding: 1px 4px; }

.net-status {
  margin: 10px 0 0;
  min-height: 1.4em;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.5;
  color: #cfd8e8;
}

.net-status.is-ok   { color: #9ae6a0; }
.net-status.is-warn { color: #ffbf6b; }

/* 合言葉の部屋 */
.lobby-head {
  margin-bottom: 10px;
  padding: 6px;
  background: var(--gold);
  border: 3px solid var(--line);
  color: var(--line);
  font-size: 15px;
  font-weight: 900;
}

.lobby-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }

.lobby-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 3px solid var(--line);
  background: var(--head);
  font-size: 14px;
  font-weight: 900;
  text-align: left;
}

.lobby-list li.is-empty { background: rgba(255, 255, 255, .12); color: #b8c4d8; }
.lobby-list li.is-you   { background: var(--gold); color: var(--line); }
.lobby-no   { text-align: center; opacity: .7; }
.lobby-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-you  { font-size: 10px; padding: 2px 5px; background: var(--line); color: var(--gold); }
.lobby-note { margin: 0 0 8px; font-size: 11px; font-weight: 800; color: #cfd8e8; }

/* 結果発表 */
.winner { font-size: 20px; font-weight: 900; margin-bottom: 10px; color: var(--gold); }
.winner small { display: block; font-size: 12px; font-weight: 800; color: #fff; }

.podium {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: end;
  gap: 4px;
  padding-top: 26px;   /* 1位のかんむりがはみ出す場所をあけておく */
  margin-bottom: 14px;
}

.podium-col { display: grid; justify-items: center; gap: 2px; min-width: 0; }

.podium-face {
  --player-color: #a8a294;
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--player-color);
  border: 3px solid var(--line);
  line-height: 0;
}

.crown { position: absolute; top: -22px; line-height: 0; }
.podium-name {
  font-size: 10px; font-weight: 900; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.podium-money { font-size: 11px; font-weight: 900; color: var(--gold); }

.podium-block {
  width: 100%;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 3px solid var(--line);
  border-bottom: none;
  color: var(--line);
  font-size: 18px;
  font-weight: 900;
}

.podium-block.h1 { height: 68px; background: var(--gold); }
.podium-block.h2 { height: 50px; }
.podium-block.h3 { height: 36px; }
.podium-block.h4 { height: 26px; }

.result-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; }

.result-row {
  --player-color: #a8a294;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--paper);
  border: 3px solid var(--line);
  border-left: 9px solid var(--player-color);
  color: var(--ink);
  font-weight: 900;
}

.result-rank { font-size: 14px; color: var(--ink-weak); }
.result-name { text-align: left; font-size: 13px; }
.result-name small { display: block; font-size: 10px; font-weight: 800; color: var(--ink-weak); }
.result-money { font-size: 13px; color: var(--plus); }

.btn-replay {
  width: 100%;
  min-height: 60px;
  border: 4px solid var(--line);
  background: var(--red);
  color: #fff;
  font-family: inherit;
  font-size: 19px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--red-d), 0 6px 0 4px var(--line);
}

/* ---------- 大きい画面での調整 ---------- */

@media (min-height: 780px) {
  .slot { min-height: 92px; }
  .slot-label { font-size: 17px; }
  .player-money { font-size: 16px; }
  .player-name { font-size: 11px; }
}

/* せまい画面では、プレイヤー欄の文字をさらに詰める */
@media (max-width: 360px) {
  .player-money { font-size: 13px; }
  .player-name  { font-size: 9px; }
  .turn-badge   { font-size: 11px; }
}
