:root {
  --bg: #0e1420; --bg2: #141d2e; --panel: #172136; --panel2: #1f2c47; --line: rgba(255,255,255,.1);
  --ink: #eef1f7; --muted: #8e9ab0; --gold: #e9b949; --teal: #38c2b0; --danger: #e5646b;
  --cw: min(calc((100vw - 28px) / 8.1), calc((100dvh - 190px) / 10), 92px);
  --ch: calc(var(--cw) * 1.4);
  --gap: calc(var(--cw) * .18);
}
@supports not (height: 100dvh) {
  :root { --cw: min(calc((100vw - 28px) / 8.1), calc((100vh - 190px) / 10), 92px); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 30%, #1a2742 0%, var(--bg) 70%) fixed;
  color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; user-select: none; -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { height: 100%; display: flex; flex-direction: column; align-items: center; }

/* header */
#top { width: 100%; max-width: 980px; display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.brand { font-weight: 800; letter-spacing: .02em; font-size: 18px; }
.brand span, h1 span { color: var(--gold); }
.status { flex: 1; text-align: center; font-size: 14px; color: var(--muted); padding: 5px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.mine { color: #1b1405; background: var(--gold); border-color: var(--gold); font-weight: 600; }
.tools { display: flex; gap: 6px; }
button.icon { width: 36px; height: 36px; padding: 0; border-radius: 10px; font-size: 18px; line-height: 1; }
button.icon.off { opacity: .45; }

/* board */
#board {
  display: grid; gap: var(--gap); justify-content: center; align-content: start; width: 100%; padding: 4px 0 8px;
  grid-template-columns: calc(var(--cw) * 2.3) calc(var(--cw) * 5.4);   /* fixed widths: the board must not move when cards come and go */
  grid-template-areas: "oside ohand" "oholds oholds" "centers centers" "mholds mholds" "mside mhand";
}
#oside { grid-area: oside; } #ohand { grid-area: ohand; } #centers { grid-area: centers; justify-self: center; }
#oholds { grid-area: oholds; justify-self: center; } #mholds { grid-area: mholds; justify-self: center; }
#mside { grid-area: mside; } #mhand { grid-area: mhand; }
@media (min-width: 820px) and (min-aspect-ratio: 5/4) {
  :root { --cw: min(calc((100dvh - 150px) / 8.9), calc((100vw - 80px) / 10), 104px); }
  #board { grid-template-columns: calc(var(--cw) * 3.9) calc(var(--cw) * 5.4); grid-template-areas: "oside ohand" "centers oholds" "centers mholds" "mside mhand"; align-items: start; }
  #centers { justify-self: start; align-self: center; }
  #oholds, #mholds { justify-self: start; }
  .hand { justify-content: flex-start; }
}

.area { position: relative; }
.hand { display: flex; gap: calc(var(--cw) * .08); justify-content: flex-start; align-items: flex-start; min-height: var(--ch); }

/* cards */
.card {
  width: var(--cw); height: var(--ch); flex: none; position: relative;
  background: center / 100% 100% no-repeat; filter: drop-shadow(0 2px 3px rgba(0,0,0,.55));
  transition: transform .12s ease, filter .12s ease;
}
.card.back { background-image: url(cards/back.webp); }
.card[data-src] { cursor: grab; touch-action: none; }
.card.playable { filter: drop-shadow(0 0 7px var(--teal)) drop-shadow(0 2px 3px rgba(0,0,0,.55)); }
.card.selected { transform: translateY(calc(var(--ch) * -.14)); filter: drop-shadow(0 0 9px var(--gold)) drop-shadow(0 2px 3px rgba(0,0,0,.55)); }
.card.dragging { opacity: .3; }
.card.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.ghost { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; transform: translate(-50%, -60%) scale(1.1); filter: drop-shadow(0 10px 12px rgba(0,0,0,.6)); }

/* side piles */
.sidepile { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.stack { position: relative; width: var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .09); }
.stack.s2 { box-shadow: 2px 2px 0 #3a4766; }
.stack.s3 { box-shadow: 2px 2px 0 #3a4766, 4px 4px 0 #2b3650; }
.stack.s4 { box-shadow: 2px 2px 0 #3a4766, 4px 4px 0 #2b3650, 6px 6px 0 #222b42; }
.label { font-size: max(11px, calc(var(--cw) * .21)); line-height: 1.2; color: var(--muted); text-align: center; width: calc(var(--cw) * 1.4); }
.label b, .label span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label b { color: var(--ink); font-weight: 600; }
.me .label b { color: var(--gold); }

/* centers */
.centers { display: flex; gap: var(--gap); padding: calc(var(--cw) * .2) calc(var(--cw) * .22) calc(var(--cw) * .1); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; flex-wrap: wrap; justify-content: center; }
.centers .cap { width: 100%; text-align: center; font-size: 10px; letter-spacing: .18em; color: var(--muted); }
.center { position: relative; width: var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .09); border: 2px dashed rgba(255,255,255,.16); display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.22); font-weight: 700; font-size: calc(var(--cw) * .5); }
.center.full { border: 0; }
.center .card { position: absolute; left: 0; top: 0; }
.center .val { position: absolute; right: -6px; bottom: -6px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--gold); color: #1b1405; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; z-index: 2; box-shadow: 0 1px 4px rgba(0,0,0,.6); }
.center.cleared .card { opacity: .35; }
.center .val.king { background: var(--teal); color: #04201c; font-size: 11px; letter-spacing: .02em; }
.deckinfo { width: 100%; text-align: center; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* holds */
.holds { display: flex; gap: var(--gap); }
.hold { position: relative; width: var(--cw); height: calc(var(--ch) * 1.8); border-radius: calc(var(--cw) * .09); }
.hold .slot { position: absolute; left: 0; top: 0; width: 100%; height: var(--ch); border: 2px dashed rgba(255,255,255,.12); border-radius: calc(var(--cw) * .09); }
.hold .card { position: absolute; left: 0; }
.hold .num { position: absolute; right: -5px; top: -7px; z-index: 3; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel2); color: var(--ink); font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.6); }
.holds:not(.mine) .hold { cursor: zoom-in; }

.target { outline: 2px solid var(--teal); outline-offset: 3px; box-shadow: 0 0 16px rgba(56,194,176,.55); background: rgba(56,194,176,.07); }
.target.over { background: rgba(56,194,176,.28); }

#actions { min-height: 0; }
#actions button { margin: 4px 0 10px; }

/* buttons & inputs */
button { font: inherit; color: var(--ink); background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; cursor: pointer; }
button:hover { border-color: rgba(255,255,255,.3); }
button.primary { background: var(--gold); color: #1b1405; border-color: var(--gold); font-weight: 700; }
button:disabled { opacity: .5; cursor: default; }
input[type=text] { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; user-select: text; -webkit-user-select: text; }
input[type=text]:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(6,9,16,.78); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.overlay[hidden], #toast[hidden], button[hidden], .note[hidden], #btnInstall[hidden] { display: none; }
.dialog { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: 100%; overflow-y: auto; }
.dialog.wide { max-width: 560px; }
.dialog h1 { margin: 0; font-size: 32px; letter-spacing: .01em; }
.dialog h2 { margin: 0; font-size: 22px; }
.dialog label { font-size: 13px; color: var(--muted); }
.tag { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.note { padding: 8px 12px; border-radius: 10px; background: rgba(233,185,73,.12); color: var(--gold); font-size: 14px; }
.chips { display: flex; gap: 8px; }
.chips label { flex: 1; color: var(--ink); }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: block; text-align: center; padding: 9px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; font-size: 14px; }
.chips input:checked + span { border-color: var(--gold); color: var(--gold); background: rgba(233,185,73,.1); }
.chips input:focus-visible + span { outline: 2px solid var(--teal); }
.joinrow, .row { display: flex; gap: 8px; }
.joinrow input { text-transform: uppercase; letter-spacing: .15em; }
.code { font-size: 20px; letter-spacing: .2em; color: var(--gold); }
details { font-size: 14px; color: var(--muted); }
summary { cursor: pointer; padding: 4px 0; }
details ul { padding-left: 18px; margin: 6px 0 0; }
details li { margin-bottom: 6px; }
button small { opacity: .7; }

.viewercards { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; --cw: 60px; }
.viewercards .card.top { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; max-width: min(92vw, 420px); background: #2a1519; color: #ffd9dc; border: 1px solid var(--danger); border-radius: 12px; padding: 10px 16px; font-size: 14px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#toast.info { background: var(--panel2); color: var(--ink); border-color: var(--line); }

@media (prefers-reduced-motion: reduce) { .card, .card.pop { transition: none; animation: none; } }
#newGameBlock { display: flex; flex-direction: column; gap: 10px; }
#newGameBlock[hidden] { display: none; }

.rules h3 { margin: 8px 0 0; font-size: 15px; color: var(--gold); }
.rules p, .rules ul { margin: 4px 0 0; font-size: 14px; color: var(--ink); }
.rules ul { padding-left: 18px; }
.rules li { margin-bottom: 4px; }
.rules button { margin-top: 10px; }
.centers { width: calc(var(--cw) * 4.4); }
.deckinfo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 820px) and (min-aspect-ratio: 5/4) { .centers { width: calc(var(--cw) * 3.9); } }

/* side pile: the number of cards left stands in front of (left of) the card, the name below the card */
.sidepile { flex-direction: row; align-items: flex-start; gap: calc(var(--cw) * .08); }
.sidecol { display: flex; flex-direction: column; align-items: center; gap: 3px; width: var(--cw); }
.sidecol .label { width: calc(var(--cw) * 1.3); }
.count { width: calc(var(--cw) * .62); text-align: right; line-height: 1.15; font-size: max(11px, calc(var(--cw) * .22)); color: var(--muted); padding-top: 3px; }
.count b, .count span { display: block; }
.count b { color: var(--ink); font-weight: 600; font-size: 1.25em; }
.me .count b { color: var(--gold); }

/* header status text is hidden (screen readers still get it); the yellow arrow right of the cards shows whose turn it is */
.status, .status.mine { font-size: 0; padding: 0; border: 0; background: none; min-height: 0; color: transparent; }
.turnarrow { position: absolute; left: calc(100% + var(--cw) * .06); top: calc(var(--ch) / 2 - var(--cw) * .22); width: 0; height: 0; border-top: calc(var(--cw) * .22) solid transparent; border-bottom: calc(var(--cw) * .22) solid transparent; border-right: calc(var(--cw) * .32) solid var(--gold); filter: drop-shadow(0 0 5px rgba(233,185,73,.7)); animation: nudge 1.2s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(calc(var(--cw) * -.08)); } }
@media (prefers-reduced-motion: reduce) { .turnarrow { animation: none; } }

/* the side pile (the cards you must get rid of) stands apart from the hand: own panel with a gold border and a ring around the card */
.sidepile { position: relative; isolation: isolate; }
.sidepile::before { content: ""; position: absolute; inset: -5px -6px -5px -7px; z-index: -1; border-radius: 12px; background: rgba(233,185,73,.07); border: 1px solid rgba(233,185,73,.3); }
.stack { outline: 2px solid rgba(233,185,73,.5); outline-offset: 2px; }
#board { column-gap: calc(var(--cw) * .3); }

/* v8: calmer side pile: no ring around the card, no panel border; a soft filled panel with a thin gold bar on its left edge; the turn arrow stands still */
.stack { outline: none; }
.sidepile::before { border: 0; background: linear-gradient(90deg, rgba(233,185,73,.16), rgba(233,185,73,.05)); box-shadow: inset 3px 0 0 rgba(233,185,73,.55); }
.turnarrow { animation: none; }

/* v9: the turn arrow stands INSIDE the side pile panel, left of the card, pointing at it (the panel is a bit wider for it) */
.turnslot { width: calc(var(--cw) * .3); height: var(--ch); display: flex; align-items: center; flex: none; }
.turnarrow { position: static; left: auto; top: auto; border-right: 0; border-left: calc(var(--cw) * .28) solid var(--gold); border-top: calc(var(--cw) * .2) solid transparent; border-bottom: calc(var(--cw) * .2) solid transparent; filter: drop-shadow(0 0 4px rgba(233,185,73,.7)); animation: none; }
.sidepile::before { inset: -5px -6px -5px -6px; }

/* result: a banner at the bottom, the finished board stays visible and clickable; a win gets a golden glow (plus confetti from game.js) */
#result.overlay { background: none; pointer-events: none; align-items: flex-end; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
#result .dialog { pointer-events: auto; max-width: 440px; text-align: center; padding: 12px 16px; gap: 6px; background: rgba(23,33,54,.96); animation: rise .45s ease-out; }
#result .dialog h2 { font-size: 24px; } #result .tag { margin: 0; }
#result .row { justify-content: center; }
#result .dialog.party { border-color: var(--gold); box-shadow: 0 0 34px rgba(233,185,73,.6), 0 10px 40px rgba(0,0,0,.5); }
#result .dialog.party h2 { color: var(--gold); animation: bounce 1s ease-in-out infinite; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bounce { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { #result .dialog, #result .dialog.party h2 { animation: none; } }

/* v11: the number of cards left stands RIGHT of the card; the side panel has a gold border on all four sides (no bar on the left only) and hugs its content */
.sidepile { width: max-content; }
.sidepile::before { border: 2px solid rgba(233,185,73,.6); box-shadow: none; background: rgba(233,185,73,.07); }
.count { text-align: left; }
.count { padding-left: 7px; width: calc(var(--cw) * .62 + 7px); }   /* clear of the stacked-card shadow */
/* v13: a bit more room (about 6 px more) between the gold border and the card */
.sidepile::before { inset: -11px -12px -11px -12px; }

/* smiley (reaction) buttons in the header, human games only */
button.icon.emoji { font-size: 20px; }
button.icon[disabled] { opacity: .35; cursor: default; }
button.icon.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

/* smiley (reaction) buttons under "N left" in my side panel (human games) */
.count .react { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.count .rb { width: 28px; height: 22px; padding: 0; font-size: 15px; line-height: 1; border-radius: 8px; text-align: center; }
.count .rb[disabled] { opacity: .35; cursor: default; }

/* ranking overlay */
.ranking .rankwrap { max-height: 52vh; overflow: auto; border-radius: 10px; }
.ranking table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ranking th, .ranking td { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.07); }
.ranking th { position: sticky; top: 0; background: var(--panel2); font-weight: 600; font-size: 12px; color: var(--muted); }
.ranking td.n, .ranking th.n { text-align: right; white-space: nowrap; }
.ranking tr.me td { background: rgba(233,185,73,.14); }
.ranking tr.top1 td:first-child { color: #ffd34d; font-weight: 800; } .ranking tr.top2 td:first-child { color: #d4d9e2; font-weight: 800; } .ranking tr.top3 td:first-child { color: #d99a63; font-weight: 800; }
.ranking .up { color: #54d18a; } .ranking .down { color: #ef7a80; } .ranking .muted { color: var(--muted); }
.ranking small { color: var(--gold); }
/* settings overlay */
.dialog h3 { margin: 6px 0 0; font-size: 15px; color: var(--gold); }
#pidShow { font-family: ui-monospace, Consolas, monospace; font-size: 11px; letter-spacing: 0; padding-left: 8px; padding-right: 6px; }
#pidInput { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
