:root {
  --gold: #d9b45a; --gold-dim: #8c7233; --ink: #f3e7cf; --bg: #150d07; --panel: rgba(24, 14, 8, .92);
  --good: #5fd078; --bad: #e8574f;
  font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }
#board { position: relative; background: #2a1a0f url(../assets/board.jpg) center / 100% 100% no-repeat; box-shadow: 0 0 40px #000; flex: none; container-type: normal; }

/* ------------------------------------------------------------- cards */
.card { position: relative; aspect-ratio: 410 / 775; flex: none; border-radius: 6% / 3.2%; background: #000; }
.card img { width: 100%; height: 100%; display: block; pointer-events: none; border-radius: inherit; }
.card.back { background: #222; }
.card .str { position: absolute; left: 1%; top: 1%; width: 31%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: calc(var(--cw, 40px) * .26); background: #ece6d6; color: #111; border: 2px solid var(--gold); line-height: 1; }
.card .str.buff { color: #0b7a24; } .card .str.nerf { color: #b4231c; }
.card.noimg { background: linear-gradient(160deg, color-mix(in srgb, var(--fc) 70%, #000), #1b1209); border: 1px solid var(--gold-dim); overflow: hidden; }
.card .ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 6% 5%; text-align: center; font-size: calc(var(--cw, 40px) * .13); line-height: 1.1; gap: 4%; }
.card .ph b { position: absolute; left: 6%; top: 3%; font-size: calc(var(--cw, 40px) * .42); }
.card .ph i { opacity: .7; font-size: .85em; }
.card.target { outline: 2px solid var(--gold); box-shadow: 0 0 12px var(--gold); cursor: pointer; animation: pulse 1s infinite alternate; }
.card.enter { animation: enter .35s ease-out; }
@keyframes enter { from { transform: scale(1.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse { to { box-shadow: 0 0 22px var(--gold); } }

/* ------------------------------------------------------------- board parts */
.row { position: absolute; left: 27.65%; width: 56.35%; border-radius: 6px; }
.row .slot { position: absolute; left: 36%; top: 0; width: 62%; height: 100%; display: flex; align-items: center; justify-content: center; }
.row .rcards { position: absolute; left: 14.3%; width: 85.7%; top: 4%; height: 92%; display: flex; align-items: center; justify-content: center; }
.row .rcards .card { height: 100%; }
.rbadge { position: absolute; left: 2.2%; top: 50%; transform: translateY(-50%); width: calc(var(--u) * 3.1); height: calc(var(--u) * 3.1); border-radius: 50%; background: radial-gradient(#3a2a1a, #1a0f08); border: 2px solid var(--gold-dim); display: grid; place-items: center; font-size: calc(var(--u) * 1.5); font-weight: 700; color: var(--ink); z-index: 2; box-shadow: 0 2px 6px #000a; }
.rbadge.hi { border-color: var(--gold); color: #fff3c4; }
.hornmark { color: var(--gold); font-weight: 700; font-size: calc(var(--u) * 1.5); text-shadow: 0 0 8px #000; }
.slot .card { height: 82%; }
.row.target { outline: 2px solid var(--gold); background: rgba(217, 180, 90, .13); cursor: pointer; animation: pulse 1s infinite alternate; }
.row.w-close::after, .row.w-ranged::after, .row.w-siege::after { content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: 6px; }
.row.w-close::after { background: linear-gradient(90deg, rgba(150, 210, 255, .35), rgba(150, 210, 255, .12)); box-shadow: inset 0 0 18px rgba(170, 225, 255, .7); }
.row.w-ranged::after { background: linear-gradient(90deg, rgba(210, 215, 220, .38), rgba(210, 215, 220, .14)); box-shadow: inset 0 0 18px rgba(230, 235, 240, .6); }
.row.w-siege::after { background: linear-gradient(90deg, rgba(70, 110, 190, .42), rgba(70, 110, 190, .15)); box-shadow: inset 0 0 18px rgba(100, 140, 220, .7); }

.pile { position: absolute; display: flex; align-items: center; justify-content: center; }
.pile .card { height: 94%; }
.pile .count { position: absolute; right: -4%; bottom: 2%; min-width: calc(var(--u) * 2); padding: 0 6px; height: calc(var(--u) * 2); border-radius: 99px; background: #000c; border: 1px solid var(--gold-dim); display: grid; place-items: center; font-size: calc(var(--u) * 1.15); }
.pile.grave { cursor: pointer; }
.pile .card.used { filter: grayscale(.9) brightness(.55); }
.pile.leader.ready .card { outline: 2px solid var(--gold); box-shadow: 0 0 16px var(--gold); animation: pulse 1s infinite alternate; cursor: pointer; }
.weatherbox { position: absolute; display: flex; align-items: center; justify-content: center; gap: 2%; padding: 1%; border-radius: 6px; }
.weatherbox .card { height: 90%; }
.weatherbox.target { outline: 2px solid var(--gold); cursor: pointer; animation: pulse 1s infinite alternate; }

.info { position: absolute; left: 1.2%; width: 24%; font-size: calc(var(--u) * 1.35); text-shadow: 0 1px 4px #000, 0 0 10px #000; line-height: 1.35; }
.info .fn { font-weight: 700; color: var(--gold); }
.info .gem { display: inline-block; width: calc(var(--u) * 1.2); height: calc(var(--u) * 1.2); border-radius: 50%; margin-right: 4px; vertical-align: -2px; background: radial-gradient(#ff8f8f, #a31515); box-shadow: 0 0 6px #f55; }
.info .gem.off { background: #2b1b12; box-shadow: none; border: 1px solid #5a432b; }
.info .tag { display: inline-block; padding: 0 8px; border-radius: 99px; background: #000a; border: 1px solid var(--gold-dim); font-size: .85em; margin-left: 6px; }
.info.turn .fn::after { content: ' ◀'; color: var(--gold); }
.total { position: absolute; width: calc(var(--u) * 6); height: calc(var(--u) * 6); border-radius: 50%; transform: translate(-50%, -50%); background: radial-gradient(#4a3420, #1a0f08); border: 3px solid var(--gold); display: grid; place-items: center; font-size: calc(var(--u) * 3.2); font-weight: 700; box-shadow: 0 0 16px #000; }
.total.lead { color: #fff1b8; box-shadow: 0 0 18px rgba(217, 180, 90, .8); }

/* ------------------------------------------------------------- hand bar */
#handbar { flex: none; height: 21vh; min-height: 84px; display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: linear-gradient(#1c1109, #0c0704); border-top: 2px solid var(--gold-dim); }
#hand { flex: 1; height: 100%; display: flex; align-items: center; justify-content: center; min-width: 0; padding-top: 6px; }
#hand .card { height: 92%; cursor: pointer; transition: transform .12s; }
#hand .card.sel { transform: translateY(-14%); outline: 2px solid var(--gold); box-shadow: 0 0 14px var(--gold); z-index: 5; }
#hand .card:hover { transform: translateY(-8%); z-index: 4; }
#hud-right { display: flex; flex-direction: column; gap: 8px; }

.btn { font: inherit; color: var(--ink); background: linear-gradient(#5a3d1e, #2f1e0e); border: 2px solid var(--gold-dim); border-radius: 10px; padding: 8px 16px; cursor: pointer; font-weight: 700; letter-spacing: .03em; }
.btn:hover:not(:disabled) { border-color: var(--gold); background: linear-gradient(#6d4a25, #3a2512); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.big { min-width: 76px; padding: 14px 10px; font-size: 1.1em; }
.btn.small { padding: 6px 12px; font-size: .85em; }
.btn.primary { background: linear-gradient(#b8912f, #7a5c16); color: #1b1006; border-color: #f0d27c; }

/* ------------------------------------------------------------- preview, toast, banner */
#preview { position: fixed; left: 1.5vw; top: 8px; z-index: 20; display: none; pointer-events: none; flex-direction: column; align-items: center; gap: 8px; width: min(26vh, 22vw); }
#preview.show { display: flex; }
#preview .card { width: 100%; box-shadow: 0 10px 40px #000; }
#preview .pdesc { background: var(--panel); border: 1px solid var(--gold-dim); border-radius: 8px; padding: 6px 8px; font-size: clamp(11px, 1.7vh, 15px); line-height: 1.3; text-align: center; }
#toast { position: fixed; left: 50%; bottom: calc(21vh + 14px); transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: var(--panel); border: 1px solid var(--gold-dim); padding: 7px 16px; border-radius: 99px; font-size: clamp(12px, 2.2vh, 17px); animation: toast 2.4s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#banner { position: fixed; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; flex-direction: column; pointer-events: none; background: radial-gradient(#000a, #0000 70%); }
#banner.show { display: flex; animation: banner 2.1s forwards; }
#banner b { font-size: clamp(28px, 9vh, 80px); color: var(--gold); text-shadow: 0 4px 24px #000; letter-spacing: .06em; }
#banner span { font-size: clamp(16px, 4vh, 34px); text-shadow: 0 2px 12px #000; }
@keyframes banner { 0% { opacity: 0; transform: scale(.85); } 12%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ------------------------------------------------------------- modals */
.overlay { position: fixed; inset: 0; z-index: 50; background: #000b; display: flex; align-items: center; justify-content: center; padding: 10px; }
.dialog { background: var(--panel); border: 2px solid var(--gold-dim); border-radius: 14px; padding: 16px 20px; max-width: min(1000px, 96vw); max-height: 94vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 60px #000; }
.dialog h1 { margin: 0; font-size: clamp(20px, 4vh, 32px); color: var(--gold); text-align: center; letter-spacing: .08em; }
.dialog h2 { margin: 0; font-size: clamp(14px, 2.6vh, 20px); color: var(--gold); }
.dialog p { margin: 0; line-height: 1.4; font-size: clamp(13px, 2.3vh, 17px); }
.dialog .row2 { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.dialog .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.choice { cursor: pointer; border: 2px solid var(--gold-dim); border-radius: 10px; padding: 8px 12px; background: #0006; text-align: left; font: inherit; color: var(--ink); }
.choice.on { border-color: var(--gold); background: rgba(217, 180, 90, .2); box-shadow: 0 0 10px rgba(217, 180, 90, .5); }
.choice small { display: block; opacity: .75; margin-top: 2px; }
.fchoice { display: flex; flex-direction: column; align-items: center; gap: 6px; width: clamp(80px, 18vh, 140px); text-align: center; }
.fchoice .card { width: 55%; }
.fchoice span { font-size: clamp(11px, 2vh, 15px); }
.cardlist { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-height: 56vh; overflow: auto; padding: 6px; }
.mcard { cursor: pointer; border-radius: 8px; padding: 3px; border: 2px solid transparent; }
.mcard .card { width: clamp(54px, 12vh, 104px); }
.mcard.on { border-color: var(--gold); background: rgba(217, 180, 90, .25); }
.rules { max-height: 60vh; overflow: auto; font-size: clamp(12px, 2.1vh, 16px); line-height: 1.45; padding-right: 8px; }
.rules li { margin-bottom: 4px; }
.resulttable { border-collapse: collapse; margin: 0 auto; font-size: clamp(13px, 2.4vh, 18px); }
.resulttable td, .resulttable th { padding: 3px 14px; text-align: center; border-bottom: 1px solid #fff2; }

#rotate { display: none; position: fixed; inset: 0; z-index: 100; background: var(--bg); align-items: center; justify-content: center; text-align: center; font-size: 22px; }
@media (orientation: portrait) and (max-width: 800px) { #rotate { display: flex; } }

.leadergrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.leadergrid .choice { font-size: clamp(12px, 2.1vh, 16px); }
.leadergrid .choice small { font-size: .82em; }
.dialog .actions.sticky, .dialog > .actions:last-child { position: sticky; bottom: -16px; background: var(--panel); padding: 8px 0 4px; margin-top: 4px; }
.fchoice { width: clamp(90px, 20vh, 150px); }
@media (max-height: 520px) { .fchoice .card { width: 38%; } .dialog { padding: 10px 14px; gap: 8px; } }

@media (max-height: 520px) {
  #preview { width: min(30vh, 20vw); }
  #preview .pdesc { font-size: 10px; padding: 4px 6px; }
  .fchoice span { font-size: 10px; }
  .dialog h1 { font-size: 20px; } .dialog h2 { font-size: 14px; }
  .btn.big { min-width: 64px; }
}
