/* ==========================================================================
   Game Night: Idiot, Hearts and Dominoes. Uses the tokens from style.css and the
   playing cards (.pc) from games.css.
   ========================================================================== */

.ct-table {
  width: 100%; max-width: 1200px; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 6px 0 10px;
  --cw: calc(clamp(44px, min(6vw, 8vh), 80px) * var(--zoom));
}
.ct-mid { display: flex; align-items: center; justify-content: center; gap: calc(var(--cw) * .7); margin-bottom: 26px; --cw: calc(clamp(60px, min(8.5vw, 11vh), 110px) * var(--zoom)); }
.ct-deck { position: relative; }
.ct-pile { position: relative; width: calc(var(--cw) * 1.9); height: calc(var(--cw) * 1.4); }
.ct-pile .pc { position: absolute; top: 0; left: 0; }
.ct-pile .pc.p3 { transform: translateX(0) rotate(-8deg); }
.ct-pile .pc.p2 { transform: translateX(calc(var(--cw) * .3)) rotate(-3deg); }
.ct-pile .pc.p1 { transform: translateX(calc(var(--cw) * .6)) rotate(2deg); }
.ct-pile .pc.p0 { transform: translateX(calc(var(--cw) * .9)) rotate(5deg); box-shadow: 0 0 0 3px var(--gold), 0 6px 16px rgba(0,0,0,.45); }
.ct-pile .pc.landed { animation: ccland .35s cubic-bezier(.2, 1.4, .4, 1) both; }
.ct-pile .cc-by { top: calc(100% + 10px); }
.ct-empty { display: grid; place-items: center; text-align: center; width: 100%; height: 100%; border-radius: 12px; border: 3px dashed var(--line-strong); color: var(--muted); font-family: var(--display); font-weight: 600; padding: 4px; }
.ct-empty small { display: block; font-weight: 400; color: var(--soft); }
.ct-burn { font-family: var(--display); font-weight: 700; font-size: 1.2em; color: #ffb36b; }
.ct-spots { width: 100%; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.ct-spot { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-radius: 16px; background: rgba(0,0,0,.22); border: 3px solid var(--rk); box-shadow: var(--shadow-1); }
.ct-spot.cur { box-shadow: 0 0 0 3px var(--gold), 0 0 22px rgba(255,207,51,.45); }
.ct-spot.mine { background: rgba(0,0,0,.34); }
.ct-spot.small { padding: 6px 8px; }
.ct-name { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ct-name span {
  display: inline-flex; align-items: center; gap: 5px; padding: .05em .65em; border-radius: 999px; background: linear-gradient(var(--rk-hi), var(--rk)); color: var(--rk-text);
  font-family: var(--display); font-weight: 700; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ct-name span .ic { width: 1em; height: 1em; }
.ct-tag { display: inline-flex; align-items: center; gap: 4px; font-size: .9em; color: var(--muted); white-space: nowrap; }
.ct-tag .ic { width: 1em; height: 1em; }
.ct-tag.ok { color: #7ee2a2; }
.ct-tag.out { color: var(--gold-hi); }

/* Idiot: three face-down cards, each with a face-up card on top */
.islots { display: flex; gap: 6px; }
.islot { flex: none; position: relative; width: var(--cw); height: calc(var(--cw) * 1.4 + var(--cw) * .22); }
.islot .idown, .islot .iup { position: absolute; left: 0; top: 0; padding: 0; border: 0; background: none; }
.islot .iup { top: calc(var(--cw) * .22); }
.islot .idown.empty { width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: calc(var(--cw) * .1); border: 2px dashed rgba(255,255,255,.18); }
.islot button { cursor: pointer; }
.islot .idown.pick .pc { box-shadow: 0 0 0 3px var(--gold), 0 0 16px rgba(255,207,51,.6); animation: deckglow 1.4s ease-in-out infinite; }
.islot .pc.ok { box-shadow: 0 0 0 3px var(--gold), 0 4px 10px rgba(0,0,0,.35); }
.islot .pc.swapto { box-shadow: 0 0 0 3px #5ad1ff, 0 0 14px rgba(90,209,255,.6); }
.pc.sel { box-shadow: 0 0 0 4px #1fa3ff, 0 0 18px rgba(31,163,255,.7) !important; }

/* my cards along the bottom: a fan of playing cards */
.hand.pfan .pcbtn { padding: 0; border: 0; background: none; flex: none; margin-left: clamp(calc(var(--cw) * -.72), calc((100cqw - var(--n) * var(--cw)) / max(1, var(--n) - 1)), 8px); transition: transform .15s ease; }
.hand.pfan .pcbtn:first-child { margin-left: 0; }
.hand.pfan .pcbtn .pc { --cw: inherit; }
.hand.pfan { --cw: calc(clamp(52px, min(9.5vw, 12vh), 100px) * var(--zoom)); }
.hand.pfan .pc { width: var(--cw); height: calc(var(--cw) * 1.4); }
.hand.pfan .pcbtn[data-act="ihand"], .hand.pfan .pcbtn[data-act="hcard"] { cursor: pointer; }
.hand.pfan .pc.ok { transform: translateY(-12px); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 0 0 3px var(--gold), 0 8px 16px rgba(0,0,0,.45); }
.hand.pfan .pcbtn:hover .pc.ok { transform: translateY(-20px); }
.hand.pfan .pc.no { filter: brightness(.55) saturate(.7); }
.hand.pfan .pc.sel { transform: translateY(-30px); }
.hand.pfan .pc.got { outline: 3px dashed #5ad1ff; outline-offset: 2px; }

/* Hearts: the trick in the middle, a name at each side */
.ht-felt { position: relative; width: min(100%, calc(var(--cw) * 7.5)); height: calc(var(--cw) * 4.6); border-radius: 50%; background: radial-gradient(ellipse, rgba(0,0,0,.22), rgba(0,0,0,.06) 70%, transparent); --cw: calc(clamp(56px, min(8vw, 10vh), 100px) * var(--zoom)); }
.ht-trick { position: absolute; inset: 0; }
.ht-card { position: absolute; left: 50%; top: 50%; transition: transform .2s ease; }
.ht-card .pc { animation: ccland .3s cubic-bezier(.2, 1.4, .4, 1) both; }
.ht-card.s { transform: translate(-50%, -18%); }
.ht-card.n { transform: translate(-50%, -82%); }
.ht-card.w { transform: translate(-125%, -50%); }
.ht-card.e { transform: translate(25%, -50%); }
.ht-card.win .pc { box-shadow: 0 0 0 4px var(--gold), 0 0 22px rgba(255,207,51,.7); }
.ht-name {
  position: absolute; display: flex; align-items: center; gap: 6px; padding: 3px 4px 3px 3px; border-radius: 999px; background: rgba(0,0,0,.45);
  box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; z-index: 2;
}
.ht-name.cur { box-shadow: 0 0 0 3px var(--gold); }
.ht-name span { display: inline-flex; align-items: center; gap: 4px; padding: .05em .6em; border-radius: 999px; background: linear-gradient(var(--rk-hi), var(--rk)); color: var(--rk-text); font-family: var(--display); font-weight: 700; max-width: 8em; overflow: hidden; text-overflow: ellipsis; }
.ht-name span .ic { width: 1em; height: 1em; }
.ht-name b { min-width: 1.6em; text-align: center; color: #fff; font-family: var(--display); }
.ht-name i { font-style: normal; font-weight: 700; color: #ff8a80; padding-right: 4px; }
.ht-name.s { left: 50%; bottom: -6px; transform: translateX(-50%); }
.ht-name.n { left: 50%; top: -6px; transform: translateX(-50%); }
.ht-name.w { left: -4px; top: 50%; transform: translateY(-50%); }
.ht-name.e { right: -4px; top: 50%; transform: translateY(-50%); }
.ht-broken { position: absolute; right: 8%; bottom: 8%; font-size: 1.6em; color: rgba(255,255,255,.18); }
.ht-broken.on { color: #ff4d5e; text-shadow: 0 0 12px rgba(255,77,94,.7); }
.ht-rule { font-size: .74em; color: var(--soft); letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }

/* Dominoes: ivory tiles with black pips */
.dm {
  --dw: calc(clamp(22px, min(3.2vw, 4.6vh), 40px) * var(--zoom)); display: inline-flex; flex: none; border-radius: calc(var(--dw) * .16); padding: calc(var(--dw) * .06);
  /* the light comes from the top of the screen and the tile's thickness shows below it, whichever way the tile
     is turned: --rot is how far it is turned, so the shading is turned back by as much */
  --sx: sin(var(--rot, 0deg)); --sy: cos(var(--rot, 0deg));
  background: linear-gradient(calc(180deg - var(--rot, 0deg)), #fffdf6, #eee6d2);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18), calc(var(--sx) * 2px) calc(var(--sy) * 2px) 0 #b9ae93, calc(var(--sx) * 3px) calc(var(--sy) * 3px) 8px rgba(0,0,0,.4);
}
.dm .dh { position: relative; width: var(--dw); height: var(--dw); }
.dm .dh .pp { position: absolute; inset: 0; }
/* a tile lying down has its pips turned with it, as on the real tiles */
.dm.h .dh .pp { transform: rotate(90deg); }
.dm .dh i {
  position: absolute; width: 19%; height: 19%; border-radius: 50%; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 38% 35%, rgba(255,255,255,.45) 0 18%, transparent 30%), var(--nc, #111);
  box-shadow: inset 0 -1px 1px rgba(0,0,0,.35);
}
.dm .dh.n10 i, .dm .dh.n11 i, .dm .dh.n12 i { width: 14%; height: 14%; }
/* the black bar between the two halves, as on the real tiles */
.dm .dh + .dh { border-left: 0; box-shadow: -1px 0 0 0 transparent; }
.dm .dh + .dh::before { content: ''; position: absolute; left: -1px; top: 18%; bottom: 18%; width: 3px; border-radius: 2px; background: #1c1c1c; }
.dm.v .dh + .dh::before, .dm.dbl .dh + .dh::before { left: 18%; right: 18%; top: -1px; bottom: auto; width: auto; height: 3px; }
/* each number's pip color, matched to the Cardinal color-dot set */
.dh.n1 { --nc: #3d9be0; } .dh.n2 { --nc: #2f9d48; } .dh.n3 { --nc: #e23b3b; } .dh.n4 { --nc: #7b4320; }
.dh.n5 { --nc: #1f55c9; } .dh.n6 { --nc: #f2b01e; } .dh.n7 { --nc: #b4359b; } .dh.n8 { --nc: #0f8c7a; }
.dh.n9 { --nc: #3f2b7a; } .dh.n10 { --nc: #f07c1c; } .dh.n11 { --nc: #7d1530; } .dh.n12 { --nc: #9b9b9b; }
.dm.v, .dm.dbl { flex-direction: column; }

.dm.landed { animation: ccland .35s cubic-bezier(.2, 1.4, .4, 1) both; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18), 0 0 0 3px var(--gold), calc(var(--sx) * 3px) calc(var(--sy) * 3px) 8px rgba(0,0,0,.4); }
.dm-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 3px; max-width: 100%; padding: 14px; min-height: 90px; border-radius: 18px; background: rgba(0,0,0,.18); }
.dm-end {
  min-width: 2.2em; height: 2.2em; border-radius: 50%; border: 2px dashed var(--line-strong); background: transparent; color: var(--muted);
  font-family: var(--display); font-weight: 700; font-size: 1.1em; cursor: default; margin: 0 6px;
}
.dm-end.on { cursor: pointer; border: 3px solid var(--gold); color: #2a1f00; background: linear-gradient(var(--gold-hi), var(--gold)); animation: deckglow 1.2s ease-in-out infinite; }
.dm-bone { color: var(--muted); font-weight: 700; }
.dm-bone b { color: #fff; }
.hand.dmhand { gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.hand.dmhand .dm { --dw: calc(clamp(28px, min(4.6vw, 5.5vh), 48px) * var(--zoom)); }
.dmbtn { padding: 0; border: 0; background: none; border-radius: 8px; transition: transform .15s ease; }
.dmbtn.ok { cursor: pointer; transform: translateY(-10px); }
.dmbtn.ok .dm { box-shadow: inset 0 0 0 1px rgba(0,0,0,.18), 0 0 0 3px var(--gold), 0 6px 14px rgba(0,0,0,.45); }

.dmbtn.sel { transform: translateY(-22px); }
.dmbtn.sel .dm { box-shadow: 0 0 0 4px #1fa3ff, 0 0 18px rgba(31,163,255,.7); }
.dmbtn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.gart .dm { --dw: 17px; }

/* Dominoes: the engine in the middle, every train heading out toward its player's face */
.ct-table.mtrain { gap: 6px; padding: 0; }
/* a table made bigger than the screen (the Table slider) scrolls, rather than being cut off on the left or top */
.ct-table.mtrain { max-width: none; width: max-content; min-width: 100%; align-items: safe center; }
main.cardgame #center:has(.mtrain) { place-items: safe center; }
.mt-head { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 14px; }
.mt-round { color: var(--muted); font-weight: 700; font-size: .9em; }
.mt-hub { position: relative; flex: none; }
/* the station: a black octagon, with a white slot in the middle for the engine */
.mt-station { position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none; overflow: visible; }
.mt-station path { fill: #161616; stroke: #000; stroke-width: 2; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.mt-engine { position: absolute; z-index: 3; transform: translate(-50%, -50%); display: grid; }
.mt-it.mt-under { opacity: 0; }   /* gone under the octagon (it slides there, fading) */
.mt-engine .dm { --dw: inherit; }
.mt-spoke { position: absolute; left: 0; top: 0; z-index: 1; width: 0; height: 0; transform-origin: 0 0; }
/* each piece of a train sits on the grid of half-tile squares: placed by its centre, turned in 90 degree steps */
.mt-it { position: absolute; left: 0; top: 0; display: grid; place-items: center; }
.mt-spoke .dm { --dw: inherit; flex: none; }
/* on the table the tile's thickness is a solid band straight down the screen: a train out to a corner shows it on
   both of its lower sides */
.mt-spoke .dm:not(.endpip), .mt-engine .dm {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.18), calc(var(--sx) * 1px) calc(var(--sy) * 1px) 0 #cfc5aa, calc(var(--sx) * 2px) calc(var(--sy) * 2px) 0 #bdb295,
    calc(var(--sx) * 3px) calc(var(--sy) * 3px) 0 #a99d80, calc(var(--sx) * 3px) calc(var(--sy) * 4px) 6px rgba(0,0,0,.4);
}
.mt-spoke.open .dm:not(.endpip) { box-shadow: 0 0 0 3px var(--bad), 0 0 14px rgba(255,77,64,.55); }
.mt-spoke.dropok .dm:not(.endpip) { box-shadow: 0 0 0 3px var(--gold), 0 0 14px rgba(255,207,51,.6); }
.mt-spoke.mt-new .dm-end { outline: 2px dashed var(--gold); outline-offset: 3px; }
.mt-it.mt-mk { z-index: 3; pointer-events: none; }
/* the toy trains and pennies sit on top of the octagon, above everything else in the middle */
.mt-mks { position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; }
.mt-mk2 { position: absolute; display: grid; place-items: center; transform: translate(-50%, -50%); pointer-events: auto; }
.mt-it.mt-flag { z-index: 4; pointer-events: none; }
.mt-more { color: #fff; font-weight: 700; font-size: calc(var(--dw) * .6); text-shadow: 0 1px 2px #000; white-space: nowrap; }
.mt-spoke .dm-end { width: calc(var(--dw) * 1.6); height: calc(var(--dw) * 1.6); min-width: 0; margin: 0; font-size: 1em; }
.mt-spoke .dm-end .dm.endpip { --dw: calc(var(--dw) * 1.0); }
.mt-opendbl { display: block; transform: translateY(calc(var(--dw) * -1.3)); padding: 0 .5em; border-radius: 999px; background: var(--bad); color: #fff; font-size: .75em; white-space: nowrap; }
.mt-spoke.mt-new .toy, .mt-mk2.ghostmk .toy { opacity: .6; }

/* a toy locomotive (community trains) */
.toy { width: calc(var(--dw, 24px) * 1.5); height: auto; filter: drop-shadow(0 2px 2px rgba(0,0,0,.45)); }
.toy .tb { fill: var(--tc); stroke: rgba(0,0,0,.35); stroke-width: .8; }
.toy .tw { fill: var(--tc); stroke: rgba(0,0,0,.5); stroke-width: 1.1; }
/* a penny (a player who couldn't play: anyone may play on their train) */
.penny {
  display: inline-grid; place-items: center; width: calc(var(--dw, 24px) * 1.2); height: calc(var(--dw, 24px) * 1.2); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f3c49a 0 12%, #c97a43 35%, #9a5426 75%, #7a3f1a 100%);
  box-shadow: inset 0 0 0 2px rgba(122,63,26,.9), inset 0 0 0 4px rgba(243,196,154,.35), 0 2px 3px rgba(0,0,0,.45);
  color: #5a2c0f; font-family: var(--display); font-weight: 700; font-size: calc(var(--dw, 24px) * .42); text-shadow: 0 1px 0 rgba(255,220,180,.6);
}
.mt-scores { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 14px; }
.mt-scores span { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.mt-scores .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rk); box-shadow: 0 0 0 2px rgba(255,255,255,.3); }
.mt-scores small { color: var(--soft); }
.hand.dmhand { flex-wrap: nowrap; gap: 5px; padding-top: 18px; }
/* the tiles shrink to fit the whole hand on one line */
.hand.dmhand .dm { --dw: min(calc(44px * var(--zoom)), calc((100cqw - (var(--n) - 1) * 5px - 24px) / var(--n) - 2px), 6vh); }

/* the dominoes tray's size slider and Fit (like the Number Tiles rack edge) */
.dmtools { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 2px 10px 0; }
.dmtools[hidden] { display: none; }
.dmtools label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.dmtools .dmlbl { font-size: .8em; white-space: nowrap; }
.dmtools input[type=range] { width: 140px; accent-color: var(--gold); cursor: pointer; }
.dmtools .sortbtn.on { background: linear-gradient(var(--gold-hi), var(--gold)); color: #2a1f00; }

/* the dominoes hand: a tray of slots (gaps allowed) to lay out trains and plan */
.hand.tray { user-select: none; -webkit-user-select: none; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; padding: 10px 8px 4px; min-height: 0; }
.trow { display: flex; gap: 4px; justify-content: center; }
.tslot {
  width: calc(var(--tdw) * 2.2 + 8px); height: calc(var(--tdw) * 1.12 + 8px); flex: none; display: grid; place-items: center;
  border-radius: 7px; background: rgba(0,0,0,.2); box-shadow: inset 0 1px 3px rgba(0,0,0,.35);
}
.tslot.tover { box-shadow: inset 0 0 0 3px var(--gold); background: rgba(255,207,51,.15); }
/* dragging onto the table: the train it would go on, and the tile waiting there for Confirm */
.mt-spoke.dropok { box-shadow: 0 0 0 3px var(--gold), 0 0 22px rgba(255,207,51,.7); }
.dm.pending { outline: 3px dashed var(--gold); outline-offset: 2px; animation: pendpulse 1s ease-in-out infinite alternate; }
@keyframes pendpulse { to { outline-color: rgba(255,207,51,.35); } }
@media (prefers-reduced-motion: reduce) { .dm.pending { animation: none; } }
.ttile { padding: 0; border: 0; background: none; cursor: grab; touch-action: none; border-radius: 6px; transition: transform .12s ease; }
.hand.tray .ttile .dm, .tghost .dm { --dw: var(--tdw); }
.ttile.ok .dm { box-shadow: inset 0 0 0 1px rgba(0,0,0,.18), 0 0 0 3px var(--gold), 0 4px 10px rgba(0,0,0,.45); }

.ttile.sel { transform: translateY(-5px); }
.ttile.sel .dm { box-shadow: 0 0 0 4px #1fa3ff, 0 0 16px rgba(31,163,255,.7); filter: none; }
.ttile.away { opacity: .25; }
.ttile:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.tghost { position: fixed; left: 0; top: 0; z-index: 95; pointer-events: none; padding: 0; border: 0; background: none; transition: none !important; will-change: transform; filter: drop-shadow(0 8px 14px rgba(0,0,0,.5)); }
body.traydragging, body.traydragging * { cursor: grabbing !important; user-select: none; }

/* the helper view: dominoes in a hand are hidden like cards */
.dm.hid .dh { background: repeating-linear-gradient(45deg, #d9cfb7 0 4px, #cbbf9f 4px 8px); }

/* the helper in control */
.vhead .vctl.on { background: linear-gradient(180deg, #ff7a6e, var(--bad)); color: #fff; box-shadow: none; }
#viewer.controlling .vwrap { box-shadow: 0 0 0 3px var(--gold), 0 0 30px rgba(255,207,51,.4); }
#helpBanner.ctl { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold), var(--shadow-3); }
#helpBanner .btn + .btn { margin-left: 6px; }
.helpping {
  position: fixed; z-index: 95; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; pointer-events: none;
  border: 4px solid var(--gold); box-shadow: 0 0 18px rgba(255,207,51,.8); animation: helpping .7s ease-out forwards;
}
@keyframes helpping { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .islot .idown.pick .pc, .dm-end.on, .ct-pile .pc.landed, .ht-card .pc, .dm.landed { animation: none; }
}
@media (max-width: 640px) {
  .ct-spot { padding: 5px 6px; border-width: 2px; }
  .ct-table { --cw: calc(36px * var(--zoom)); }
}
