:root {
  --bg: #14121a;
  --bg2: #1f1b2b;
  --panel: #262135;
  --line: #3a3350;
  --text: #f1eef8;
  --muted: #a9a2bf;
  --pink: #ff2d95;
  --cyan: #35d0ff;
  --green: #3ddc84;
  --orange: #ff9f2d;
  --red: #ff4b4b;
  --cw: min(calc((100vw - 16px) / 3), 150px);
  --ch: calc(var(--cw) * 1.389);
  --ew: calc(var(--cw) * 0.5);
  --eh: calc(var(--ew) * 1.389);
  --hand-h: 158px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { height: 100dvh; display: flex; flex-direction: column; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer; }
button:disabled { opacity: .4; }
button.primary { background: var(--pink); border-color: var(--pink); color: #fff; font-weight: 700; }
button.secondary { background: transparent; }
input { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input#code { text-transform: uppercase; letter-spacing: .3em; font-size: 22px; text-align: center; font-weight: 700; }
[hidden] { display: none !important; }

.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.lobby-box { margin: auto; width: min(100%, 440px); padding: 24px 18px; display: flex; flex-direction: column; gap: 14px; padding-top: max(24px, env(safe-area-inset-top)); }
.lobby-box.wide { width: min(100%, 560px); margin-top: 0; }
.lobby-box h1 { margin: 0 0 6px; font-size: 34px; letter-spacing: .08em; color: var(--pink); text-align: center; font-style: italic; }
.lobby-box h2 { margin: 0 0 6px; font-size: 16px; color: var(--cyan); }
.lobby-box label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.lobby-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
label.radio { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.radio input { width: auto; }
.hint { color: var(--muted); text-align: center; margin: 0; font-size: 13px; }
.code-big { font-size: 46px; font-weight: 800; letter-spacing: .25em; text-align: center; color: var(--cyan); background: var(--panel); border-radius: 14px; padding: 14px; }

.camp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.camp-grid .pick { position: relative; border-radius: 8px; overflow: hidden; border: 3px solid transparent; }
.camp-grid .pick img { display: block; width: 100%; }
.camp-grid .pick.sel { border-color: var(--green); }
.camp-grid .pick.sel::after { content: "✓"; position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--green); color: #062; font-weight: 800; font-size: 14px; display: flex; align-items: center; justify-content: center; }
img { -webkit-touch-callout: none; -webkit-user-drag: none; }
#zoom { position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,.92); display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; padding: 12px; }
#zoom .zoom-hint { color: var(--muted); font-size: 12px; }
#zoom img { max-width: 96vw; max-height: 92dvh; width: auto; height: auto; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.8); }

/* ---------- game ---------- */
#screen-game { position: relative; }
#topbar { display: flex; align-items: center; gap: 4px; padding: 3px 6px; padding-top: max(3px, env(safe-area-inset-top)); background: var(--bg2); border-bottom: 1px solid var(--line); flex: none; }
#topbar .tb { padding: 3px 8px; font-size: 12px; border-radius: 7px; line-height: 1.2; }
#turn-info { flex: 1; text-align: center; font-weight: 700; font-size: 12px; line-height: 1.2; }
#turn-info.mine { color: var(--green); }
#turn-info.theirs { color: var(--orange); }

#table { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; padding: 6px 4px 22px; scroll-behavior: auto; }
.side { display: flex; flex-direction: column; gap: 4px; }
.side.opp { transform: none; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); padding: 2px 4px; }
.side-head b { color: var(--text); }
.side-head .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 4px; }
.side-head .dot.on { background: var(--green); }
.row3 { display: grid; grid-template-columns: repeat(3, var(--cw)); justify-content: center; gap: 4px; }
.row-label { font-size: 10px; color: var(--muted); text-align: center; letter-spacing: .1em; text-transform: uppercase; }
.slot { width: var(--cw); height: var(--ch); border-radius: 7px; border: 1.5px dashed var(--line); position: relative; display: flex; align-items: center; justify-content: center; }
.slot.camp-slot { border-style: solid; border-color: transparent; }
.slot.over { border-color: var(--green); background: rgba(61,220,132,.15); }
.slot .slot-hint { font-size: 10px; color: var(--line); }

.card { width: 100%; height: 100%; position: relative; border-radius: 7px; }
.card img.face { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 7px; transition: transform .18s; }
.card.damaged img.face { transform: rotate(90deg) scale(.72); }
.card.unprot::after { display: none; }
.card.destroyed { opacity: .85; }
.card.over { outline: 3px solid var(--cyan); }
.card .nr { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.card .nr img { width: calc(var(--cw) * 0.34); filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); }
.card .nr span { font-size: 9px; font-weight: 800; letter-spacing: .06em; color: #fff; background: rgba(0,0,0,.7); padding: 1px 5px; border-radius: 6px; white-space: nowrap; }
.eslot .card .nr span { display: none; }
.eslot .card .nr img { width: calc(var(--ew) * 0.4); }
.card .waters { position: absolute; top: 3px; right: 3px; display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.drop { width: 26px; height: 26px; touch-action: none; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.card .drop { width: 24px; height: 24px; }
.card .badge { position: absolute; left: 3px; bottom: 3px; background: var(--pink); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 8px; }
.card .punk-badge { position: absolute; left: 3px; top: 3px; background: rgba(0,0,0,.65); color: #fff; font-size: 9px; padding: 1px 4px; border-radius: 6px; }

.events-row { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.eslot { width: var(--ew); height: var(--eh); border: 1.5px dashed var(--line); border-radius: 6px; position: relative; display: flex; align-items: center; justify-content: center; }
.eslot .qn { position: absolute; width: 22px; opacity: .6; pointer-events: none; }
.eslot .card .drop { width: 18px; height: 18px; }
.eslot.over, .ezone.over { border-color: var(--green); background: rgba(61,220,132,.15); }
.ezone { display: flex; gap: 6px; padding: 4px; border-radius: 8px; border: 1.5px dashed transparent; }
.mini { width: var(--ew); height: var(--eh); border-radius: 6px; }
.mini img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; display: block; }
.mini.ghosted { opacity: .25; }
.sep { color: var(--line); font-size: 18px; padding: 0 2px; }

.center { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 0; margin: 6px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.pile { width: var(--ew); height: var(--eh); border-radius: 6px; position: relative; background: var(--panel); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; flex-direction: column; font-size: 11px; color: var(--muted); }
.pile img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.pile .cnt { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; font-size: 11px; color: var(--text); }
.pile.deck { background: linear-gradient(135deg, #ff2d95, #6a2bd9); color: #fff; font-weight: 800; letter-spacing: .05em; }
.pile.deck span.t { font-size: 10px; }
.zone { min-width: 64px; min-height: var(--eh); border: 1.5px dashed var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 3px; padding: 4px; font-size: 10px; color: var(--muted); text-align: center; }
.zone.over { border-color: var(--green); background: rgba(61,220,132,.15); }
.zone .lbl { width: 100%; }
.zone .mini-punk { width: 26px; height: 36px; object-fit: cover; border-radius: 3px; }

.supply { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 120px; min-height: 44px; padding: 5px 8px; border: 1.5px dashed var(--line); border-radius: 10px; }
.supply.over { border-color: var(--green); background: rgba(61,220,132,.15); }
.supply .lbl { font-size: 10px; color: var(--muted); margin-right: 2px; }
.supply .drop { width: 30px; height: 30px; }
.opp-hand { display: flex; align-items: center; gap: 6px; }
.opp-hand .back { width: 22px; height: 30px; border-radius: 3px; background: linear-gradient(135deg, #ff2d95, #6a2bd9); margin-left: -12px; border: 1px solid #000; }
.opp-hand .back:first-child { margin-left: 0; }

#hand-area { flex: none; background: var(--bg2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#actionbar { display: flex; gap: 6px; padding: 6px 6px 2px; align-items: stretch; }
#actionbar .supply { flex: 1 1 auto; min-width: 0; min-height: 40px; padding: 3px 6px; gap: 3px; }
#actionbar .supply .drop { width: 28px; height: 28px; }
#actionbar .zone.spent { flex: 0 0 auto; min-width: 56px; min-height: 40px; padding: 2px 4px; gap: 2px; }
#actionbar .zone.spent .drop { width: 22px; height: 22px; }
#actionbar .zone.spent .lbl { width: 100%; font-size: 9px; }
#actionbar button { flex: 0 0 auto; padding: 7px 10px; font-size: 13px; white-space: nowrap; }
#actionbar button.end { background: var(--green); border-color: var(--green); color: #062; font-weight: 700; }
#hand { display: flex; gap: 6px; padding: 4px 8px 8px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; height: 132px; align-items: flex-end; }
#hand:empty::before { content: "Your hand is empty"; color: var(--muted); font-size: 12px; margin: auto; }
.hcard { flex: none; width: 84px; height: 117px; border-radius: 6px; position: relative; }
.hcard img { width: 100%; height: 100%; display: block; border-radius: 6px; object-fit: cover; }
.hcard.dragging { opacity: .35; }
.hcard .cost { position: absolute; top: -4px; right: -4px; background: var(--cyan); color: #012; font-weight: 800; font-size: 11px; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg2); }
.hcard .unaff { position: absolute; inset: 0; border-radius: 6px; box-shadow: inset 0 0 0 2px var(--red); }

#ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; opacity: .92; filter: drop-shadow(0 8px 14px rgba(0,0,0,.6)); }
#ghost img { display: block; border-radius: 7px; }
#ghost.card-ghost img { width: var(--cw); height: var(--ch); object-fit: cover; }
#ghost.drop-ghost img { width: 34px; height: 34px; }

#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; background: var(--bg2); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow-y: auto; }
#sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.sheet-card { display: flex; gap: 12px; align-items: flex-start; }
.sheet-card img { width: 40%; max-width: 170px; border-radius: 8px; flex: none; }
.sheet-card.damaged img { transform: none; }
.sheet-card .info { flex: 1; min-width: 0; font-size: 13px; }
.sheet-card .info h3 { margin: 0 0 4px; font-size: 17px; }
.sheet-card .info .sub { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.sheet-card .info p { margin: 4px 0; }
.sheet-card .info .lab { color: var(--cyan); font-weight: 700; }
.sheet-card .info .faq { color: var(--muted); font-style: italic; font-size: 12px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; }
.sheet-actions button { padding: 10px 8px; font-size: 13px; }
.sheet-actions button.wide { grid-column: 1 / -1; }
.sheet-actions button.danger { border-color: var(--red); color: var(--red); }
.sheet-actions button.good { border-color: var(--green); color: var(--green); }
.sheet-actions button.ab { border-color: var(--cyan); color: var(--cyan); text-align: left; }
#sheet h3.t { margin: 0 0 10px; font-size: 16px; }
.log-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.log-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log-list li b { color: var(--cyan); }
.log-list li.sys { color: var(--orange); }
.num-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.num-grid button { min-width: 52px; font-size: 18px; font-weight: 700; }
.discard-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.discard-grid img { width: 100%; border-radius: 5px; display: block; }

#toast { position: fixed; left: 50%; top: calc(52px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 70; background: rgba(20,18,26,.95); border: 1px solid var(--line); color: var(--text); padding: 8px 14px; border-radius: 12px; font-size: 13px; max-width: 92vw; text-align: center; pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
#toast.err { border-color: var(--red); color: #ffb3b3; }
#banner { position: fixed; top: 0; left: 0; right: 0; z-index: 80; background: var(--red); color: #fff; text-align: center; font-size: 12px; padding: 4px; padding-top: max(4px, env(safe-area-inset-top)); }
#banner.win { background: var(--green); color: #062; font-size: 14px; font-weight: 800; padding: 8px; }
#banner.win button { padding: 4px 10px; font-size: 13px; background: #062; color: #fff; border-color: #062; border-radius: 8px; }

#notice { position: fixed; inset: 0; z-index: 85; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.notice-box { background: var(--bg2); border: 1px solid var(--pink); border-radius: 16px; padding: 14px; width: min(100%, 380px); display: flex; flex-direction: column; align-items: center; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.7); }
.notice-box img { width: 46%; max-width: 170px; border-radius: 8px; }
.notice-text { text-align: center; }
.notice-text h3 { margin: 0 0 6px; font-size: 17px; color: var(--pink); }
.notice-text p { margin: 4px 0; font-size: 14px; }
.notice-text .act { color: var(--green); font-weight: 700; }
.notice-box button { width: 100%; }

#win { position: fixed; inset: 0; z-index: 88; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(255,45,149,.35), rgba(20,18,26,.96) 70%); }
.win-box { width: min(100%, 400px); background: var(--bg2); border: 2px solid var(--pink); border-radius: 20px; padding: 22px 18px; text-align: center; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 0 60px rgba(255,45,149,.35); animation: winpop .45s cubic-bezier(.2,1.4,.4,1); }
.win-box.mine { border-color: var(--green); box-shadow: 0 0 60px rgba(61,220,132,.35); }
.win-box h2 { margin: 8px 0 0; font-size: 40px; letter-spacing: .12em; font-style: italic; color: var(--pink); }
.win-box.mine h2 { color: var(--green); }
.win-box .who { margin: 0; font-size: 15px; }
.win-box .sub { margin: 0; color: var(--muted); font-size: 12px; }
.win-camps { display: flex; justify-content: center; gap: 6px; margin: 6px 0; }
.win-camps img { width: 26%; border-radius: 6px; }
.win-box button { width: 100%; font-size: 15px; padding: 12px; }
@keyframes winpop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-8px); } }
