:root {
  --ink: #1b1222;
  --sea: #0b2f52;
  --sea2: #124271;
  --paper: #f4e4c1;
  --paper2: #e8d2a2;
  --wood: #7a4524;
  --gold: #ffcf4a;
  --text: #2a1a12;
  --muted: #7a6450;
  --ok: #5fd35f;
  --bad: #ff5a5a;
  --boss: #c65bd6;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sea);
  color: var(--paper);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; align-items: center;
  overflow: hidden;
}
#hud { width: 100%; max-width: 1280px; padding: 6px 10px 4px; display: flex; flex-direction: column; gap: 4px; }
.hud-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hud-row.sub { font-size: 13px; color: #cfe3ff; gap: 14px; min-height: 26px; }
.hud-row.actions { justify-content: center; }
.spacer { flex: 1; }
.pill { background: var(--ink); border-radius: 999px; padding: 3px 10px; font-weight: 700; white-space: nowrap; }
.pill.gold { color: var(--gold); }
.pill.on { color: var(--ok); }
.pill.off { color: #9aa7b8; }
.chest { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.chest-bar { width: 110px; height: 10px; background: var(--ink); border-radius: 3px; overflow: hidden; border: 1px solid #000; display: flex; }
.chest-fill { height: 100%; background: linear-gradient(90deg, #d79b2a, var(--gold)); flex: none; }
.chest-pend { height: 100%; flex: none; background: repeating-linear-gradient(90deg, rgba(255, 207, 74, 0.45) 0 3px, transparent 3px 5px); }
.pend { color: var(--gold); opacity: 0.85; font-size: 12px; white-space: nowrap; }
.chest-fill.full { background: var(--bad); animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
#stage { flex: 1; display: flex; align-items: flex-start; justify-content: center; width: 100%; min-height: 0; }
#deck { image-rendering: pixelated; image-rendering: crisp-edges; display: block; border: 3px solid var(--ink); border-radius: 6px; box-shadow: 0 6px 0 #061a2e; max-width: 100%; }
.btn {
  font: inherit; font-weight: 800; cursor: pointer; color: var(--text);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 6px;
  padding: 7px 14px; box-shadow: 0 3px 0 var(--ink); transition: transform 0.05s;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 3px 9px; font-size: 13px; box-shadow: 0 2px 0 var(--ink); }
.btn.info { font: italic 700 13px Georgia, serif; min-width: 26px; padding: 2px 8px; border-radius: 50%; }
.btn.ghost { background: var(--paper2); }
.btn.gold { background: var(--gold); }
.btn.map { background: #9fe0c9; }
.btn.boss { background: var(--boss); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { filter: brightness(1.25); } }
.btn.big { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 14px; text-align: left; }
.btn.big small { font-weight: 600; font-size: 12px; color: var(--muted); }
.big-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 10px 0; }
#tabs { width: 100%; display: flex; justify-content: center; gap: 2px; background: var(--ink); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); z-index: 5; }
.tab { flex: 1; max-width: 130px; display: flex; flex-direction: column; align-items: center; gap: 1px; background: transparent; border: 0; color: #cfe3ff; font: inherit; font-size: 12px; padding: 4px 2px; border-radius: 6px; cursor: pointer; }
.tab .ico { font-size: 18px; }
.tab.active { background: var(--sea2); color: var(--gold); }
#panel {
  position: fixed; left: 50%; transform: translate(-50%, 110%); bottom: 58px; width: min(760px, 100%);
  max-height: 62vh; overflow-y: auto; background: var(--paper); color: var(--text);
  border: 3px solid var(--ink); border-bottom: 0; border-radius: 10px 10px 0 0; padding: 10px 14px 18px;
  transition: transform 0.18s ease-out, visibility 0s linear 0.18s; z-index: 4; box-shadow: 0 -6px 0 rgba(0,0,0,0.25);
  visibility: hidden; 
}
#panel.open { transform: translate(-50%, 0); visibility: visible; transition: transform 0.18s ease-out; }
.panel-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -10px; background: var(--paper); padding: 4px 0; z-index: 1; }
.panel-head h2 { margin: 0; font-size: 20px; }
h3 { margin: 14px 0 6px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.summary { font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
.small { font-size: 12px; }
.empty { color: var(--muted); font-style: italic; }
.member { border-bottom: 1px solid var(--paper2); padding: 6px 0; }
.card-line { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.rank-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rank); box-shadow: 0 0 0 1px rgba(27, 18, 34, 0.35); flex: none; }
.rank-tag { display: inline-block; background: var(--rank); color: var(--ink); font-weight: 800; font-size: 12px; line-height: 1.3; padding: 0 6px; border-radius: 4px; border: 1px solid var(--ink); }
.row-btns { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-btns.center { justify-content: center; margin-top: 14px; }
.member-sub { display: flex; align-items: center; gap: 8px; margin: 3px 0 0 20px; flex-wrap: wrap; }
.place { font-size: 12px; font-weight: 800; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--ink); }
.place.arena { background: #ffd0a6; } .place.ready { background: #bff0bf; } .place.forge { background: #ffe08a; } .place.tavern { background: #d9c7a5; }
.dur { position: relative; width: 90px; height: 12px; background: var(--ink); border-radius: 3px; overflow: hidden; }
.dur span { position: absolute; inset: 0; font-size: 9px; color: #fff; text-align: center; line-height: 12px; font-weight: 700; text-shadow: 0 1px 0 #000, 0 0 2px #000, 0 0 2px #000; }
.dur-fill { height: 100%; } .dur-fill.ok { background: var(--ok); } .dur-fill.mid { background: var(--gold); } .dur-fill.low { background: var(--bad); }
.detail { margin: 6px 0 4px 20px; padding: 8px; background: var(--paper2); border-radius: 6px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.pity { margin: 8px 0; display: block; width: 100%; text-align: left; background: none; border: 0; padding: 2px 0; font: inherit; color: inherit; cursor: pointer; }
.pity:hover .pity-label { text-decoration: underline; }
.pity-label { font-size: 13px; font-weight: 700; }
.pity-bar { height: 8px; background: var(--paper2); border: 1px solid var(--ink); border-radius: 4px; overflow: hidden; }
.pity-bar div { height: 100%; background: linear-gradient(90deg, #b06bff, #ff9f2e); }
.odds { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px 16px; }
.odds-row { display: flex; align-items: center; gap: 6px; }
.fuse-box { background: var(--paper2); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 30px; z-index: 1; }
.keep { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-weight: 700; }
.keep .btn.chosen { outline: 2px solid var(--ink); outline-offset: 1px; }
.confirm { background: #fff3cf; border: 2px solid var(--ink); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
.confirm p { margin: 0 0 6px; font-size: 13px; }
.pick { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.pick.on { background: #ffe9a8; } .pick.off { opacity: 0.4; }
.shop { background: var(--paper2); border-radius: 8px; padding: 6px 12px 12px; margin: 10px 0; }
.shop p { margin: 4px 0 8px; }
.sell { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.input { font: inherit; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 6px; background: #fffaf0; color: var(--text); flex: 1; min-width: 140px; }
.log { font-size: 13px; padding: 2px 0; }
.prev { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
#overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(5, 15, 30, 0.82); z-index: 10; padding: 16px; }
#overlay.open { display: flex; }
.reveal { text-align: center; max-width: 820px; width: 100%; }
.reveal h2 { color: var(--gold); text-shadow: 0 2px 0 var(--ink); }
.reveal-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.reveal-grid.n1 { grid-template-columns: minmax(0, 200px); justify-content: center; }

.poster { position: relative; height: 196px; }
.poster-roll { position: absolute; inset: 22px 6px; background: linear-gradient(90deg, #a77b3f, #f0dcae 28%, #e3c58e 72%, #a77b3f); border: 2px solid var(--ink); border-radius: 12px; display: flex; align-items: center; justify-content: center; transition: transform 0.2s, opacity 0.2s; }
.poster-roll .seal { width: 26px; height: 26px; border-radius: 50%; background: #a01d1d; box-shadow: inset 0 0 0 4px #741010; border: 2px solid var(--ink); }
.poster-face { position: absolute; inset: 0; background: #f2dfb3; border: 3px solid var(--ink); border-radius: 4px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text); transform: scaleY(0.05); opacity: 0; transition: transform 0.22s ease-out, opacity 0.15s; box-shadow: inset 0 0 0 2px #d9bf86; }
.poster.open .poster-roll { opacity: 0; transform: scaleY(0.2); }
.poster.open .poster-face { transform: none; opacity: 1; }
.poster-head { font-family: Georgia, "Times New Roman", serif; font-weight: 900; letter-spacing: 2px; font-size: 16px; color: #3a2414; }
.poster-portrait { width: 48px; height: 48px; image-rendering: pixelated; background: #e6cf9c; border: 2px solid #6b4a2a; filter: brightness(0) opacity(0.7); transition: filter 0.25s; }
.poster.stamped .poster-portrait { filter: none; }
.poster-class { font-size: 12px; font-weight: 800; }
.poster-bounty { display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.poster-bounty small { font-size: 9px; letter-spacing: 1px; font-weight: 800; color: #6b4a2a; }
.poster-bounty .num { font-family: Georgia, "Times New Roman", serif; font-size: 16px; font-variant-numeric: tabular-nums; }
.poster-stamp { margin: 3px 0 1px; transform: rotate(-8deg) scale(2.2); opacity: 0; border: 3px solid var(--rank); color: var(--rank); background: rgba(255, 250, 235, 0.7); font-weight: 900; font-size: 14px; letter-spacing: 1px; padding: 1px 6px; border-radius: 4px; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); pointer-events: none; transition: transform 0.16s cubic-bezier(0.2, 1.6, 0.4, 1), opacity 0.1s; }
.poster.stamped .poster-stamp { opacity: 1; transform: rotate(-8deg) scale(1); }
.poster-rate { font-size: 10px; color: var(--muted); margin-top: auto; }
.poster.strong.stamped .poster-face { box-shadow: inset 0 0 0 2px #d9bf86, 0 0 0 3px var(--rank), 0 0 22px var(--rank); animation: poster-shake 0.25s; }
@keyframes poster-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.chip { font: inherit; font-size: 13px; font-weight: 700; color: var(--gold); background: rgba(0, 0, 0, 0.3); border: 1px solid var(--ink); border-radius: 999px; padding: 1px 9px; cursor: pointer; }
.bounty { font-size: 12px; font-weight: 700; color: #7a4a10; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.bounty .mult { font-size: 11px; padding: 0 5px; border-radius: 8px; background: #f3e2c0; color: #7a4a10; }
.bounty .mult.full { background: #7a4a10; color: #fff3d6; }
.bounty-bar { display: inline-block; width: 56px; height: 5px; border-radius: 3px; background: #e9d8b6; overflow: hidden; }
.bounty-bar > span { display: block; height: 100%; background: #c98a2b; }
.ranks { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; }
.ranks li { display: flex; gap: 8px; align-items: center; background: var(--paper2); border-radius: 6px; padding: 6px 10px; }
.ranks li.me { background: #ffe9a8; outline: 2px solid var(--ink); }
.ranks .r { font-weight: 900; width: 36px; }
#toasts { position: fixed; bottom: calc(var(--tabs-h, 56px) + 10px); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 20; pointer-events: none; width: min(420px, 92vw); }
.toast { background: var(--ink); color: var(--paper); border: 2px solid var(--gold); padding: 7px 12px; border-radius: 8px; font-weight: 700; font-size: 14px; animation: in 0.2s ease-out; }
.toast.err { border-color: var(--bad); }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }
@media (max-width: 640px) {
  .reveal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .poster { height: 172px; }
  .poster-head { font-size: 13px; letter-spacing: 1px; }
  .poster-portrait { width: 40px; height: 40px; }
  .poster-class { font-size: 11px; }
  .poster-bounty .num { font-size: 14px; }
  .poster-stamp { font-size: 11px; padding: 0 4px; }
  .poster-rate { display: none; }
  .reveal h2 { margin: 4px 0 8px; font-size: 20px; }
  #overlay { align-items: flex-start; overflow-y: auto; padding: 12px; background: rgba(5, 15, 30, 0.95); }
  
  .reveal { display: flex; flex-direction: column; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); }
  .reveal-grid { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 2px; }
  .reveal-btns { flex: none; margin-top: 8px; }
  .chest-bar { width: 70px; }
  #panel { max-height: 70vh; }
}
@media (prefers-reduced-motion: reduce) {
  .btn.boss, .chest-fill.full { animation: none; }
  .poster-face, .poster-roll, .poster-stamp, .poster-portrait { transition: none; }
  .poster.strong.stamped .poster-face { animation: none; }
}
.goal { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,0.35); border: 2px solid var(--ink); border-radius: 8px; color: var(--paper); font: inherit; font-size: 13px; font-weight: 700; padding: 5px 10px; cursor: pointer; }
.goal:hover { background: rgba(0,0,0,0.5); }
.goal-bar { width: 80px; height: 8px; background: var(--ink); border-radius: 4px; overflow: hidden; display: inline-block; }
.goal-bar span { display: block; height: 100%; background: var(--gold); }
.goal-num { color: var(--gold); font-variant-numeric: tabular-nums; }
.welcome { background: var(--paper); color: var(--text); border: 3px solid var(--ink); border-radius: 12px; padding: 16px 20px; max-width: 460px; width: 100%; text-align: center; box-shadow: 0 6px 0 var(--ink); }
.welcome h2 { margin: 0 0 6px; }
.welcome-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.welcome-grid div { background: var(--paper2); border-radius: 8px; padding: 8px 4px; display: flex; flex-direction: column; }
.welcome-grid b { font-size: 18px; }
.welcome-grid small { color: var(--muted); }
.warn { color: #a3361f; font-weight: 700; }
#credit { position: fixed; right: 8px; bottom: 62px; font-size: 10px; color: #9fb6d6; z-index: 3; pointer-events: none; }
.btn.big.gift { width: 100%; margin-top: 10px; background: linear-gradient(90deg, #ffe08a, var(--gold)); animation: pulse 1.6s infinite; }
.steps { text-align: left; margin: 10px 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  #hud { padding: 4px 6px 2px; gap: 3px; }
  .hud-row { gap: 6px; }
  .hud-row.sub { font-size: 12px; gap: 10px; }
  .pill { padding: 2px 8px; font-size: 13px; }
  .chest { font-size: 12px; }
  .btn { padding: 5px 10px; }
  .goal { font-size: 12px; padding: 4px 8px; }
  .goal-bar { width: 50px; }
  .chest-bar { width: 48px; }
  .hud-row .spacer { flex: 0 0 0; }
  
  .btn, .btn.small { min-height: 40px; }
  .goal { min-height: 40px; }
  .hud-row.sub .chip { min-height: 40px; min-width: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .hud-row:first-child { flex-wrap: nowrap; }
  .chest { min-width: 0; flex: 1 1 auto; }
  .pend { overflow: hidden; text-overflow: ellipsis; }
}


.coach { animation: coach 1.4s ease-in-out infinite; }
@keyframes coach { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 211, 77, 0.9); } 50% { box-shadow: 0 0 0 6px rgba(255, 211, 77, 0); } }
@media (prefers-reduced-motion: reduce) { .coach { animation: none; outline: 2px solid var(--gold); } }
.log-list { list-style: none; padding: 0; margin: 10px 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.log-list li { display: flex; align-items: center; gap: 8px; }
.log-list li.done { opacity: 0.6; }
.log-list .tick { width: 18px; text-align: center; color: var(--gold); font-weight: 700; }

.chip.flag { background: #7a1f1f; color: #ffe08a; }
.name-box .sell { justify-content: center; margin: 10px 0 4px; }
.name-box .input { max-width: 260px; text-align: center; font-weight: 700; }
