/* ===== Caratos スタイル (レスポンシブ両対応) ===== */
:root {
  /* ===== デフォルト: フルーツ (明るいポップ) ===== */
  --bg: #ffe6bf; --bg2: #f6d491; --bg-glow: #fff6dd;
  --panel: #ffffff; --panel2: #fff2d8;
  --gold: #f2a52a; --gold-dim: #cf7d16;
  --ink: #4a3320; --ink-dim: #a2865f;
  --line: rgba(90, 60, 25, 0.16);
  --shadow: 0 4px 14px rgba(150, 100, 40, 0.18);
  --input-bg: #fff8ec;

  /* iOSセーフエリア (ノッチ/ホームインジケータ/角丸)。実機のみ非0。 */
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);

  /* 5色 (紫青緑赤黒) + 金。両テーマ共通の鮮やかな色。内部キー w=紫 */
  --gem-w: #a55cf0; --gem-w2: #7b39c7;   /* 紫: ぶどう */
  --gem-u: #2e86e0; --gem-u2: #175aa8;   /* 青: ブルーベリー */
  --gem-g: #3fbf5f; --gem-g2: #229a41;   /* 緑: 青りんご */
  --gem-r: #f0455a; --gem-r2: #c02236;   /* 赤: いちご */
  --gem-k: #3c4855; --gem-k2: #1c242d;   /* 黒: さくらんぼ(濃) */
  --gem-gold: #f7c948; --gem-gold2: #d99a1e; /* 金: パイナップル */
}
/* ===== 宝石テーマ (ダーク・重厚) ===== */
[data-theme="gems"] {
  --bg: #0e2a4a; --bg2: #0a1f38; --bg-glow: #1a4272;
  --panel: #143a60; --panel2: #0d2844;
  --gold: #f2c14e; --gold-dim: #b8912f;
  --ink: #eaf2ff; --ink-dim: #9db4d0;
  --line: rgba(255, 255, 255, 0.14);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  --input-bg: #0a1c33;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background-color: var(--bg2); } /* 未描画領域が白くならないよう固定 */
html, body {
  margin: 0; min-height: 100%;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-glow), var(--bg) 55%, var(--bg2));
  background-color: var(--bg2); /* グラデ下の単色ベース (白余白の保険) */
  overscroll-behavior: none; /* iOSのラバーバンドで白が見えるのを防ぐ */
}
h1, h2, h3 { margin: 0 0 .4em; }
button { font-family: inherit; }
.screen { min-height: 100%; }
.hidden { display: none !important; }

/* ---- ボタン ---- */
.btn {
  display: block; width: 100%; padding: 12px 16px; margin: 8px 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ink); font-size: 15px; font-weight: 700;
  cursor: pointer; transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold-dim)); color: #2a1c00; border-color: var(--gold); }
.btn.ghost { background: transparent; color: var(--ink-dim); border-color: var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
/* ボタンとして使う <a> (例: 応援ページの寄付ボタン) */
a.btn { text-decoration: none; text-align: center; box-sizing: border-box; }
a.btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
/* フッターの応援リンクだけ少し目立たせる (コーヒー色) */
.support-link { color: var(--gold) !important; font-weight: 700; }
/* ボタンでなく控えめなテキストリンク (例: チュートリアル再挑戦) */
.link-btn { display: block; width: 100%; background: none; border: none; padding: 6px 0 0; margin: 0;
  color: var(--gold); font-size: 13px; font-weight: 700; text-decoration: underline; cursor: pointer; }
.link-btn:hover { filter: brightness(1.15); }

/* ---- ホーム / ロビー ---- */
#home, #lobby, #solo { display: flex; align-items: center; justify-content: center; min-height: 100dvh; overflow-y: auto;
  padding: calc(16px + var(--sat)) calc(20px + var(--sar)) calc(44px + var(--sab)) calc(20px + var(--sal)); }
/* 言語切替ボタン (ホーム右上) */
.lang-btn { position: absolute; top: calc(10px + var(--sat)); right: calc(12px + var(--sar)); z-index: 3;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
.lang-btn:hover { filter: brightness(1.15); }
.home-card {
  width: 100%; max-width: 420px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 20px; padding: 26px; box-shadow: var(--shadow);
}
.logo { font-size: 34px; text-align: center; letter-spacing: 1px; }
.tagline { text-align: center; color: var(--ink-dim); margin-top: -4px; font-size: 13px; }
.home-desc { text-align: center; color: var(--ink); font-size: 13px; line-height: 1.7; margin: 14px 4px 4px; opacity: .9; }

/* フッターのリンク (遊び方/更新履歴/プライバシー/About) */
.home-footer { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; margin: 16px auto 0; max-width: 420px; }
.home-footer a { color: var(--ink-dim); font-size: 12px; cursor: pointer; text-decoration: none; }
.home-footer a:hover { color: var(--gold); text-decoration: underline; }
/* ホームだけは画面下部の小さな横並びバーに (縦長を防ぐ) */
#home { position: relative; }
#home .home-footer { position: absolute; left: 0; right: 0; bottom: calc(8px + var(--sab)); margin: 0; max-width: none;
  gap: 2px 14px; font-size: 11px; padding: 0 12px; }

/* 情報ページ */
#info { display: block; min-height: 100dvh; padding: calc(0px + var(--sat)) var(--sar) var(--sab) var(--sal); }
.info-page { max-width: 680px; margin: 0 auto; padding: 16px 18px 28px; }
.info-head { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; background: var(--bg2); padding: 10px 0; z-index: 2; }
.info-head h2 { margin: 0; font-size: 20px; }
.info-content { line-height: 1.8; color: var(--ink); font-size: 15px; }
.info-content h3 { font-size: 16px; margin: 22px 0 6px; color: var(--gold); }
.info-content p { margin: 8px 0; }
.info-content ul { margin: 8px 0; padding-left: 20px; }
.info-content li { margin: 5px 0; }
.info-content .muted { color: var(--ink-dim); font-size: 13px; }
.info-content code { background: #0a1c33; padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.info-content .cl-ver { color: var(--gold); font-weight: 800; }
.info-content .cl-date { color: var(--ink-dim); font-size: 12px; margin-left: 6px; }
.info-content .rb-ex { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--gold);
  border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 14px; }
.info-content .rb-ex b { color: var(--gold); }
.info-footer { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 16px; }

/* 手番(先手/後手/ランダム)セレクタ */
.order-select { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; }
.order-select .order-label { font-size: 13px; color: var(--ink-dim); flex: 0 0 auto; }
.order-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.order-opt { padding: 7px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer; transition: filter .15s, border-color .15s; }
.order-opt:hover { filter: brightness(1.12); }
.order-opt.sel { background: linear-gradient(180deg, var(--gold), var(--gold-dim)); color: #2a1c00; border-color: var(--gold); }

/* CPU レベル選択 */
.level-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.level-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); cursor: pointer; transition: filter .15s, transform .08s; }
.level-item:hover { filter: brightness(1.12); }
.level-item:active { transform: scale(.99); }
.level-item.locked { opacity: .55; cursor: not-allowed; filter: none; }
.level-item.cleared { border-color: var(--gold); }
.level-num { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 9px; background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  color: #2a1c00; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.level-item.locked .level-num { background: #33445c; color: var(--ink-dim); }
.level-info { flex: 1; min-width: 0; }
.level-name { font-weight: 700; font-size: 15px; }
.level-desc { color: var(--ink-dim); font-size: 12px; }
.level-badge { font-size: 13px; color: var(--ink-dim); }
.level-item.cleared .level-badge { color: var(--gold); }
.unlock-msg { color: var(--gold); font-weight: 800; font-size: 15px; margin: 6px 0 2px; }

/* テーマ切替 */
.theme-switch { display: flex; align-items: center; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.theme-switch .lbl { font-size: 13px; color: var(--ink-dim); }
.theme-switch button { flex: 1; min-width: 110px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer; }
.theme-switch button.active { border-color: var(--gold); background: linear-gradient(180deg, var(--gold), var(--gold-dim)); color: #3a2400; }

.drawer-links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 12px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.drawer-links a { color: var(--ink-dim); font-size: 13px; cursor: pointer; }
.drawer-links a:hover { color: var(--gold); }
.field { display: block; margin: 14px 0 6px; }
.field span { display: block; font-size: 13px; color: var(--ink-dim); margin-bottom: 6px; }
.field input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--input-bg); color: var(--ink); font-size: 16px; }
.or { text-align: center; color: var(--ink-dim); margin: 16px 0 6px; font-size: 13px; }
.error-text { color: #ff8a8a; font-size: 13px; min-height: 18px; text-align: center; }
.hint { color: var(--ink-dim); font-size: 13px; text-align: center; }
.room-code-box { text-align: center; background: var(--input-bg); border-radius: 14px; padding: 14px; margin: 10px 0; }
.room-code-box .label { display: block; font-size: 12px; color: var(--ink-dim); }
.room-code-box .code { font-size: 40px; font-weight: 800; letter-spacing: 8px; color: var(--gold); }
.player-list { list-style: none; padding: 0; margin: 6px 0 14px; }
.player-list li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin: 6px 0; background: var(--panel); border-radius: 10px; border: 1px solid var(--line); }
.player-list .dot { width: 10px; height: 10px; border-radius: 50%; background: #4caf50; }
.player-list .dot.off { background: #666; }
.player-list .host-badge { margin-left: auto; font-size: 11px; color: var(--gold); }

/* ========== 宝石 (共通) ========== */
.gem {
  border-radius: 50%; position: relative;
  border: 1px solid rgba(0,0,0,.35); box-shadow: inset 0 2px 4px rgba(255,255,255,.35), inset 0 -3px 5px rgba(0,0,0,.3);
}
.gem::after { content: ""; position: absolute; left: 22%; top: 16%; width: 30%; height: 22%; border-radius: 50%; background: rgba(255,255,255,.55); filter: blur(1px); }
.g-w { background: radial-gradient(circle at 35% 30%, var(--gem-w), var(--gem-w2)); }
.g-u { background: radial-gradient(circle at 35% 30%, var(--gem-u), var(--gem-u2)); }
.g-g { background: radial-gradient(circle at 35% 30%, var(--gem-g), var(--gem-g2)); }
.g-r { background: radial-gradient(circle at 35% 30%, var(--gem-r), var(--gem-r2)); }
.g-k { background: radial-gradient(circle at 35% 30%, var(--gem-k), var(--gem-k2)); }
.g-gold { background: radial-gradient(circle at 35% 30%, var(--gem-gold), var(--gem-gold2)); }
/* カード地色タイント (色即判別・中央の球体を廃したぶん色を強めに) */
.tint-w { background: linear-gradient(165deg, #eadcfa, #cbaaf0); }
.tint-u { background: linear-gradient(165deg, #dcebfb, #a9ccf3); }
.tint-g { background: linear-gradient(165deg, #dbf2e2, #a8e0bd); }
.tint-r { background: linear-gradient(165deg, #fbdede, #f2b5b5); }
.tint-k { background: linear-gradient(165deg, #dbe2ea, #b6c2ce); }

/* ========== ゲーム画面 ========== */
#game { display: flex; flex-direction: column; min-height: 100dvh; }
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  /* ノッチ/時計を避けて上・左右にセーフエリアぶん余白 */
  padding: calc(8px + var(--sat)) calc(12px + var(--sar)) 8px calc(12px + var(--sal));
  background: var(--panel2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { font-size: 17px; font-weight: 800; letter-spacing: .5px; }
.turn-banner { font-weight: 700; font-size: 14px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-banner.mine { color: var(--gold); }
.room-tag { color: var(--ink-dim); font-size: 13px; margin-right: 8px; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; width: 38px; height: 34px; font-size: 18px; cursor: pointer; }

/* ---- 盤面グリッド ---- */
#board {
  flex: 1; display: grid; gap: 12px;
  padding: 12px calc(12px + var(--sar)) 12px calc(12px + var(--sal));
  grid-template-columns: 210px minmax(0, 1fr) auto auto;
  grid-template-areas: "players tiers tokens nobles";
  align-items: start; max-width: 1300px; margin: 0 auto; width: 100%;
}
.players-region { grid-area: players; display: flex; flex-direction: column; gap: 8px; }
.tiers-region  { grid-area: tiers; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tokens-region { grid-area: tokens; display: flex; flex-direction: column; gap: 8px; }
.nobles-region { grid-area: nobles; display: flex; flex-direction: column; gap: 8px; }

/* ---- プレイヤーパネル (参考画像式: 色ごとにカード/宝石の数) ---- */
.ppanel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.ppanel.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(242,193,78,.35); }
.ppanel.self { background: rgba(242,165,42,.14); border-color: var(--gold); }
.ppanel-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.ppanel-head .pdot { width: 8px; height: 8px; border-radius: 50%; background: #4caf50; flex: 0 0 auto; }
.ppanel-head .pdot.off { background: #667; }
.ppanel-head .pname { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ppanel-head .ppts { margin-left: auto; font-weight: 800; color: var(--gold); font-size: 15px; display: flex; align-items: center; gap: 2px; }
.gemstats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.gemstat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.gs-card { width: 100%; aspect-ratio: 1; border-radius: 5px; color: #fff; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px rgba(0,0,0,.6); border: 1px solid rgba(0,0,0,.3); }
.gs-card.g-w { color: #fff; }
.gs-card.empty { background: rgba(120,120,120,.18); color: var(--ink-dim); text-shadow: none; }
/* トークン枚数を丸いコイン型で (色即判別) */
.gs-tok { width: 100%; aspect-ratio: 1; border-radius: 50%; font-size: 11px; font-weight: 800; color: #fff;
  display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.gs-tok.zero { opacity: .18; }
.ppanel-foot { display: flex; gap: 6px; margin-top: 5px; font-size: 11px; color: var(--ink-dim); white-space: nowrap; }
.ppanel-foot .pf-gem { color: var(--ink); font-weight: 700; } /* 手持ち宝石の合計 x/10 */
.ppanel-foot .pf-gem.over { color: #ff8f6b; } /* 10枚超 = 手番終了時に捨てる */

/* ---- カード段 ---- */
.tier-row { display: flex; gap: 8px; align-items: stretch; }
.deck-pile {
  flex: 0 0 auto; width: 52px; border-radius: 9px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 20px; border: 1px solid rgba(255,255,255,.25);
}
.deck-pile.t1 { background: linear-gradient(160deg, #2f6f46, #17492c); }
.deck-pile.t2 { background: linear-gradient(160deg, #b98a2e, #7c5a17); }
.deck-pile.t3 { background: linear-gradient(160deg, #7a4bb0, #4a2c74); }
.deck-pile small { font-size: 11px; opacity: .9; font-weight: 700; margin-top: 2px; }
.tier-cards { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; min-width: 0; }

.card {
  position: relative; aspect-ratio: 5/7; border-radius: 10px; cursor: pointer;
  color: #1a2330; border: 1px solid rgba(0,0,0,.18); box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column; overflow: hidden; transition: transform .08s;
  min-width: 0;
}
.card:active { transform: scale(.97); }
.card.empty { background: rgba(255,255,255,.05); border: 1px dashed var(--line); box-shadow: none; cursor: default; }
.card.affordable { outline: 3px solid var(--gold); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; }
/* 得点: 左上・星形 */
.star-badge {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 14px; color: #4a3600;
  background: linear-gradient(160deg, #ffe38a, var(--gold-dim));
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.star-badge.blank { visibility: hidden; }
/* 色: 右上 (テーマのフルーツ絵文字を中に表示) */
.card-bonus { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.card-mid { flex: 1; } /* 中央は色タイントのみの空きスペース (球体は廃止) */
/* コスト: 下部・横並び。折り返しは wrap-reverse で
   「下の行が埋まり、あふれた分が左上に乗る」順にする。 */
.card-costs { display: flex; gap: 3px; flex-wrap: wrap-reverse; align-content: flex-end; }
.cost-pip {
  width: 20px; height: 20px; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 1px rgba(0,0,0,.5);
}
.cost-pip.g-w { color: #fff; }

/* ---- トークン列 (銀行) ---- */
.token-wrap { position: relative; }
.token {
  width: 62px; height: 62px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px;
  color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); transition: transform .08s;
}
.token:active { transform: scale(.92); }
.token.selected { outline: 3px solid var(--gold); outline-offset: 2px; }
.token.disabled { opacity: .32; cursor: default; }
.token .tok-glyph { font-size: 30px; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.token .count {
  position: absolute; right: -3px; bottom: -3px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 50%; width: 24px; height: 24px;
  font-size: 12px; display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.token .selbadge {
  position: absolute; left: -4px; top: -4px; background: var(--gold); color: #2a1c00;
  border-radius: 50%; width: 20px; height: 20px; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}

/* ---- 貴族 ---- */
.noble {
  width: 66px; height: 66px; border-radius: 10px; padding: 5px; overflow: hidden;
  background: linear-gradient(135deg, #efe3c4, #d8c48c); color: #3a2e12;
  border: 2px solid var(--gold); box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: space-between;
}
.noble .pts { font-weight: 800; font-size: 14px; display: flex; align-items: center; gap: 1px; }
/* 必要ボーナスのpipは1行に収める (はみ出し防止) */
.noble .req { display: flex; flex-wrap: nowrap; gap: 2px; justify-content: flex-start; }
.noble .req .pip { font-size: 9px; font-weight: 800; padding: 1px 3px; border-radius: 4px; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.4); white-space: nowrap; }
.noble .req .pip.g-w { color: #fff; }

/* ---- 手元バー ---- */
#handBar { position: sticky; bottom: 0; z-index: 4; background: var(--panel2); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  /* ホームインジケータ/左右ノッチを避ける (下の余白ぶんは暗い地色で埋まる) */
  padding: 8px calc(12px + var(--sar)) calc(8px + var(--sab)) calc(12px + var(--sal)); }
.hand-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hand-total { font-size: 13px; color: var(--ink-dim); }
.hand-total b { color: var(--ink); font-size: 16px; }
.hand-tokens { display: flex; gap: 5px; }
.hand-tok {
  width: 34px; height: 34px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px rgba(0,0,0,.6); cursor: default; position: relative;
}
.hand-tok.discardable { cursor: pointer; outline: 2px solid var(--gold); }
.hand-tok .minus { position: absolute; right: -3px; top: -6px; color: var(--gold); font-size: 12px; font-weight: 800; }
.reserved-region { display: flex; gap: 6px; align-items: center; }
.reserved-label { font-size: 11px; color: var(--ink-dim); }
.mini-card {
  width: 44px; height: 60px; border-radius: 7px; cursor: pointer; padding: 4px; position: relative;
  color: #1a2330; font-size: 10px; font-weight: 800; display: flex; flex-direction: column; justify-content: space-between;
  border: 1px solid rgba(0,0,0,.2); box-shadow: var(--shadow);
}
.mini-card.hidden-card { background: linear-gradient(160deg, #43506a, #2a3348); color: #cbd6e6; align-items: center; justify-content: center; text-align: center; }
.mini-card .mc-cost { display: flex; gap: 2px; flex-wrap: wrap; }
.mini-card .mc-pip { width: 13px; height: 13px; border-radius: 50%; font-size: 8px; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; }
/* 道場コーチバー */
.coach-bar { flex-basis: 100%; background: linear-gradient(180deg, #ffe8a6, #f4c65a); color: #4a3300;
  border: 1px solid var(--gold); border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 8px; }
.coach-bar .coach-ic { font-size: 16px; }
.coach-rec { outline: 3px solid var(--gold) !important; outline-offset: 2px; animation: coachpulse 1.1s ease-in-out infinite; }
@keyframes coachpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(242,193,78,.6); } 50% { box-shadow: 0 0 0 6px rgba(242,193,78,0); } }

/* 初回チュートリアル(吹き出し) */
.tutorial-bar { position: relative; flex-basis: 100%; background: linear-gradient(180deg, #d7e9ff, #a9cdfa); color: #0e2a4a;
  border: 1px solid #5b9be0; border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 700;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.tutorial-bar::before { content: ""; position: absolute; top: -8px; left: 22px; width: 14px; height: 14px;
  background: #d7e9ff; border-left: 1px solid #5b9be0; border-top: 1px solid #5b9be0; transform: rotate(45deg); }
.tutorial-bar .tut-ic { font-size: 16px; flex: 0 0 auto; }
.tutorial-bar .tut-text { flex: 1 1 180px; line-height: 1.5; }
.tutorial-bar .tut-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.tutorial-bar .tut-actions .btn { width: auto; margin: 0; min-width: 0; padding: 7px 14px; font-size: 12px; }
.tutorial-rec { outline: 3px solid #5b9be0 !important; outline-offset: 2px; animation: tutpulse 1.1s ease-in-out infinite; border-radius: 8px; }
@keyframes tutpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(91,155,224,.6); } 50% { box-shadow: 0 0 0 6px rgba(91,155,224,0); } }

.action-region { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.action-region .btn { width: auto; margin: 0; min-width: 120px; }
.action-hint { font-size: 11px; color: var(--ink-dim); display: flex; flex-direction: column; line-height: 1.45; } /* 2行(宝石ルール / カード操作) */
.action-hint span { white-space: nowrap; } /* 各行は途中改行しない */

/* ---- モーダル / ドロワー / トースト ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 20px; }
.modal-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.modal-actions { display: flex; gap: 8px; margin: 12px 0; }
.modal-actions .btn { margin: 0; }
.card-detail { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }

/* ---- 勝敗リザルト ---- */
.result-box { max-width: 380px; text-align: center; border: 2px solid var(--gold); }
.result-trophy { font-size: 52px; line-height: 1; margin: 4px 0; }
.result-title { font-size: 22px; font-weight: 800; margin: 6px 0 2px; }
.result-title.win { color: var(--gold); }
.result-sub { color: var(--ink-dim); font-size: 13px; margin-bottom: 12px; }
.result-scores { list-style: none; padding: 0; margin: 0 0 14px; }
.result-scores li { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; margin: 6px 0; background: var(--panel); border-radius: 10px; border: 1px solid var(--line); }
.result-scores li.winner { border-color: var(--gold); background: rgba(242,165,42,.16); }
.result-scores .rk { width: 22px; color: var(--ink-dim); font-weight: 800; }
.result-scores .nm { flex: 1; text-align: left; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-scores .sc { font-weight: 800; color: var(--gold); }
.result-scores .meta { color: var(--ink-dim); font-size: 11px; font-weight: 500; }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.result-actions .btn { margin: 0; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(88%, 340px); background: var(--panel2); border-left: 1px solid var(--line); z-index: 20; overflow-y: auto; box-shadow: -8px 0 24px rgba(0,0,0,.4);
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) 16px; }
/* メニュー上部: 退出・再戦など主要操作は常にここ(ログが長くても埋もれない) */
.drawer-primary { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.drawer-primary .btn { margin: 0; }
.log-list { list-style: none; padding: 0; margin: 0 0 14px; font-size: 13px; color: var(--ink-dim); }
.log-list li { padding: 5px 0; border-bottom: 1px solid var(--line); }
/* 貴族選択モーダル: タップで直接選べるカード一覧 */
.noble-modal-grid { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.noble-modal-grid .noble { width: 84px; height: 84px; cursor: pointer; border-width: 3px; transition: transform .08s, filter .15s; }
.noble-modal-grid .noble:hover { filter: brightness(1.12); }
.noble-modal-grid .noble:active { transform: scale(.96); }
.noble-modal-grid .noble .pts { font-size: 16px; }
.noble-modal-grid .noble .req .pip { font-size: 10px; padding: 2px 4px; }
.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: #d23f3f; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 14px; box-shadow: var(--shadow); max-width: 90%; }
.toast.ok { background: #2fa257; }

/* =================================================== */
/* ===== 縦画面 (portrait): 縦積みに組み替え ===== */
/* スマホ横持ちは landscape 扱いなので下のワイドが効く。 */
/* =================================================== */
@media (orientation: portrait) {
  #board {
    grid-template-columns: 1fr;
    grid-template-areas: "nobles" "tokens" "tiers" "players";
    gap: 8px; padding: 8px calc(10px + var(--sar)) 8px calc(10px + var(--sal));
  }
  .nobles-region { flex-direction: row; overflow-x: auto; padding-bottom: 2px; }
  .tokens-region { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .players-region { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .players-region .ppanel { flex: 0 0 200px; }
  .token { width: 48px; height: 48px; font-size: 16px; }
  .noble { width: 56px; height: 56px; }
  .deck-pile { width: 44px; font-size: 17px; }
}

/* とても狭い縦: カードを小さく */
@media (orientation: portrait) and (max-width: 480px) {
  #board { gap: 6px; padding: 6px calc(10px + var(--sar)) 6px calc(10px + var(--sal)); }
  .tier-cards { gap: 6px; }
  .card { padding: 4px; border-radius: 8px; }
  .star-badge { width: 26px; height: 26px; font-size: 12px; }
  .card-bonus { width: 20px; height: 20px; }
  .cost-pip { width: 18px; height: 18px; font-size: 10px; }
  .ppanel { padding: 6px; }
  .ppanel-head { margin-bottom: 4px; }
  .ppanel-foot { margin-top: 3px; }
  #handBar { gap: 6px 8px; padding: 6px calc(10px + var(--sar)) calc(6px + var(--sab)) calc(10px + var(--sal)); }
  .action-region .btn { min-width: 100px; font-size: 14px; }
}

/* =================================================== */
/* ===== 横画面で背が低い = スマホ横持ち: ワイドを1画面に圧縮 ===== */
/* 高さに合わせてカードを縮め、スクロールなしで収める。 */
/* =================================================== */
@media (orientation: landscape) and (max-height: 560px) {
  #game { height: 100dvh; overflow: hidden; }
  #topbar { padding: calc(4px + var(--sat)) calc(10px + var(--sar)) 4px calc(10px + var(--sal)); }
  .brand { font-size: 15px; }
  .turn-banner { font-size: 12px; }

  #board {
    flex: 1 1 auto; min-height: 0; overflow: hidden; align-items: stretch;
    grid-template-columns: 132px minmax(0, 1fr) auto auto;
    gap: 6px; padding: 6px calc(6px + var(--sar)) 6px calc(6px + var(--sal));
  }
  .players-region { gap: 5px; overflow-y: auto; }
  .ppanel { padding: 5px; }
  .ppanel-head { margin-bottom: 4px; }
  .ppanel-head .pname { font-size: 11px; }
  .ppanel-head .ppts { font-size: 13px; }
  .gemstats { gap: 2px; }
  .gs-card { font-size: 10px; border-radius: 4px; }
  .gs-tok { font-size: 10px; }
  .ppanel-foot { font-size: 10px; gap: 5px; margin-top: 3px; }

  /* カードは行の高さに合わせて縮める (幅は縦横比から算出) */
  .tiers-region { justify-content: space-between; gap: 6px; height: 100%; }
  .tier-row { flex: 1 1 0; min-height: 0; gap: 5px; }
  .tier-cards { display: flex; gap: 5px; }
  .card { height: 100%; width: auto; aspect-ratio: 5/7; padding: 4px; border-radius: 7px; }
  .deck-pile { height: 100%; width: auto; aspect-ratio: 5/7; font-size: 14px; }
  .star-badge { width: 20px; height: 20px; font-size: 10px; }
  .card-bonus { width: 15px; height: 15px; }
  .card-costs { gap: 2px; }
  .cost-pip { width: 15px; height: 15px; font-size: 9px; }

  .tokens-region { gap: 5px; }
  .token { width: 42px; height: 42px; font-size: 14px; }
  .token .count { width: 18px; height: 18px; font-size: 10px; }
  .token .selbadge { width: 16px; height: 16px; font-size: 10px; }
  .nobles-region { gap: 5px; }
  .noble { width: 48px; height: 48px; padding: 3px; }
  .noble .pts { font-size: 12px; }
  .noble .req .pip { font-size: 8px; padding: 0 3px; }

  #handBar { padding: 4px calc(10px + var(--sar)) calc(4px + var(--sab)) calc(10px + var(--sal)); gap: 8px; flex-wrap: nowrap; overflow-x: auto; }
  .mini-card { width: 34px; height: 46px; }
  .action-region .btn { min-width: 96px; font-size: 13px; padding: 8px 10px; }
  .action-hint { display: none; } /* 横スマホでは省スペース優先 */
}
