/* ========== 全体 ========== */
* { box-sizing: border-box; }

:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --accent: #ff6b6b;
  --accent-dark: #d04848;
  --text: #2b2b2b;
  --muted: #888;
  --border: #e0ddd5;

  --path-bg: #fffbe7;
  --path-line: #cfa45e;

  --color-start: #ffd166;
  --color-normal: #cce8ff;
  --color-event: #fde2a8;
  --color-good: #b8e6b8;
  --color-bad: #ffb3b3;
  --color-stock: #d4c1f9;
  --color-profession: #ffc4dd;
  --color-marriage: #ffc4dd;
  --color-child: #ffe2b3;
  --color-payday: #c5e8d0;
  --color-insurance: #d0eaff;
  --color-money: #cce8ff;
  --color-goal: #ff6b6b;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ========== ヘッダー ========== */
.app-header {
  padding: 14px 24px;
  background: linear-gradient(135deg, #ff6b6b, #ffa15d);
  color: white;
}
.header-row {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.app-header h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.05em;
  font-family: "Yusei Magic", "Klee One", sans-serif;
}
.subtitle { margin: 4px 0 0; font-size: 12px; opacity: 0.9; }
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.speed-label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.95;
}
.speed-label select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.18);
  color: white;
  font-size: 13px;
  cursor: pointer;
}
.speed-label select option { color: var(--text); }
.ghost-btn {
  padding: 6px 12px;
  background: rgba(255,255,255,0.18);
  color: white;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.ghost-btn:hover { background: rgba(255,255,255,0.32); }

/* ========== レイアウト ========== */
.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

/* ====== スマホ: タッチターゲット最低サイズ確保 ====== */
@media (hover: none) and (pointer: coarse) {
  button {
    min-height: 36px;
  }
  .toggle-group button {
    min-width: 48px;
    padding: 8px 14px;
    font-size: 13px;
  }
  .char-btn {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }
  .course-card {
    min-height: 80px;
  }
  .modal-choices button {
    min-height: 44px;
  }
}

/* ====== スマホ最適化 ====== */
@media (max-width: 768px) {
  .app-header {
    padding: 10px 12px;
  }
  .header-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-header h1 { font-size: 18px; }
  .subtitle { font-size: 11px; }
  .header-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .layout {
    padding: 8px;
    gap: 8px;
  }
  .board-area {
    padding: 12px 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* スマホでは盤面に最小幅を確保してスクロール表示 */
  .board {
    min-width: 800px;
  }
  .board-area::before {
    content: "← スワイプで盤面を移動 →";
    display: block;
    text-align: center;
    font-size: 10px;
    color: var(--muted);
    margin-bottom: 4px;
  }

  .side-panel > div {
    padding: 10px;
  }
  .side-panel h2 { font-size: 12px; }
  .current-player { font-size: 16px; }
  .spin-btn { padding: 10px; font-size: 14px; }
  .roulette-wrap { width: 180px; height: 180px; }
  .dice-result-overlay {
    width: 48px;
    height: 48px;
    font-size: 22px;
  }
  .market-btn { font-size: 12px; padding: 8px; }

  .player-row {
    font-size: 12px;
    padding: 6px;
    grid-template-columns: auto 1fr auto;
  }
  .player-row .pjob { font-size: 10px; }
  .player-row .pname { font-size: 13px; }
  .player-row .spark { max-width: 80px; height: 18px; }

  .log {
    max-height: 180px;
    font-size: 11px;
  }

  /* モーダル */
  .modal-content {
    width: 94vw;
    max-height: 90vh;
    overflow-y: auto;
    padding: 16px;
  }
  .setup-modal {
    max-width: 94vw;
  }
  .course-picker {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .course-card .course-emoji { font-size: 26px; }
  .course-card .course-desc { font-size: 10px; }
  .setup-row-top {
    grid-template-columns: auto 1fr auto;
    gap: 6px;
  }
  .setup-row input[type="text"] { font-size: 12px; }
  .char-btn { width: 28px; height: 28px; font-size: 15px; }

  /* 市場モーダル */
  .market-content {
    width: 96vw;
    padding: 12px;
  }
  .market-header h3 { font-size: 16px; }
  .market-tip { font-size: 10px; padding: 5px 8px; }
  .market-summary {
    grid-template-columns: 1fr;
    font-size: 11px;
    padding: 6px 10px;
  }
  .market-summary .ms-item.total {
    grid-column: 1 / 2;
  }
  .market-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .market-tab {
    flex: 0 0 auto;
    font-size: 12px;
    padding: 6px 10px;
  }
  .market-stock {
    grid-template-columns: 1fr;
  }
  .stock-price { text-align: left; grid-column: 1 / 2; }
  .stock-actions { flex-direction: column; align-items: stretch; }
  .market-action-btn { width: 100%; padding: 8px; }
  .stock-owned { margin-left: 0; margin-top: 4px; text-align: right; }

  .bank-buttons {
    flex-direction: column;
  }
  .bank-buttons button {
    width: 100%;
  }
  .house-plans {
    grid-template-columns: 1fr;
  }
  .mortgage-builder {
    flex-direction: column;
    align-items: stretch;
  }
  .mortgage-builder label,
  .mortgage-builder select {
    width: 100%;
  }

  /* ライフカード */
  .life-card {
    width: 84vw;
  }
  .life-card .card-emoji { font-size: 60px; }
  .life-card .card-title { font-size: 20px; }
  .life-card .card-desc { font-size: 12px; }

  /* 為替 */
  .fx-rate-box .fx-value { font-size: 28px; }
}

/* iPhone 等の超小型 (~420px) 向け補正 */
@media (max-width: 420px) {
  .board { min-width: 720px; }
  .roulette-wrap { width: 150px; height: 150px; }
  .dice-result-overlay { width: 40px; height: 40px; font-size: 18px; }
  .player-row .spark { max-width: 60px; }
  .header-actions { font-size: 11px; }
}

/* ========== 盤面 (SVG曲線パス上にマス配置) ========== */
.board-area {
  background: #fdf6e3;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  background-image:
    radial-gradient(circle at 15% 25%, rgba(255,200,150,0.22), transparent 35%),
    radial-gradient(circle at 85% 80%, rgba(180,220,255,0.22), transparent 40%),
    radial-gradient(circle, rgba(207,164,94,0.07) 1px, transparent 1px);
  background-size: cover, cover, 18px 18px;
  container-type: inline-size;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 580;
  margin: 0 auto;
}
.board-path-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.08));
}

.cell {
  position: absolute;
  width: 9.2%;
  aspect-ratio: 1 / 1;
  padding: 4px;
  background: var(--color-normal);
  border: 2px solid rgba(0,0,0,0.12);
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.1),
    0 3px 5px rgba(0,0,0,0.18),
    0 8px 14px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  text-align: center;
  font-family: "Klee One", "Hiragino Sans", "Noto Sans JP", sans-serif;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  z-index: 2;
}
.cell:hover {
  transform: var(--cell-base-transform, none) scale(1.18) rotate(0deg) !important;
  z-index: 6;
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.1),
    0 8px 16px rgba(0,0,0,0.28),
    0 16px 28px rgba(0,0,0,0.12);
}

.cell .cell-num {
  position: absolute;
  top: -10%;
  left: -10%;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: white;
  border: 2px solid rgba(0,0,0,0.2);
  font-size: clamp(8px, 1.15cqi, 13px);
  color: var(--text);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  font-family: "Yusei Magic", "Klee One", sans-serif;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.cell .cell-label {
  font-weight: 600;
  font-size: clamp(8px, 1.3cqi, 14px);
  margin-top: 22%;
  line-height: 1.15;
  font-family: "Klee One", "Hiragino Sans", sans-serif;
}

.cell .cell-detail {
  font-size: clamp(7px, 1.0cqi, 12px);
  color: rgba(0,0,0,0.7);
  font-family: "Klee One", "Hiragino Sans", sans-serif;
  line-height: 1.2;
}

.cell.type-start { background: var(--color-start); }
.cell.type-event { background: var(--color-event); }
.cell.type-card {
  background: linear-gradient(135deg, #ffe066, #ffc44d);
}
.cell.type-card .cell-detail {
  font-size: 18px;
  font-weight: 900;
  color: rgba(0,0,0,0.7);
}

/* 教育系マス */
.cell.type-school {
  background: linear-gradient(135deg, #b3d4fc, #80b3ff);
}
.cell.type-lesson {
  background: linear-gradient(135deg, #f9d5e5, #f5b0c6);
}
.cell.type-cram {
  background: linear-gradient(135deg, #d1c4e9, #b39ddb);
}
.cell.type-study {
  background: linear-gradient(135deg, #c8e6c9, #a5d6a7);
}
.cell.type-bonus {
  background: linear-gradient(135deg, #ffe082, #ffcc40);
}
/* 職業選択 (STOP マス) は赤く強調 */
.cell.type-profession {
  background: linear-gradient(135deg, #ff9a3c, #ff6b6b);
  color: white;
  outline: 3px solid #c84141;
  outline-offset: 2px;
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.2),
    0 0 14px rgba(255,107,107,0.7),
    0 3px 5px rgba(0,0,0,0.18);
  font-weight: 700;
}
.cell.type-profession .cell-detail,
.cell.type-profession .cell-label {
  color: white;
}
.cell.type-profession .cell-num { color: var(--accent-dark); }
.cell.type-money { background: var(--color-money); }
.cell.type-payday { background: var(--color-payday); }
.cell.type-stock { background: var(--color-stock); }
.cell.type-profession { background: var(--color-profession); }
.cell.type-marriage { background: var(--color-marriage); }
.cell.type-child { background: var(--color-child); }
.cell.type-insurance { background: var(--color-insurance); }
.cell.type-goal {
  background: linear-gradient(135deg, #ff6b6b, #ff9a3c);
  color: white;
  font-weight: 700;
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.2),
    0 0 14px rgba(255,107,107,0.6);
}
.cell.type-goal .cell-num { color: var(--accent); }
.cell.type-goal .cell-detail { color: rgba(255,255,255,0.9); }

/* マスをつなぐ矢印 */
.cell::after {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: 0.55;
}
.cell.arrow-right::after {
  right: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid var(--path-line);
}
.cell.arrow-left::after {
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 10px solid var(--path-line);
}
.cell.arrow-down::after {
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid var(--path-line);
}

/* プレイヤーコマ */
.tokens {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  z-index: 3;
}
.token {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 3px rgba(0,0,0,0.35);
  transition: transform 0.3s ease;
}
.cell.highlight {
  outline: 3px solid var(--accent);
  outline-offset: -2px;
  animation: pulse 0.4s ease;
  z-index: 4;
}

@keyframes pulse {
  0% { transform: scale(0.95); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ========== サイドパネル ========== */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-panel > div {
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.side-panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.current-player {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.current-player .pdot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.spin-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.spin-btn:hover:not(:disabled) { background: var(--accent-dark); }
.spin-btn:disabled { background: #ccc; cursor: not-allowed; }

/* ===== ルーレット ===== */
.roulette-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 6px auto 14px;
}
.roulette-wheel {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.18));
  transform-origin: 50% 50%;
  transition: filter 0.2s;
}
.roulette-wheel.glow {
  filter:
    drop-shadow(0 0 12px rgba(255,160,90,0.7))
    drop-shadow(0 4px 8px rgba(0,0,0,0.18));
}
.roulette-pointer {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 22px solid #d23a3a;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
  z-index: 4;
}
.dice-result-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: white;
  border: 4px solid #333;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  color: var(--text);
  z-index: 3;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  pointer-events: none;
}
/* 回転中は中央バッジを縮めて中央軸を見せる */
.dice-result-overlay.spinning {
  width: 0; height: 0;
  border-width: 0;
  background: transparent;
}
.dice-result-overlay.flash {
  animation: dice-flash 0.5s ease;
}
@keyframes dice-flash {
  0% { transform: translate(-50%,-50%) scale(1); background: white; }
  40% { transform: translate(-50%,-50%) scale(1.4); background: #ffd166; }
  100% { transform: translate(-50%,-50%) scale(1); background: white; }
}

.sector-label {
  fill: #2b2b2b;
  font-size: 22px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: white;
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* ===== コマ (absolute, 絵文字) ===== */
.tokens-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.token-piece {
  position: absolute;
  width: clamp(28px, 4cqi, 44px);
  height: clamp(28px, 4cqi, 44px);
  border-radius: 50%;
  background: white;
  border: 3px solid var(--player-color, #888);
  box-shadow: 0 3px 6px rgba(0,0,0,0.35);
  transform: translate(-50%, -50%);
  transition: box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.token-piece .token-emoji {
  font-size: clamp(16px, 2.5cqi, 26px);
  line-height: 1;
  user-select: none;
}
.token-piece.is-current {
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--player-color) 50%, transparent),
    0 3px 6px rgba(0,0,0,0.35);
  animation: token-pulse 1.4s ease-in-out infinite;
}
@keyframes token-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -50%) scale(1.10); }
}
.token-piece .token-name {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255,255,255,0.9);
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ===== 吹き出し ===== */
.speech-bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, 0);
  background: white;
  border: 2px solid #333;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
  font-family: "Klee One", sans-serif;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  z-index: 30;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid white;
  filter: drop-shadow(0 2px 0 currentColor);
}

/* ===== ライフカード演出 ===== */
.card-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 300;
  perspective: 1400px;
  cursor: pointer;
}
.card-modal.hidden {
  display: none;
}
.life-card {
  position: relative;
  width: min(320px, 80vw);
  aspect-ratio: 5 / 7;
  border-radius: 20px;
  background: linear-gradient(160deg, #fffaf0 0%, #ffeed1 100%);
  border: 6px solid #ffd166;
  box-shadow:
    0 20px 50px rgba(0,0,0,0.5),
    inset 0 -6px 0 rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  gap: 14px;
  text-align: center;
  font-family: "Klee One", "Hiragino Sans", sans-serif;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}
.life-card.mood-happy {
  background: linear-gradient(160deg, #fff5e8 0%, #ffd9b3 100%);
  border-color: #ff9a3c;
}
.life-card.mood-sad {
  background: linear-gradient(160deg, #f0f4ff 0%, #c9d6f7 100%);
  border-color: #6b88c4;
}
.life-card.mood-neutral {
  background: linear-gradient(160deg, #fefefe 0%, #e6e6e6 100%);
  border-color: #999;
}
.life-card .card-emoji {
  font-size: 80px;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2));
}
.life-card .card-title {
  font-size: 26px;
  font-weight: 700;
  color: #2b2b2b;
  font-family: "Yusei Magic", "Klee One", sans-serif;
}
.life-card .card-desc {
  font-size: 14px;
  color: #555;
  line-height: 1.5;
}
.life-card .card-amount {
  font-size: 22px;
  font-weight: 800;
  margin-top: 6px;
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,0.6);
}
.life-card .card-amount.positive { color: #2a9d4f; }
.life-card .card-amount.negative { color: #c84141; }
.life-card .card-hint {
  position: absolute;
  bottom: 12px;
  left: 0; right: 0;
  font-size: 10px;
  color: rgba(0,0,0,0.4);
}

/* ===== 金融市場モーダル ===== */
.market-btn {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  background: linear-gradient(135deg, #2c5f87, #4a87b3);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
}
.market-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #1f4d70, #366a93);
}
.market-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.market-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  z-index: 250;
}
.market-modal.hidden { display: none; }
.market-content {
  background: white;
  width: min(640px, 92vw);
  max-height: 90vh;
  border-radius: 14px;
  padding: 18px 22px;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.market-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.market-header h3 {
  margin: 0;
  font-size: 20px;
  font-family: "Yusei Magic", sans-serif;
}
.ghost-btn.dark {
  background: rgba(0,0,0,0.08);
  color: var(--text);
  border-color: rgba(0,0,0,0.15);
}
.market-tip {
  margin: 0 0 14px;
  font-size: 11px;
  color: var(--muted);
  background: #f7f7f7;
  padding: 6px 10px;
  border-radius: 6px;
  border-left: 3px solid #4a87b3;
  line-height: 1.5;
}

.market-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 12px;
  background: #f0f4fa;
  border: 1px solid #d0dde8;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 12px;
}
.ms-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ms-item span { color: var(--muted); }
.ms-item b { font-family: monospace; font-weight: 700; }
.ms-item.negative b { color: #c84141; }
.ms-item.total {
  grid-column: 1 / 3;
  border-top: 1px solid #c0cdd8;
  padding-top: 4px;
  margin-top: 2px;
}
.ms-item.total b { color: var(--accent-dark); font-size: 14px; }
.ms-item .up { color: #2a9d4f; }
.ms-item .down { color: #c84141; }
.ms-item .flat { color: var(--muted); }

.market-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 12px;
}
.market-tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.market-tab:hover { color: var(--text); background: #fafafa; }
.market-tab.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}
.market-pane {
  display: none;
}
.market-pane.active {
  display: block;
}

.bank-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fafafa;
  margin-bottom: 10px;
}
.bank-card.highlight {
  border-color: #4a87b3;
  background: #f0f6fc;
}
.bank-card.warning {
  border-color: #d29c50;
  background: #fdf6ec;
}
.bank-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}
.bank-title small {
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
}
.bank-hint {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.4;
}

.house-options {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.house-options-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}
.house-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px dotted #eee;
}
.house-option:last-child { border-bottom: none; }
.house-option strong { display: block; font-weight: 700; }
.house-option small {
  display: block;
  color: var(--muted);
  font-size: 10px;
}
.house-opt-btn {
  padding: 5px 10px;
  font-size: 11px;
  border: 1.5px solid var(--accent);
  background: white;
  color: var(--accent-dark);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
.house-opt-btn:hover:not(:disabled) {
  background: var(--accent);
  color: white;
}
.house-opt-btn.active {
  background: #2a9d4f;
  color: white;
  border-color: #2a9d4f;
}
.house-opt-btn:disabled {
  border-color: #ccc;
  color: #999;
  background: #f5f5f5;
  cursor: not-allowed;
}
.house-opt-on {
  font-size: 11px;
  font-weight: 700;
  color: #2a9d4f;
  padding: 5px 10px;
  background: #e8f5e9;
  border-radius: 6px;
}

.house-plans {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.house-buy-btn {
  padding: 10px 8px;
  border: 2px solid var(--accent);
  background: white;
  color: var(--accent-dark);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.3;
  text-align: center;
}
.house-buy-btn:hover:not(:disabled) {
  background: var(--accent);
  color: white;
}
.house-buy-btn:disabled {
  border-color: #ccc;
  color: #999;
  background: #f5f5f5;
  cursor: not-allowed;
}
.house-buy-btn.full {
  border-color: #ffd166;
  color: #b58806;
  background: #fff9e6;
}
.house-buy-btn.full:hover {
  background: #ffd166;
  color: #2b2b2b;
}
.house-buy-btn small {
  font-weight: 500;
  font-size: 10px;
  color: var(--muted);
}

.mortgage-builder {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.mortgage-builder label {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.mortgage-builder select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
}
.mortgage-builder #mortgage-take {
  padding: 8px 14px;
  margin-left: auto;
}

.fx-rate-box {
  text-align: center;
  padding: 20px 0;
  background: linear-gradient(135deg, #2c5f87, #4a87b3);
  color: white;
  border-radius: 10px;
  margin-bottom: 12px;
}
.fx-rate-box .fx-label {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 4px;
}
.fx-rate-box .fx-value {
  font-size: 36px;
  font-weight: 900;
  font-family: monospace;
}
.fx-rate-box .fx-trend {
  font-size: 13px;
  font-weight: 700;
  margin-top: 4px;
}
.fx-rate-box .fx-trend.up { color: #ffd166; }
.fx-rate-box .fx-trend.down { color: #ff9aa9; }
.fx-explain {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 12px;
  padding: 8px 12px;
  background: #f7f7f7;
  border-radius: 6px;
}
.fx-history {
  margin-top: 10px;
}
.fx-history-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.fx-history-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 60px;
  background: #f7f7f7;
  border-radius: 6px;
  padding: 4px;
}
.fx-bar {
  flex: 1;
  background: linear-gradient(180deg, #4a87b3, #2c5f87);
  border-radius: 2px 2px 0 0;
  min-height: 4px;
}
.market-section {
  margin-bottom: 14px;
}
.market-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.05em;
}
.market-stock {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fafafa;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
}
.stock-head {
  grid-column: 1 / 2;
}
.stock-name {
  font-weight: 700;
  font-size: 15px;
}
.stock-desc {
  font-size: 10px;
  color: var(--muted);
}
.stock-price {
  text-align: right;
  grid-column: 2 / 3;
}
.price-val {
  font-weight: 800;
  font-size: 18px;
  font-family: monospace;
}
.price-trend {
  font-size: 11px;
  font-weight: 700;
  font-family: monospace;
}
.price-trend.up { color: #2a9d4f; }
.price-trend.down { color: #c84141; }
.price-trend.flat { color: var(--muted); }
.stock-actions {
  grid-column: 1 / 3;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 4px;
}
.market-action-btn {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid;
  border-radius: 6px;
  cursor: pointer;
}
.market-action-btn.buy {
  background: #2a9d4f;
  color: white;
  border-color: #2a9d4f;
}
.market-action-btn.sell {
  background: white;
  color: #c84141;
  border-color: #c84141;
}
.market-action-btn:disabled {
  background: #eee;
  color: #999;
  border-color: #ddd;
  cursor: not-allowed;
}
.stock-owned {
  font-size: 11px;
  margin-left: auto;
  color: var(--muted);
}
.stock-owned b { color: var(--text); font-size: 13px; }

.market-bank {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fafafa;
}
.bank-balance {
  font-size: 13px;
  margin-bottom: 8px;
}
.bank-balance strong {
  font-family: monospace;
  font-size: 16px;
}
.bank-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.bank-buttons button {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--accent);
  background: white;
  color: var(--accent);
  border-radius: 6px;
  cursor: pointer;
}
.bank-buttons button:hover { background: var(--accent); color: white; }
.market-flash {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 8px 16px;
  border-radius: 8px;
  background: #333;
  color: white;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 400;
}
.market-flash.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.market-flash.error { background: #c84141; }

.player-row .ptotal {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}

/* ===== 紙吹雪 ===== */
.confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  overflow: hidden;
}
.confetti {
  position: absolute;
  border-radius: 2px;
  will-change: transform;
}

/* ===== プレイヤーアバター (パネル用) ===== */
.player-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--player-color, #888);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.player-avatar.small {
  width: 28px;
  height: 28px;
  font-size: 16px;
  border-width: 2px;
}

/* 旧 dice 表示は使用しないが念のためフォールバック */
.dice-result {
  margin-top: 10px;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  min-height: 32px;
}

#player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  background: #fafafa;
  border-left: 4px solid;
  font-size: 13px;
  position: relative;
  transition: background 0.2s, box-shadow 0.2s;
}
.player-row.active {
  background: #fff5e6;
}
.player-row.leader {
  background: linear-gradient(90deg, #fffbe6, #fafafa);
  box-shadow: inset 0 0 0 1px #ffd166;
}
.player-row .pinfo {
  min-width: 0;
}
.player-row .pname {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-row .rank-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0,0,0,0.08);
  color: var(--muted);
}
.player-row .rank-badge.leader {
  background: transparent;
  font-size: 14px;
  padding: 0;
}
.player-row .pjob { color: var(--muted); font-size: 11px; }
.player-row .pmoney {
  font-weight: 700;
  font-family: monospace;
  text-align: right;
}
.player-row .pmeta {
  font-size: 10px;
  color: var(--muted);
}
.player-row .pdot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.player-row .ptrend {
  display: block;
  font-size: 10px;
  font-weight: 700;
}
.player-row .ptrend.up { color: #2a9d4f; }
.player-row .ptrend.down { color: #c84141; }
.player-row .ptrend.flat { color: var(--muted); }
.player-row .pchart {
  margin-top: 2px;
}
.player-row .spark {
  width: 100%;
  max-width: 140px;
  height: 22px;
  display: block;
}

.log {
  max-height: 240px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
}
.log-entry {
  padding: 4px 0;
  border-bottom: 1px dashed #eee;
}
.log-entry.event { color: var(--accent-dark); font-weight: 600; }
.log-entry.money-up { color: #2a9d4f; }
.log-entry.money-down { color: #c84141; }

/* ========== モーダル ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: white;
  padding: 24px;
  border-radius: 12px;
  max-width: 420px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}
.modal-content h3 { margin: 0 0 12px; }
.modal-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.modal-choices button {
  padding: 12px;
  font-size: 14px;
  border: 2px solid var(--accent);
  background: white;
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.modal-choices button:hover {
  background: var(--accent);
  color: white;
}

.result-list {
  text-align: left;
  font-size: 14px;
  line-height: 1.8;
}
.result-list .winner { font-weight: 700; color: var(--accent); }

/* ========== ゲーム未開始時の CTA ========== */
.board-area { position: relative; }
.start-cta {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(253,246,227,0.96);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: 16px;
  z-index: 50;
  padding: 20px;
}
.start-cta.hidden { display: none; }
.start-cta-inner {
  text-align: center;
  max-width: 420px;
}
.start-cta-emoji {
  font-size: 64px;
  margin-bottom: 12px;
  animation: gentle-bounce 1.4s ease-in-out infinite;
}
@keyframes gentle-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.start-cta-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  font-family: "Yusei Magic", "Klee One", sans-serif;
  margin-bottom: 6px;
}
.start-cta-sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
}
.start-cta-btn {
  padding: 16px 32px;
  font-size: 18px;
  font-weight: 700;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(255,107,107,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.start-cta-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255,107,107,0.5);
}
.start-cta-btn:active { transform: translateY(0); }
.start-cta-hint {
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
}

/* ヘッダーの「プレイヤー設定」ボタンを少し目立たせる */
#setup-btn {
  background: rgba(255,255,255,0.3);
  font-weight: 700;
}

/* ========== モーダル閉じるボタン (×) ========== */
.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.06);
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  z-index: 10;
}
.modal-close-btn:hover {
  background: rgba(0,0,0,0.15);
  color: var(--text);
}
/* setup-modal は position:relative を確保 */
.setup-modal { position: relative; }

/* ========== コース選択 ========== */
.setup-section {
  margin-bottom: 16px;
}
.setup-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 8px;
  letter-spacing: 0.05em;
}
.course-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
}
.loading-fallback {
  grid-column: 1 / -1;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.course-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  background: white;
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
  font-family: "Klee One", "Hiragino Sans", sans-serif;
}
.course-card:hover { background: #fafafa; }
.course-card.selected {
  border-color: var(--accent);
  background: #fff5e6;
  transform: scale(1.03);
  box-shadow: 0 2px 6px rgba(255,107,107,0.2);
}
.course-card .course-emoji {
  font-size: 32px;
  line-height: 1;
  margin-bottom: 6px;
}
.course-card .course-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.course-card .course-desc {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}
.course-card .course-meta {
  font-size: 9px;
  color: var(--muted);
  margin-top: 6px;
}

/* ========== プレイヤー設定モーダル ========== */
.setup-modal {
  max-width: 560px;
  text-align: left;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0; /* 内部で padding を分割するので外は0 */
  overflow: hidden;
}
.setup-modal .setup-header {
  padding: 22px 24px 12px;
  flex-shrink: 0;
}
.setup-modal h3 { margin: 0 0 8px; }
.setup-modal .setup-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 24px 16px;
  min-height: 0; /* flex内で overflow を効かせる */
}
.setup-modal .setup-footer {
  flex-shrink: 0;
  padding: 14px 24px 18px;
  background: white;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.04);
}
.setup-modal .setup-footer .spin-btn {
  font-size: 16px;
  padding: 14px;
}
.setup-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 16px;
  text-align: center;
}
.setup-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}
.setup-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: #fafafa;
  border-radius: 8px;
  border-left: 5px solid;
}
.setup-row-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}
.token-preview {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--player-color, #888);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.char-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.char-btn {
  width: 32px;
  height: 32px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
  padding: 0;
}
.char-btn:hover { background: #f0f0f0; }
.char-btn.selected {
  border-color: var(--accent);
  background: #fff5e6;
  transform: scale(1.18);
}
.setup-row input[type="text"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
}
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.toggle-group button {
  padding: 6px 12px;
  font-size: 12px;
  border: none;
  background: white;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.toggle-group button.on {
  background: var(--accent);
  color: white;
}
