:root {
  --bg: #1d1626; --panel: #2c2238; --panel2: #3a2d4a; --line: #4a3b5e; --text: #f2ecf7; --muted: #a99bb8;
  --accent: #e8c26a; --good: #7bd88f; --bad: #ef6f6c; --mine: #4f8fe8; --theirs: #e8545f;
  --ink: #2a2220;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; overscroll-behavior: none; }
#app { height: 100dvh; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 2px solid #57466e; border-radius: 8px; padding: 10px 16px; cursor: pointer; }
button:hover:not(:disabled) { background: #4b3b60; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #6a4aa0; border-color: var(--accent); }
button.big { padding: 16px 22px; font-size: 1.15rem; }
input, select, textarea { font: inherit; color: var(--text); background: #231a2e; border: 2px solid #57466e; border-radius: 6px; padding: 8px 10px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.toast { background: #000c; border: 1px solid var(--accent); padding: 10px 16px; border-radius: 8px; margin-top: 8px; }
#toasts { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 100; pointer-events: none; display: flex; flex-direction: column; align-items: center; }

/* ---------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 12px; }
.modal { background: var(--panel); border: 2px solid var(--accent); border-radius: 14px; padding: 20px; max-width: min(96vw, 640px); max-height: 94dvh; overflow: auto; }
.modal.wide { max-width: min(96vw, 980px); }
.modal h2 { color: var(--accent); text-align: center; margin-bottom: 12px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.opaque { background: var(--bg); }

/* ---------- home */
.home { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.home .box { width: min(520px, 100%); display: flex; flex-direction: column; gap: 12px; }
.home h1 { font-size: clamp(2rem, 7vw, 3.2rem); color: var(--accent); text-align: center; }
.home .sub { text-align: center; }
.section { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.section h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.codebox { font-size: 2.6rem; letter-spacing: .3em; text-align: center; color: var(--accent); font-weight: 700; }
.statusdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.statusdot.open { background: var(--good); }
.statusdot.reconnecting, .statusdot.connecting { background: var(--accent); }

/* ---------- cards */
.card { position: relative; container-type: inline-size; aspect-ratio: 742 / 1042; width: 100%; border-radius: 4.5% / 3.2%; border: 2px solid var(--ink);
  --frame: #ab9a77; background: var(--frame); color: var(--ink); font-family: "Segoe UI", system-ui, sans-serif; user-select: none; overflow: visible; }
.card.kind-item { --frame: #7aa5dd; } .card.kind-sanctuary { --frame: #7fbf8d; }
.card.mine { --frame: #6a9be8; } .card.theirs { --frame: #e8707a; }
.card.flipped { --frame: #f4f1ea; } .card.flipped.mine { --frame: #b4ccff; } .card.flipped.theirs { --frame: #ffbcc4; }
.card.dimmed::after { content: ""; position: absolute; inset: 0; background: #0006; border-radius: 4cqw; pointer-events: none; }
.card .art { position: absolute; left: 2.8%; top: 2.2%; width: 94.4%; height: 54%; }
.card .artimg { position: absolute; inset: 0; overflow: hidden; background: hsl(var(--hue) 35% 45%); }
.card.flipped .artimg { background: hsl(var(--hue) 45% 85%); }
.card .mono { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 40cqw; font-weight: 800; color: #fff3; }
.card .artpic { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .nametab { position: absolute; left: 1.6%; top: .3%; max-width: 74%; background: var(--frame); padding: 1.1cqw 7cqw 1.1cqw 3.4cqw; font-family: Lato, "Segoe UI", system-ui, sans-serif; font-weight: 700; font-size: 7.4cqw; line-height: 1.15; white-space: nowrap;
  clip-path: polygon(0 0, 100% 0, calc(100% - 3.4cqw) 100%, 0 100%); overflow: hidden; }
.card .nametab span { display: block; overflow: hidden; text-overflow: ellipsis; }
.card .drop { position: absolute; right: 1.6%; top: 1%; width: 14cqw; aspect-ratio: 40 / 56; }
.card .dropsvg { width: 100%; height: 100%; display: block; fill: #fdf6e3; stroke: var(--ink); stroke-width: 2.2; stroke-linejoin: round; overflow: visible; }
.card .drop b { position: absolute; left: 0; right: 0; top: 40%; text-align: center; font-size: 8.4cqw; font-weight: 800; line-height: 1; }
.card .drop b.long { font-size: 6.6cqw; }
.card .drop b.up { color: #1f8a3a; } .card .drop b.down { color: #c0392b; }
.card .chips { position: absolute; left: 1.4cqw; bottom: 1.4cqw; right: 1.4cqw; display: flex; flex-wrap: wrap-reverse; gap: 1cqw; align-content: flex-start; }
.card .chip { font-size: 5.6cqw; font-weight: 700; padding: .6cqw 3cqw; border-radius: 9cqw; border: .5cqw solid var(--ink); color: #fff; background: #8f736b; line-height: 1.3; }
.card .chip.Top { background: #3f86f2; } .card .chip.Bottom { background: #ec5fa4; } .card .chip.Switch { background: #a77fe0; }
.card .chip.Item { background: #6b86ad; } .card .chip.Sanctuary { background: #3f9455; }
.card .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 1.3cqw; background: #0007; }
.card .progress i { display: block; height: 100%; background: var(--accent); }
.card .textbox { position: absolute; left: 3.4%; width: 93.2%; top: 58%; bottom: 3.4%; background: #f9e0bd; border: .65cqw solid var(--ink); border-radius: 2cqw; padding: 2.4cqw 3cqw; overflow: hidden; font-family: Lato, "Segoe UI", system-ui, sans-serif; font-size: 6cqw; line-height: 1.2; font-weight: 700; }
.card.flipped .textbox { background: #fffdf7; } .card.flipped.mine .textbox { background: #e6eeff; } .card.flipped.theirs .textbox { background: #ffe8ea; }
.card .textbox p { margin: 0 0 1.4cqw; white-space: pre-line; }
.card .textbox .orgasm { display: flex; gap: 1.4cqw; align-items: flex-start; }
.card .textbox .mini { flex: none; width: 1em; height: 1.4em; fill: #fffaf0; stroke: var(--ink); stroke-width: 3; margin-top: .05em; }
.card .foot { position: absolute; left: 5%; right: 5%; bottom: .5%; display: flex; justify-content: space-between; font-size: 2.5cqw; opacity: .8; }
.card .badge { position: absolute; right: 6cqw; bottom: 8cqw; background: var(--accent); border: .8cqw solid var(--ink); border-radius: 50%; width: 12cqw; height: 12cqw; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 7cqw; z-index: 2; }
.card.back { background: #5b2f4e; border-color: var(--accent); }
.card.back::after { content: ""; position: absolute; inset: 9% 10%; border: .8cqw solid #7a3d68; border-radius: 3cqw; background: radial-gradient(circle at 50% 55%, #f6e9f2 0 18%, transparent 19%); }
.card .highlight { position: absolute; inset: -1.2cqw; border: 1.4cqw solid var(--accent); border-radius: 6cqw; pointer-events: none; }

@container (max-width: 160px) {
  .drop { width: 21cqw; }
  .drop b { font-size: 12.5cqw; top: 38%; }
  .drop b.long { font-size: 10cqw; }
  .nametab { max-width: 68%; }
}

@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
@keyframes flip { 0% { transform: rotateY(90deg) scale(1.05); box-shadow: 0 0 0 0 #fff; } 60% { box-shadow: 0 0 30px 8px #fff9; } 100% { transform: none; box-shadow: none; } }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.card.anim-pop { animation: pop .28s ease-out; }
.card.anim-flip { animation: flip .55s ease-out; }

/* ---------- game layout */
.game { height: 100dvh; padding: 10px; display: grid; gap: 10px; grid-template-columns: 270px minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "info opp detail" "info board detail" "info me controls"; }
.info { grid-area: info; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.opphand { grid-area: opp; display: flex; justify-content: center; height: 42px; overflow: hidden; }
.opphand .card { width: 60px; margin-left: -26px; }
.opphand .card:first-child { margin-left: 0; }
.boardwrap { grid-area: board; container-type: size; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board { --gap: 6px; --cw: min(calc((100cqw - 4 * var(--gap)) / 5), calc((100cqh - 3 * var(--gap)) / 4 * .712)); display: grid; grid-template-columns: repeat(5, var(--cw)); gap: var(--gap); }
.slot { position: relative; width: var(--cw); aspect-ratio: 742 / 1042; border-radius: 6px; background: #2a2036; border: 2px solid var(--line); }
.slot.legal { background: #27402f; border: 3px solid var(--good); cursor: pointer; }
.slot.choice { background: #4a3d22; border: 3px solid var(--accent); cursor: pointer; }
.slot.legal:hover, .slot.choice:hover { filter: brightness(1.3); }
.slot .card { position: absolute; inset: 0; width: 100%; }
.slot.choice .card, .slot.legal .card { cursor: pointer; }
.slot.choice .card::before { content: ""; position: absolute; inset: -2px; border: 3px solid var(--accent); border-radius: 5cqw; z-index: 3; pointer-events: none; }
.slot.sacrificed::after { content: "✕"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 3rem; color: var(--bad); animation: pop .5s ease-out reverse forwards; }
.me { grid-area: me; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.banner { min-height: 1.6em; color: var(--accent); font-weight: 600; text-align: center; padding: 2px 6px; }
.banner.warn { color: var(--bad); }
.hand { display: flex; justify-content: center; align-items: flex-start; width: 100%; padding: 14px 6px 0; --hw: 124px; height: calc(var(--hw) * .712 + 16px); overflow: hidden; }
.hand .card { width: var(--hw); flex: none; transition: transform .12s; margin-left: var(--overlap, 6px); cursor: pointer; }
.hand .card:first-child { margin-left: 0; }
.hand .card:hover, .hand .card.selected { transform: translateY(-6px); z-index: 5; }
.hand .card.selected::before { content: ""; position: absolute; inset: -4px; border: 4px solid var(--accent); border-radius: 5cqw; z-index: 4; pointer-events: none; }
.detail { grid-area: detail; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; }
.detail .bigcard { width: 100%; max-width: 300px; align-self: center; }
.detail .detailtext { background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 10px; font-size: .95rem; flex: 1; min-height: 70px; overflow: auto; }
.controls { grid-area: controls; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; align-content: start; }
.controls > .preview, .controls > .muted, .controls > .skipbtn { grid-column: 1 / -1; }
.controls .preview { height: 3.9em; overflow: hidden; font-size: .86rem; }
.controls button.big { padding: 9px 10px; font-size: 1.05rem; }
.controls .muted { min-height: 1.3em; }
.controls .endbtn { order: 1; } .controls .menubtn { order: 2; } .controls .preview { order: 3; } .controls .muted { order: 4; } .controls .skipbtn { order: 5; }
.preview { color: var(--accent); min-height: 2.6em; font-size: .92rem; }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 10px; display: flex; gap: 12px; align-items: center; }
.panel.active.mine { border-color: var(--mine); border-width: 3px; } .panel.active.theirs { border-color: var(--theirs); border-width: 3px; }
.portrait { width: 64px; height: 64px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; color: #fff; flex: none; }
.portrait.mine { background: #254b86; } .portrait.theirs { background: #86252e; }
.pstats { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pname { color: var(--muted); font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pstat { display: flex; align-items: center; gap: 6px; }
.pstat.score { font-size: 1.4rem; font-weight: 700; }
.pstat svg { width: 18px; height: 22px; flex: none; }
.log { background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 8px; flex: 1; overflow: auto; font-size: .86rem; min-height: 60px; }
.log div { padding: 1px 0; } .log .p0 { color: var(--mine); } .log .p1 { color: var(--theirs); }
.turnlabel { font-size: 1.8rem; color: var(--accent); font-weight: 700; }
.mobilebar { display: none; }
.netbanner { position: fixed; top: 0; left: 0; right: 0; background: #7a2630; text-align: center; padding: 6px; z-index: 60; }
.netbanner.warn { background: #6b5a1c; }
.mullrow, .choicerow { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.mullrow .card, .choicerow .card { width: min(160px, 21vw); cursor: pointer; }
.mullrow .card.chosen { transform: translateY(-8px); }
.mullrow .card.chosen::before { content: "REPLACE"; position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; background: #8a1f2699; color: #fff; font-weight: 800; font-size: 11cqw; border-radius: 4cqw; }
.choicerow .card:hover { transform: translateY(-6px); }

@media (max-width: 900px), (max-height: 560px) and (orientation: landscape) {
  .game { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto auto; padding: 6px; gap: 6px;
    grid-template-areas: "info" "opp" "board" "me" "controls"; }
  .info { flex-direction: row; align-items: stretch; }
  .info .turnlabel { display: none; } .info .log { display: none; }
  .info .panel { flex: 1; padding: 6px; gap: 8px; min-width: 0; } .portrait { width: 40px; height: 40px; font-size: 1.3rem; }
  .detail { display: none; }
  .opphand { height: 44px; } .opphand .card { width: 30px; margin-left: -12px; }
  .hand { --hw: 22vw; overflow-x: auto; overflow-y: hidden; justify-content: flex-start; padding-top: 6px; }
  .controls { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .controls .preview { flex-basis: 100%; order: 3; height: 2.7em; min-height: 0; }
  .controls .muted { min-height: 1.3em; }
  .controls button { flex: 1; }
  .mobilebar { display: flex; }
  .board { --gap: 3px; }
}
/* ---------- deck builder */
.builder { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) 340px 300px; gap: 10px; padding: 10px; }
.collection { display: flex; flex-direction: column; min-height: 0; gap: 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; overflow: auto; padding: 4px 4px 40px; flex: 1; align-content: start; }
.grid .card { cursor: pointer; }
.deckcol { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.decklist { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.deckrow { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 6px; color: #fff; font-size: .95rem; }
.deckrow.furry { background: #6b4a35; } .deckrow.item { background: #2f5d9a; } .deckrow.sanctuary { background: #3a7d4a; }
.deckrow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deckrow button { padding: 0 9px; line-height: 1.5; }
.count { font-size: 1.8rem; font-weight: 700; color: var(--accent); } .count.ok { color: var(--good); }
@media (max-width: 1100px) { .builder { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); height: 100dvh; } .builder .detailcol { display: none; } .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); } }
