/* トラバト — 見た目
   カードの大きさは --cw（幅）ひとつで決まります。画面の幅と高さの両方に収まる大きさを自動で選びます。 */
:root {
  color-scheme: dark;
  --felt: #0f5a36;
  --felt-hi: #177a4d;
  --felt-lo: #072c1c;
  --ink: #f3efe2;
  --ink-dim: #a9c2b3;
  --line: rgba(255, 255, 255, .13);
  --gold: #f2c14e;
  --gold-lo: #b8860b;
  --redc: #c8102e;
  --blkc: #1b1f23;
  --card: #fdfbf5;
  --card-edge: #cfc7b3;
  --opp: #ef7b7b;
  --t-normal: #5eead4;
  --t-special: #fb7185;
  --t-stack: #a3e635;
  --t-block: #fbbf24;
  --t-copy: #c4a1ff;
  --t-attack: #fb923c;
  --gap: 5px;
  --cw: clamp(40px, min(calc((100vw - 16px - 5 * var(--gap)) / 6), calc((100vh - 250px) / 7.1)), 88px);
  --ch: calc(var(--cw) * 1.4);
  --w: var(--cw);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
}
@supports (height: 100dvh) {
  :root { --cw: clamp(40px, min(calc((100vw - 16px - 5 * var(--gap)) / 6), calc((100dvh - 250px) / 7.1)), 88px); }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background: var(--felt);
  background: radial-gradient(ellipse 90% 70% at 50% 50%, var(--felt-hi), var(--felt) 45%, var(--felt-lo));
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }

/* ---------- ボタン ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: 14px; line-height: 1.2;
  min-height: 36px; padding: 8px 16px;
  color: var(--ink); background: rgba(0, 0, 0, .25);
  border: 1.5px solid rgba(255, 255, 255, .35); border-radius: 999px;
  cursor: pointer; transition: background .15s, transform .08s;
}
.btn:hover { background: rgba(255, 255, 255, .12); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { color: #2a1d00; background: linear-gradient(#f8d67a, #e3a92b); border-color: #f8d67a; }
.btn.primary:hover { background: linear-gradient(#fbe09a, #eab53c); }
.btn.danger { border-color: #f08a8a; color: #ffd6d6; }
.btn.fx { border-color: var(--t-copy); color: #efe4ff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, .1); }
.btn.big { font-size: 17px; padding: 14px 20px; }
.btn.small { font-size: 12.5px; padding: 4px 10px; min-height: 30px; }

/* ---------- タイトル ---------- */
.title { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; text-align: center; }
.title-inner { width: min(420px, 100%); }
.logo-cards { position: relative; height: 92px; margin: 0 auto 4px; width: 200px; }
.lc {
  position: absolute; left: 50%; top: 8px; width: 54px; height: 76px; margin-left: -27px;
  display: grid; place-items: center; font-size: 34px;
  background: var(--card); border: 1px solid var(--card-edge); border-radius: 7px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .4); color: var(--blkc);
  transform-origin: 50% 120%;
}
.lc2, .lc3 { color: var(--redc); }
.lc1 { transform: rotate(-24deg); }
.lc2 { transform: rotate(-8deg); }
.lc3 { transform: rotate(8deg); }
.lc4 { transform: rotate(24deg); }
.logo {
  margin: 6px 0 4px; font-size: clamp(46px, 13vw, 80px); font-weight: 900; letter-spacing: .06em;
  color: var(--gold); text-shadow: 0 3px 0 #6b4a00, 0 10px 26px rgba(0, 0, 0, .5);
}
.tagline { margin: 0; color: var(--ink-dim); font-size: 14px; }
.menu { display: flex; flex-direction: column; gap: 10px; margin: 28px auto 0; width: min(320px, 100%); }
.foot { margin-top: 28px; font-size: 12px; color: var(--ink-dim); opacity: .7; }
.foot a { color: inherit; text-decoration: none; }           /* ハブ（ほかのゲーム）へ戻る道 */
.foot a:hover { color: var(--gold); }

/* ---------- 対戦画面 ---------- */
.game { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  flex: none; display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 6px;
  background: rgba(0, 0, 0, .28); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 900; color: var(--gold); letter-spacing: .05em; font-size: 15px; }
.modelabel { flex: 1; min-width: 0; font-size: 12px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.board {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column;
  width: 100%; max-width: calc(6 * var(--cw) + 5 * var(--gap) + 16px); margin: 0 auto; padding: 4px 8px 0;
}
.side { flex: none; display: flex; flex-direction: column; gap: 7px; }
.side.opp { padding-top: 2px; }
.row { display: flex; gap: var(--gap); align-items: flex-start; }
.slots { display: grid; grid-template-columns: repeat(5, var(--cw)); gap: var(--gap); }

.slot {
  position: relative; width: var(--cw); height: var(--ch);
  border-radius: calc(var(--cw) * .1);
  background: rgba(0, 0, 0, .12);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .14);
}
.slots.life .slot { height: calc(var(--ch) * .78); --w: calc(var(--cw) * .78); display: grid; place-items: center; }
.slot .in { position: absolute; inset: 0; display: grid; place-items: center; }
.slots.life .slot .in { position: static; }

/* 場のカード（1枚・重ね掛け・裏向き） */
.stk { position: relative; width: var(--cw); height: var(--ch); transition: transform .25s; }
.stk > .card { position: absolute; left: 0; top: 0; }
.stk.two > .card:first-child { transform: translate(-7%, -5%) scale(.9); }
.stk.two > .card:last-child { transform: translate(8%, 6%) rotate(7deg) scale(.9); }
.stk.down { transform: rotate(90deg) scale(.714); }
.slot.done .stk { filter: brightness(.72) saturate(.7); }

.tag {
  position: absolute; z-index: 3; white-space: nowrap; pointer-events: none;
  font-size: 10.5px; font-weight: 800; line-height: 1.35; padding: 0 6px; border-radius: 999px;
}
.tag.atk { left: 50%; bottom: -7px; transform: translateX(-50%); background: rgba(0, 0, 0, .78); color: #fff; }
.tag.efx { right: -5px; top: -7px; background: var(--t-copy); color: #1d0b33; }
.tag.cnt { left: -4px; top: -7px; background: #fff; color: #102; }
.tag.done { left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, .7); color: #ddd; font-weight: 700; }

/* カード */
.card {
  position: relative; width: var(--w); height: calc(var(--w) * 1.4); flex: none;
  border-radius: calc(var(--w) * .1); background: var(--card); border: 1px solid var(--card-edge);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .38); color: var(--blkc); overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
.card.red { color: var(--redc); }
.card .cr {
  position: absolute; left: calc(var(--w) * .06); top: calc(var(--w) * .05);
  display: flex; flex-direction: column; align-items: center; line-height: .95;
  font: 800 calc(var(--w) * .3) / .95 Georgia, "Times New Roman", serif; letter-spacing: -.05em;
}
.card .cr i { font-style: normal; font-family: system-ui, sans-serif; font-size: calc(var(--w) * .22); margin-top: 1px; }
.card .cr.br { left: auto; top: auto; right: calc(var(--w) * .06); bottom: calc(var(--w) * .05); transform: rotate(180deg); }
.card .pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--w) * .52); padding-top: calc(var(--w) * .05); }
.card.hi .pip { font: 800 calc(var(--w) * .46) / 1 Georgia, serif; }
.card.joker { background: linear-gradient(140deg, #fff6cf, #ffd9ec 50%, #d4efff); color: #6a2c91; }
.card.joker .pip { font-size: calc(var(--w) * .5); color: #d4418e; }
.card.joker .cr { font-family: system-ui, sans-serif; font-size: calc(var(--w) * .2); letter-spacing: 0; }
.card.back {
  background: repeating-linear-gradient(45deg, #7a2030 0 4px, #9b3444 4px 8px);
  border: 2px solid #fdfbf5;
}
.card.back::after {
  content: ""; position: absolute; inset: calc(var(--w) * .07);
  border: 1px solid rgba(255, 255, 255, .45); border-radius: calc(var(--w) * .06);
}
.card.back.b2 { background: repeating-linear-gradient(45deg, #1d3557 0 4px, #2c4f7c 4px 8px); }

/* 押せる所・選んだ所 */
.tg { cursor: pointer; }
.tg::before {
  content: ""; position: absolute; inset: -4px; border-radius: calc(var(--cw) * .14); z-index: 4; pointer-events: none;
  border: 2.5px solid var(--tc, var(--t-normal)); box-shadow: 0 0 14px var(--tc, var(--t-normal));
  animation: pulse 1.1s ease-in-out infinite;
}
.tg-normal { --tc: var(--t-normal); }
.tg-special { --tc: var(--t-special); }
.tg-stack { --tc: var(--t-stack); }
.tg-block { --tc: var(--t-block); }
.tg-copy { --tc: var(--t-copy); }
.tg-attack { --tc: var(--t-attack); }
.tg-draw { --tc: var(--gold); }
@keyframes pulse { 50% { opacity: .35; } }
.slot.sel::after, .pile.sel::after {
  content: ""; position: absolute; inset: -4px; border-radius: calc(var(--cw) * .14); z-index: 5; pointer-events: none;
  border: 3px solid var(--gold); box-shadow: 0 0 18px rgba(242, 193, 78, .8);
}
.card.sel { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(242, 193, 78, .8) !important; }
.slot, .pile, .ohand { cursor: pointer; }

/* 山札・墓地 */
.pile { position: relative; width: var(--cw); height: var(--ch); flex: none; }
.pile.small { --w: calc(var(--cw) * .78); height: calc(var(--ch) * .78); display: grid; justify-items: center; }
.pile .card { position: absolute; top: 0; }
.pile .card.under { transform: translate(2px, 3px); }
.pile .empty { position: absolute; inset: 0; border-radius: calc(var(--cw) * .1); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .14); }
.pile .lbl { position: absolute; z-index: 3; left: 50%; top: -8px; transform: translateX(-50%); font-size: 10px; line-height: 1.4; padding: 0 6px; border-radius: 999px; background: var(--felt-lo); color: var(--ink-dim); white-space: nowrap; }
.pile .num { position: absolute; z-index: 3; right: -3px; bottom: 2px; font-size: 11px; font-weight: 800; line-height: 1.4; padding: 0 6px; border-radius: 999px; background: rgba(0, 0, 0, .8); }

/* 手札 */
.mhand-row { flex: none; justify-content: center; padding: 10px 0 max(6px, env(safe-area-inset-bottom)); }
.mhand { display: flex; justify-content: center; align-items: flex-end; width: 100%; min-height: var(--ch); }
.mhand .card { margin-left: var(--ov, 4px); cursor: pointer; touch-action: none; transition: transform .15s, margin .2s; }
.mhand .card:first-child { margin-left: 0; }
.mhand .card.sel { transform: translateY(-10px); z-index: 5; }
.mhand .card.can { box-shadow: 0 2px 5px rgba(0, 0, 0, .38), 0 0 0 2px rgba(94, 234, 212, .6); }
.mhand .empty-hand { color: var(--ink-dim); font-size: 12px; align-self: center; }
.ohand-row { justify-content: center; }
.ohand { display: flex; align-items: center; justify-content: center; min-height: calc(var(--ch) * .45); width: 100%; }
.ohand .card { --w: calc(var(--cw) * .45); margin-left: calc(var(--cw) * -.2); }
.ohand .card:first-child { margin-left: 0; }
.ohand .n { margin-left: 10px; font-size: 12px; color: var(--ink-dim); }

/* 真ん中（状況・案内・ログ） */
.mid {
  flex: 1 1 auto; min-height: 118px; display: flex; flex-direction: column; gap: 5px;
  margin: 8px -8px; padding: 6px 8px; background: rgba(0, 0, 0, .3); border-block: 1px solid var(--line);
}
.status { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; }
.status .turn { font-weight: 800; }
.status .who { font-weight: 800; padding: 1px 8px; border-radius: 999px; }
.who.me { background: var(--gold); color: #2a1d00; }
.who.op { background: var(--opp); color: #2b0707; }
.phases { display: flex; gap: 3px; list-style: none; margin: 0; padding: 0; }
.phases li { padding: 1px 7px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: var(--ink-dim); font-size: 11px; }
.phases li.on { background: #fff; color: #0b2a1b; font-weight: 800; }
.rights { margin-left: auto; font-size: 11px; color: var(--ink-dim); }
.rights b { color: var(--ink); }
.prompt { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; min-height: 40px; }
.prompt .msg { flex: 1 1 200px; margin: 0; font-size: 13px; line-height: 1.45; }
.prompt .msg b { color: var(--gold); }
.prompt .msg .warn { color: #ffb4b4; }
.prompt .btns { display: flex; flex-wrap: wrap; gap: 6px; }
.prompt .btn { font-size: 13px; padding: 6px 12px; min-height: 34px; }
.seg { display: inline-flex; border: 1.5px solid rgba(255, 255, 255, .35); border-radius: 999px; overflow: hidden; }
.seg button { font: inherit; font-size: 12.5px; font-weight: 700; color: var(--ink); background: transparent; border: 0; padding: 6px 10px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: #fff; color: #0b2a1b; }
.thinking::after { content: "…"; display: inline-block; animation: dots 1.2s steps(4) infinite; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }
.log { flex: 1 1 auto; min-height: 3em; overflow-y: auto; font-size: 11.5px; line-height: 1.5; color: var(--ink-dim); padding-right: 4px; overscroll-behavior: contain; }
.log div { padding: 0 0 1px; }
.log .turn { color: var(--gold); font-weight: 700; margin-top: 3px; }
.log .fx { color: #e6d6ff; }
.log .bt { color: #ffd9ad; }
.log .win { color: var(--gold); font-weight: 800; }
.log .mine { color: #cdeee0; }

/* 演出 */
.banner {
  position: absolute; left: 0; right: 0; top: 50%; z-index: 20; pointer-events: none; opacity: 0;
  text-align: center; padding: 12px 0; font-size: clamp(22px, 6vw, 38px); font-weight: 900; letter-spacing: .06em;
  color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, .6);
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .62) 18%, rgba(0, 0, 0, .62) 82%, transparent);
  transform: translateY(-50%);
}
.banner small { display: block; font-size: .45em; font-weight: 700; color: var(--gold); letter-spacing: .1em; }
.banner.show { animation: banner 1.1s ease both; }
@keyframes banner {
  0% { opacity: 0; transform: translateY(-50%) scale(.92); }
  15% { opacity: 1; transform: translateY(-50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}
.battle { position: absolute; inset: 0; z-index: 21; display: none; place-items: center; pointer-events: none; }
.battle.show { display: grid; animation: fadeio 1.8s ease both; }
@keyframes fadeio { 0% { opacity: 0; } 12% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }
.battle .box { --w: min(64px, calc(var(--cw) * 1.05)); display: grid; gap: 8px; justify-items: center; background: rgba(0, 0, 0, .78); border: 1px solid var(--line); border-radius: 16px; padding: 12px 18px; }
.battle .duel { display: flex; align-items: center; gap: 14px; }
.battle .side-b { display: grid; justify-items: center; gap: 4px; font-size: 12px; }
.battle .cards { display: flex; gap: 3px; }
.battle .val { font-size: 22px; font-weight: 900; }
.battle .vs { font-size: 20px; font-weight: 900; color: var(--gold); }
.battle .lost .cards { animation: lost .9s .5s ease both; }
@keyframes lost { to { filter: grayscale(1) brightness(.55); transform: rotate(-10deg) translateY(6px); } }
.battle .res { font-weight: 800; font-size: 14px; }
.in.enter { animation: enter .35s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(-12px) scale(.86); } }
.mhand .card.enter { animation: enterhand .3s ease-out; }
@keyframes enterhand { from { opacity: 0; transform: translateY(16px); } }

/* ゲーム内パネル */
.ov { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .55); }
.panel {
  width: min(560px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  padding: 16px; border-radius: 16px; background: linear-gradient(#134c33, #0a3020);
  border: 1.5px solid rgba(242, 193, 78, .55); box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.panel h2 { margin: 0 0 10px; font-size: 18px; color: var(--gold); }
.ov-body { font-size: 14px; line-height: 1.65; }
.ov-body p { margin: 6px 0; }
.panel .btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.cardgrid { --w: 50px; display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.cardgrid .pick { cursor: pointer; }
.cardgrid .pick:hover { transform: translateY(-2px); }
.cardgrid.big { --w: 64px; justify-content: center; }
.note { font-size: 12.5px; color: var(--ink-dim); }
.bigres { text-align: center; font-size: 34px; font-weight: 900; color: var(--gold); margin: 6px 0; }
.bigres.lose { color: #ffb4b4; }
.code { text-align: center; font-size: 40px; font-weight: 900; letter-spacing: .18em; color: var(--gold); margin: 8px 0; }
.inp {
  font: inherit; font-size: 24px; letter-spacing: .25em; text-align: center; width: 100%; padding: 10px;
  color: var(--ink); background: rgba(0, 0, 0, .3); border: 1.5px solid rgba(255, 255, 255, .35); border-radius: 12px;
}
.inp:focus { outline: 2px solid var(--gold); }
.stack-list { display: grid; gap: 8px; }
.split { display: grid; gap: 10px; }
.split .btn { width: 100%; }
.err { color: #ffb4b4; }
.rules .lead { font-weight: 700; }
.rules h3 { font-size: 15px; color: var(--gold); margin: 16px 0 6px; }
.rules ul, .rules ol { padding-left: 1.3em; margin: 4px 0; }
.rules li { margin: 3px 0; }
.rules .small { font-size: 12.5px; color: var(--ink-dim); }
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 60; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 8px 16px; border-radius: 999px; text-align: center; font-size: 13px;
  background: rgba(8, 22, 15, .94); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  opacity: 0; transform: translate(-50%, 16px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.ghost-card { position: fixed; z-index: 70; pointer-events: none; transform: translate(-50%, -60%) rotate(-5deg); opacity: .92; }

@media (min-width: 700px) {
  .prompt .msg { font-size: 14px; }
  .log { font-size: 12.5px; }
  .status { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
