:root {
  --bg: #1d2430;
  --panel: #283242;
  --panel2: #323e52;
  --text: #ecebe4;
  --dim: #9aa3b2;
  --accent: #f0c552;
  --up: #5adca0;
  --down: #f06e64;
  --sel: #58b4ff;
  /* カードの幅は画面の幅と高さの両方に合わせる（縦が短い画面でもはみ出さない） */
  --kw: clamp(56px, min(6.4vw, 11.5vh), 112px);   /* サプライのカード幅 */
  --hw: clamp(66px, min(7.4vw, 13vh), 124px);     /* 手札のカード幅 */
  --pw: clamp(46px, min(4.6vw, 7.5vh), 80px);     /* 場のカード幅 */
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; }
button, .button, input, select {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid #4a5870;
  border-radius: 8px; padding: 6px 12px; text-decoration: none; display: inline-block;
}
button, .button { cursor: pointer; }
button:hover:not(:disabled), .button:hover { background: #3e4d66; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: #b98a1c; border-color: #e0b244; color: #fff; font-weight: bold; }
button.primary:hover:not(:disabled) { background: #cf9c22; }
button.big { padding: 10px 22px; font-size: 16px; }
input { background: #1a212c; }
.hidden { display: none !important; }
.view { min-height: 100vh; }
h1 { text-align: center; color: var(--accent); margin: 28px 0 4px; font-size: 32px; }
h2 { font-size: 16px; margin: 18px 0 8px; color: var(--dim); }
.sub { text-align: center; color: var(--dim); margin: 0 0 18px; }
.panel { max-width: 980px; margin: 0 auto 30px; background: var(--panel); border-radius: 14px; padding: 18px 22px; }
.row { display: flex; gap: 10px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 18px; }
.grow { flex: 1; min-width: 240px; }
.radios label { margin-right: 14px; cursor: pointer; }
.hint { color: var(--dim); font-size: 13px; }
.banner { position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 50;
  background: #a33c33; color: #fff; padding: 8px 18px; border-radius: 0 0 10px 10px; }
.banner.info { background: #2f6aa8; }

/* ---------- ロビー ---------- */
.seat-editor { display: flex; gap: 10px; flex-wrap: wrap; }
.seat-editor .seat { background: var(--panel2); border-radius: 10px; padding: 8px 12px; min-width: 170px; }
.seat-editor .seat b { display: block; margin-bottom: 6px; color: var(--dim); font-weight: normal; font-size: 12px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 340px; overflow: auto; }
.pick { background: var(--panel2); border-radius: 8px; padding: 6px 8px; cursor: pointer; border: 2px solid transparent; font-size: 13px; }
.pick.on { border-color: var(--accent); background: #4a4326; }
.pick small { color: var(--dim); }
.cpu-opts { gap: 16px; align-items: center; margin-top: 8px; }
.join-error { color: #ff8c78; font-weight: bold; min-height: 1em; }
.host-panel { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.passphrase { font-family: ui-monospace, Consolas, monospace; font-size: 22px; font-weight: bold;
              letter-spacing: 2px; background: var(--panel2); border-radius: 8px; padding: 4px 12px;
              color: var(--accent); user-select: all; }
.members { display: flex; flex-direction: column; gap: 4px; background: var(--panel2);
           border-radius: 8px; padding: 8px 10px; }
.member { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
button.small { padding: 2px 8px; font-size: 12px; }
button.danger { background: #8a3a32; }
#private-box.hidden { display: none; }
.modal.ask { z-index: 60; }               /* 部屋の管理画面などの上に重ねる */
.ask-box { max-width: min(680px, 94vw); }
.ask-msg { line-height: 1.7; margin: 4px 0 12px; }
.ask-buttons { flex-wrap: wrap; }
.copy-area { width: min(620px, 86vw); box-sizing: border-box; resize: none; font-size: 14px;
             line-height: 1.6; white-space: pre; overflow-x: auto;   /* 折り返さず全文を見せる */
             font-family: ui-monospace, Consolas, monospace; background: var(--panel2);
             color: var(--text); border-radius: 6px; padding: 8px; }
.speed-box { font-size: 13px; color: var(--dim); display: inline-flex; gap: 4px; align-items: center;
             white-space: nowrap; flex-shrink: 0; }
.speed-box.hidden { display: none; }
.pick { position: relative; }
.pick.cand { border-color: #82b9ff; background: #26364d; }
.pick.won { box-shadow: 0 0 0 2px #6fd38a inset; }
.pick.off { opacity: .45; }
.ptag { position: absolute; top: -8px; right: 4px; font-size: 10px; font-weight: bold; color: #1e1e1e;
        border-radius: 5px; padding: 0 5px; }
.ptag.fixed { background: var(--accent); }
.ptag.won { background: #6fd38a; }
.pick-summary { font-weight: bold; font-size: 15px; margin: 4px 0; }
.pick-modes { display: inline-flex; gap: 6px; align-items: center; }
.pick-msg { color: #ff8c78; font-weight: bold; margin-left: 10px; }
.drawn-box { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 6px 0;
             background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.dchip { background: #2f4a37; border-radius: 6px; padding: 1px 7px; font-size: 13px; }
.dchip.fixed { background: #4a4326; }
.pick-grid { padding-top: 8px; }
.tag-fixed { color: var(--accent); }
.tag-cand { color: #82b9ff; }
.wait-seats { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.wait-seat { background: var(--panel2); border-radius: 10px; padding: 10px 16px; min-width: 150px; }
.wait-seat.empty { opacity: .55; border: 1px dashed #6a7890; }
.wait-kingdom { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- カード ---------- */
.card {
  --w: var(--kw);
  position: relative; width: var(--w); height: calc(var(--w) * 1.45); flex: none;
  border-radius: calc(var(--w) * .08); color: #222; overflow: hidden; user-select: none;
  background: var(--c1, #e9e2cf); border: 2px solid rgba(0,0,0,.45);
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
  display: flex; flex-direction: column; font-size: calc(var(--w) * .105);
  transition: transform .08s, box-shadow .08s;
  -webkit-touch-callout: none; touch-action: manipulation;   /* 長押しでメニューを出さない・ダブルタップで拡大しない */
}
.card.two { background: linear-gradient(135deg, var(--c1) 0 50%, var(--c2) 50% 100%); }
/* 上の段：コストの硬貨と名前（カード幅に合わせて大きく。硬貨と名前が重ならないよう名前の左を空ける） */
.card .nm { font-weight: bold; text-align: center; padding: 3% 3% 0 29%; line-height: 1.12;
  font-size: 1.15em; min-height: 2.3em; display: flex; align-items: center; justify-content: center; }
.card .cost { position: absolute; left: 4%; top: 3%; width: 1.85em; height: 1.85em; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe68a, #d69b18); border: 1px solid #7a5a10;
  display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 1.25em; }
.card .art { margin: 2% 5%; flex: 1; border-radius: 6px; background: rgba(255,255,255,.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  line-height: 1.2; overflow: hidden; padding: 2%; }
/* 本文：+カード／+アクション／+購入／+$ を1行ずつ、大きめに（「+1 アクション」が1行に収まる大きさ） */
.card .bonus { font-weight: bold; font-size: 1.2em; line-height: 1.25; }
.card .bonus .bl { white-space: nowrap; }
.card .txt { font-size: .82em; color: #333; }
.card .big-coin { width: 2.9em; height: 2.9em; border-radius: 50%; font-size: 1.7em; font-weight: bold;
  background: radial-gradient(circle at 35% 35%, #fff1a8, #d9a21c); border: 2px solid #7a5a10;
  display: flex; align-items: center; justify-content: center; color: #4b3505; }
.card .big-vp { width: 2.6em; height: 2.9em; font-size: 1.6em; font-weight: bold; color: #fff;
  background: #2e7d32; clip-path: polygon(0 0, 100% 0, 100% 65%, 50% 100%, 0 65%);
  display: flex; align-items: center; justify-content: center; padding-bottom: .4em; }
.card .big-vp.neg { background: #6a3c8c; }
.card .tp { text-align: center; font-size: .78em; padding: 1% 0 3%; color: #333; }
.card.mini .art .txt { display: none; }
.card.hidden-card { background: repeating-linear-gradient(45deg, #39465e 0 6px, #2f3a4f 6px 12px); border-color: #1b2230; }

.t-Action { --c1: #ebe5d3; }
.t-Treasure { --c1: #f2cf63; }
.t-Victory { --c1: #8fcf86; }
.t-Curse { --c1: #b48ad6; }
.t-Reaction { --c1: #8eb8e6; }
.t-Duration { --c1: #f0a868; }
.t-Attack .nm { color: #8a1c14; }

.card.clickable { cursor: pointer; }
.card.playable { box-shadow: 0 0 0 3px var(--up), 0 4px 10px rgba(0,0,0,.45); }
.card.playable:hover, .card.selectable:hover { transform: translateY(-6px); }
.card.selectable { cursor: pointer; box-shadow: 0 0 0 3px rgba(88,180,255,.6); }
.card.selected { transform: translateY(-12px); box-shadow: 0 0 0 4px var(--sel), 0 6px 14px rgba(0,0,0,.5); }
.card .order { position: absolute; right: 4%; top: 3%; background: var(--sel); color: #fff; border-radius: 50%;
  width: 1.7em; height: 1.7em; display: flex; align-items: center; justify-content: center; font-weight: bold; }
.card.dim { filter: grayscale(.6) brightness(.75); }

/* ---------- 対戦画面 ---------- */
#game { height: 100vh; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto auto; gap: 6px; padding: 6px 10px; }
.topbar { display: flex; align-items: center; gap: 16px; background: var(--panel); border-radius: 10px; padding: 6px 14px; }
.turninfo { min-width: 260px; }
#turn-label { font-weight: bold; font-size: 16px; }
.phase { color: var(--accent); font-size: 13px; }
.counters { display: flex; gap: 10px; flex: 1; justify-content: center; }
.counter { position: relative; background: var(--panel2); border-radius: 10px; padding: 4px 16px; text-align: center; min-width: 96px; }
.topbar button { white-space: nowrap; }
@media (max-width: 1200px) {
  .topbar { gap: 8px; }
  .turninfo { min-width: 0; flex-shrink: 1; }
  .counter { min-width: 56px; padding: 4px 8px; }
}
.counter .lbl { display: block; font-size: 11px; color: var(--dim); }
.counter .val { font-size: 24px; font-weight: bold; transition: color .3s; }
.counter.flash-up .val { color: var(--up); }
.counter.flash-down .val { color: var(--down); }
.tools { display: flex; gap: 6px; }

.opponents { display: flex; gap: 8px; }
.opp { flex: 1; background: var(--panel); border-radius: 10px; padding: 6px 10px; display: flex; gap: 10px; align-items: center; min-width: 0; border: 2px solid transparent; }
.opp.current { border-color: var(--accent); }
.opp .who { font-weight: bold; white-space: nowrap; }
.opp .stats { color: var(--dim); font-size: 12px; white-space: nowrap; }
.opp .badge { font-size: 11px; background: #7a2f2a; padding: 1px 6px; border-radius: 6px; margin-left: 4px; }
.opp .extra { display: flex; gap: 4px; overflow: hidden; }
.opp .card { --w: 38px; }

.board { display: grid; grid-template-columns: minmax(0, 1fr) clamp(240px, 22vw, 330px); gap: 8px; min-height: 0; }
.supply-wrap { display: flex; gap: 10px; background: var(--panel); border-radius: 10px; padding: 8px; min-height: 0; overflow: auto; align-items: flex-start; }
.supply-base { display: flex; flex-direction: column; gap: 8px; }
.base-row { display: flex; gap: 6px; }
.supply-base .card { --w: calc(var(--kw) * .78); }
.supply-kingdom { display: grid; grid-template-columns: repeat(5, auto); gap: 6px; flex: 1; justify-content: center; }
.pile { position: relative; }
.pile .count { position: absolute; right: -4px; bottom: -4px; background: #11161f; color: #fff; border-radius: 10px;
  padding: 0 7px; font-size: 12px; font-weight: bold; border: 1px solid #556; z-index: 2; }
.pile.empty .card { opacity: .3; }
.pile.buyable .card { box-shadow: 0 0 0 3px var(--accent), 0 4px 10px rgba(0,0,0,.45); cursor: pointer; }
.pile.buyable .card:hover, .pile.gainable .card:hover { transform: translateY(-4px); }
.pile.gainable .card { box-shadow: 0 0 0 3px var(--sel), 0 4px 10px rgba(0,0,0,.45); cursor: pointer; }

.side { display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 6px; min-height: 0; }
.detail { background: var(--panel); border-radius: 10px; padding: 8px; display: flex; gap: 8px; min-height: 120px; }
.detail .card { --w: 96px; }
.detail .info { font-size: 13px; line-height: 1.45; white-space: pre-wrap; flex: 1; }
.detail .info b { font-size: 15px; }
.detail-empty { color: var(--dim); font-size: 12px; margin: auto; }
.feed { background: var(--panel); border-radius: 10px; padding: 6px 8px; min-height: 44px; font-size: 13px; }
.feed div { transition: opacity .6s; }
.feed .old { opacity: .45; }
.log { background: var(--panel); border-radius: 10px; padding: 6px 8px; overflow: auto; font-size: 12px; color: #cfd3da; min-height: 0; }
.log div { padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.log .turn { color: var(--accent); margin-top: 4px; }

.playrow, .hand-wrap { display: flex; align-items: center; gap: 8px; min-height: 0; }
.area-label { color: var(--dim); font-size: 12px; writing-mode: vertical-rl; text-orientation: upright; letter-spacing: 2px; position: relative; }
.cards-row { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; overflow-y: visible; padding: 14px 4px 4px; min-height: calc(var(--pw) * 1.45 + 20px); flex: 1; }
.playrow .card { --w: var(--pw); }
.playrow { background: var(--panel); border-radius: 10px; padding: 0 8px; }
.cards-row .sep { width: 2px; background: #556; margin: 0 6px; flex: none; }

.prompt { display: flex; align-items: center; gap: 10px; background: #3a3220; border: 1px solid #6b5a2a; border-radius: 10px; padding: 8px 14px; min-height: 48px; flex-wrap: wrap; }
.prompt .text { flex: 1; font-size: 15px; min-width: 200px; }
.prompt.waiting { background: var(--panel); border-color: transparent; color: var(--dim); }

.me { display: flex; gap: 10px; align-items: stretch; }
.my-info { background: var(--panel); border-radius: 10px; padding: 8px 10px; width: 190px; font-size: 13px; flex: none; }
.my-info .who { font-weight: bold; font-size: 15px; margin-bottom: 4px; }
.my-info .piles { display: flex; gap: 6px; margin-top: 6px; }
.my-info .piles .card { --w: 44px; }
.hand-wrap { flex: 1; background: var(--panel); border-radius: 10px; padding: 0 8px; min-width: 0; }
.hand .card { --w: var(--hw); }
.hand { min-height: calc(var(--hw) * 1.45 + 24px); }

/* ---------- モーダル ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal-box { background: var(--panel); border-radius: 14px; padding: 18px 22px; max-width: min(1100px, 94vw); max-height: 90vh; overflow: auto; }
.modal-box h2 { color: var(--text); font-size: 20px; margin-top: 0; }
.modal-cards { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; padding-top: 12px; }
.modal-cards .card { --w: 110px; }
.result-table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.result-table td, .result-table th { padding: 6px 10px; border-bottom: 1px solid #445; text-align: left; vertical-align: top; }
.result-table .win { color: var(--accent); font-weight: bold; }
.deck-list { font-size: 12px; color: #cfd3da; }

/* ---------- 値の変化の表示 ---------- */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.float { position: absolute; transform: translate(-50%, 0); text-align: center; white-space: nowrap;
  animation: rise 1.8s ease-out forwards; text-shadow: 0 1px 3px #000, 0 0 6px #000; }
.float .main { font-size: 22px; font-weight: bold; }
.float .subtxt { font-size: 12px; color: #e8e8e8; }
.float.up .main { color: var(--up); }
.float.down .main { color: var(--down); }
.float.zero .main { color: #ddd; }
@keyframes rise { 0% { opacity: 0; margin-top: 6px; } 10% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; margin-top: -26px; } }

.dock { display: contents; }   /* パソコンでは #game のグリッドにそのまま並ぶ */

@media (max-width: 900px) {
  .board { grid-template-columns: 1fr; }
  .side { display: none; }
  .my-info { width: 120px; }
}

/* ---------- スマホ（幅 700px 以下） ----------
   縦に1列で並べ、ページ全体を縦にスクロールする。プロンプトと手札は画面の下に固定。
   カードの説明は長押しで出す（マウスを乗せる操作がないため）。 */
@media (max-width: 700px) {
  :root {
    /* 王国カードは 4 列が画面いっぱいに収まる幅（広めのスマホでは 100px まで） */
    --kw: min(100px, calc((100vw - 36px) / 4));
    /* 手札は 5 枚がほぼ収まる幅 */
    --hw: max(62px, calc((100vw - 120px) / 5));
    --pw: 44px;
  }
  body { font-size: 13px; }
  h1 { font-size: 24px; margin-top: 16px; }
  .panel { padding: 12px 12px; margin-bottom: 16px; border-radius: 10px; }
  .seat-editor .seat { min-width: 0; flex: 1 1 40%; }
  .grow { min-width: 0; }

  #game { height: auto; min-height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 4px 6px 0; }
  /* 上の段：1行目に手番とボタン、2行目にアクション・購入・コイン */
  .topbar { flex-wrap: wrap; gap: 4px 6px; padding: 6px 8px; }
  .turninfo { flex: 1 1 auto; min-width: 0; }
  #turn-label { font-size: 14px; }
  .phase { font-size: 12px; }
  .tools { flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
  .tools button { padding: 4px 8px; font-size: 12px; }
  .speed-box { font-size: 11px; }
  .speed-box select { padding: 2px 4px; font-size: 12px; }
  .counters { order: 3; flex: 1 1 100%; gap: 6px; }
  .counter { flex: 1; min-width: 0; padding: 2px 4px; }
  .counter .val { font-size: 18px; }

  .opponents { flex-direction: column; gap: 4px; }
  .opp { padding: 4px 8px; flex-wrap: wrap; gap: 4px 8px; }
  .opp .stats { white-space: normal; }

  .board { display: flex; flex-direction: column; gap: 4px; }
  .supply-wrap { flex-direction: column; align-items: center; overflow: visible; padding: 6px 4px; }
  .supply-base { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .supply-base .card { --w: calc(var(--kw) * .64); }
  .base-row { flex-wrap: wrap; justify-content: center; }
  .supply-kingdom { grid-template-columns: repeat(auto-fill, var(--kw)); justify-content: center; width: 100%; gap: 6px 4px; }
  /* 説明欄は長押しの画面で出すので隠す。直前の行動と記録は小さく残す */
  .side { display: grid; grid-template-rows: auto auto; }
  .detail { display: none; }
  .log { max-height: 110px; }

  .playrow { padding: 0 4px; }
  .area-label { display: none; }
  .cards-row { padding: 10px 2px 4px; min-height: calc(var(--pw) * 1.45 + 14px); }

  /* 下に固定：プロンプト（ボタン）と手札 */
  .dock { display: flex; flex-direction: column; gap: 4px; position: sticky; bottom: 0; z-index: 20;
          background: var(--bg); padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
          box-shadow: 0 -6px 12px rgba(0,0,0,.4); }
  .prompt { padding: 6px 8px; min-height: 0; gap: 6px; }
  .prompt .text { min-width: 0; font-size: 13px; flex: 1 1 100%; }
  .prompt button { padding: 6px 10px; }
  /* 自分の情報は手札の上に1行で（山札・捨て札の絵は出さず、枚数だけ） */
  .me { flex-direction: column; gap: 4px; }
  .my-info { width: auto; padding: 3px 8px; font-size: 12px; display: flex; flex-wrap: wrap;
             align-items: baseline; gap: 0 10px; }
  .my-info .who { font-size: 12px; margin: 0; }
  .my-info .piles { margin: 0; gap: 10px; }
  .my-info .piles .card { display: none; }
  .hand-wrap { padding: 0 4px; }
  .hand { min-height: calc(var(--hw) * 1.45 + 16px); }

  .modal-box { padding: 12px 14px; }
  .float .main { font-size: 18px; }
}

/* 長押しで出すカードの説明 */
.card-detail { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.card-detail .card { --w: 140px; }
.card-detail .info { white-space: pre-wrap; line-height: 1.6; font-size: 15px; flex: 1; min-width: 180px; }
.card-detail .info b { font-size: 18px; }
