/* The cribbage table (layouts/partials/cribbage-table.html, drawn by js/cribbage-table.js), shared by the
   vs-computer, online and friend games. Every zone has a fixed height derived from the card size, so the
   table never shifts while playing; results open as overlays. Card faces: css/cards.css. */

.ct {
  /* card width scales with the screen so six cards fit a phone; everything else follows it */
  --cw: clamp(40px, calc((min(100vw, 700px) - 76px) / 6.6), 62px);
  --ch: calc(var(--cw) * 1.4);
  --pw: calc(var(--cw) * .8);          /* pegging pile cards */
  --ph: calc(var(--pw) * 1.4);
  --ow: calc(var(--cw) * .66);         /* opponent's card backs */
  --oh: calc(var(--ow) * 1.4);
  --mw: clamp(24px, calc(var(--cw) * .58), 32px); /* results cards */
  --me: #66bb6a; --opp: #64b5f6; --gold: #ffd54f;
  position: relative; max-width: 700px; width: 100%; margin: 0 auto; box-sizing: border-box;
  padding: 10px; border-radius: 14px; color: #fff;
  font-family: 'Maven Pro', 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #0d1f15 0%, #1e3a29 40%, #142a1e 60%, #1e3a29 100%);
  overflow: hidden;
}
.ct *, .ct *::before, .ct *::after { box-sizing: border-box; }
.ct b, .ct strong { color: inherit; }
.ct [hidden] { display: none !important; }

/* ── Scoreboard ── */
.ct-board { display: flex; gap: 8px; align-items: stretch; background: rgba(255, 255, 255, .05); border-radius: 10px; padding: 6px 8px; }
.ct-players { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ct-player { display: flex; align-items: center; gap: 8px; height: 40px; padding: 2px 6px; border-radius: 8px; transition: background .3s; }
.ct-player.is-turn { background: rgba(255, 255, 255, .07); }
.ct-avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: .66em; font-weight: 800;
  background: rgba(255, 255, 255, .12); color: #fff;
}
.ct-player[data-who="me"] .ct-avatar { background: #2e7d32; }
.ct-player[data-who="opp"] .ct-avatar { font-size: 1em; }
.ct-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ct-pmain { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ct-pline { display: flex; align-items: center; gap: 6px; min-width: 0; height: 20px; }
.ct-name { font-weight: 700; font-size: .9em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ct-dealer { flex-shrink: 0; font-size: .62em; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 2px 6px; border-radius: 5px; background: rgba(255, 213, 79, .18); color: var(--gold); }
.ct-turn { flex-shrink: 0; font-size: .66em; font-weight: 700; color: #b9f6ca; animation: ctPulse 1.4s ease-in-out infinite; }
.ct-player[data-who="opp"] .ct-turn { color: #bbdefb; }
.ct-score { margin-left: auto; flex-shrink: 0; position: relative; display: flex; align-items: baseline; gap: 2px; }
.ct-score-val { font-size: 1.2em; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.ct-score small { font-size: .62em; color: rgba(255, 255, 255, .45); }
.ct-delta { position: absolute; right: 100%; top: -2px; margin-right: 4px; font-weight: 800; font-size: .8em; padding: 1px 6px; border-radius: 999px; opacity: 0; pointer-events: none; white-space: nowrap; color: #0b1a10; }
.ct-player[data-who="me"] .ct-delta { background: var(--me); }
.ct-player[data-who="opp"] .ct-delta { background: var(--opp); }
.ct-delta.is-on { animation: ctDelta 1.6s ease-out forwards; }
/* pegboard track: back peg (previous score) and front peg (score now), skunk line at 91 */
.ct-track { position: relative; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .1); }
.ct-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 4px; transition: width .7s ease; }
.ct-player[data-who="me"] .ct-fill { background: linear-gradient(90deg, #2e7d32, var(--me)); }
.ct-player[data-who="opp"] .ct-fill { background: linear-gradient(90deg, #1565c0, var(--opp)); }
.ct-skunk { position: absolute; left: 75.2%; top: -2px; bottom: -2px; width: 2px; background: rgba(255, 255, 255, .35); }
.ct-peg { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; left: 0; transition: left .7s ease; border: 2px solid #0d1f15; }
.ct-peg-back { background: rgba(255, 255, 255, .55); }
.ct-peg-front { background: #fff; box-shadow: 0 0 6px rgba(255, 255, 255, .8); }
.ct-tools { display: flex; flex-direction: column; justify-content: center; gap: 4px; flex-shrink: 0; }

.ct-timer { height: 4px; margin: 6px 2px 2px; border-radius: 2px; background: rgba(255, 255, 255, .06); overflow: hidden; }
#ct-timer-bar { display: block; height: 100%; width: 0; background: var(--me); transition: width .25s linear, background .3s; }
.ct-mode-label:empty { display: none; }
.ct-mode-label { text-align: center; font-size: .8em; font-weight: 700; color: #ffd740; background: rgba(255, 215, 0, .1); border: 1px solid rgba(255, 215, 0, .25); border-radius: 8px; padding: 4px 10px; margin: 4px 0 0; }

/* ── Play area: fixed heights ── */
.ct-play { position: relative; margin-top: 6px; }
.ct-hand { display: flex; justify-content: center; align-items: center; gap: 4px; border-radius: 12px; background: rgba(0, 0, 0, .22); }
.ct-opp-hand { height: calc(var(--oh) + 12px); }
.ct-opp-hand .ct-card { width: var(--ow); height: var(--oh); }
.ct-opp-hand .ct-card + .ct-card { margin-left: calc(var(--ow) * -.35); }
.ct-my-hand { height: calc(var(--ch) + 24px); padding-top: 10px; align-items: center; }
.ct-my-hand .ct-card { width: var(--cw); height: var(--ch); }

.ct-table {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  height: calc(var(--ph) + 50px); margin: 6px 0; padding: 6px 8px;
  background: rgba(0, 0, 0, .2); border-radius: 12px; border: 1px solid rgba(255, 255, 255, .05);
}
.ct-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.ct-label { font-size: .64em; color: rgba(255, 255, 255, .45); text-transform: uppercase; letter-spacing: 1px; white-space: nowrap; }
.ct-cardslot { position: relative; width: var(--pw); height: var(--ph); border-radius: 7px; border: 1px dashed rgba(255, 255, 255, .18); }
.ct-cardslot .ct-card { position: absolute; inset: 0; width: 100%; height: 100%; }
/* the crib: a small stack with its size */
.ct-cardslot .ct-stack:nth-child(2) { transform: translate(2px, -2px); }
.ct-cardslot .ct-stack:nth-child(3) { transform: translate(4px, -4px); }
.ct-cardslot .ct-stack:nth-child(4) { transform: translate(6px, -6px); }
.ct-badge { position: absolute; right: -8px; bottom: -8px; z-index: 5; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #0d1f15; border: 1px solid rgba(255, 255, 255, .3); font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
/* pegging pile: up to 8 overlapping cards in a fixed width */
.ct-pile-slot { position: relative; }
.ct-pile { display: flex; justify-content: center; align-items: center; height: calc(var(--ph) + 6px); width: calc(var(--pw) * 4.6); }
.ct-pile .ct-card { width: var(--pw); height: var(--ph); flex-shrink: 0; }
.ct-pile .ct-card + .ct-card { margin-left: calc(var(--pw) * -.48); }
.ct-count { font-weight: 800; font-size: .9em; background: rgba(0, 0, 0, .45); padding: 2px 12px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.ct-count.is-hot { color: var(--gold); }

/* status: two lines, fixed height */
.ct-status {
  height: 4.3em; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; font-size: .95em; line-height: 1.35; padding: 0 10px; margin: 0 0 6px;
  background: rgba(0, 0, 0, .3); border-radius: 10px; color: rgba(255, 255, 255, .92); overflow: hidden;
}
.ct-status .ct-note { font-size: .86em; color: var(--gold); }
.ct-status > * { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ct-status > .ct-note { -webkit-line-clamp: 1; }

.ct-actions { height: 50px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.ct-options { height: 32px; display: flex; align-items: center; justify-content: center; gap: 14px; color: rgba(255, 255, 255, .65); font-size: .82em; }
.ct-options label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ct-options input { width: 18px; height: 18px; accent-color: #4caf50; }

/* ── Cards ── */
.ct-card { flex-shrink: 0; transition: transform .18s, box-shadow .18s, opacity .18s; }
.ct-card.is-pickable, .ct-card.is-playable { cursor: pointer; }
.ct-card.is-pickable:hover { transform: translateY(-5px); }
.ct-card.is-selected { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--gold), 0 0 14px rgba(255, 213, 79, .7) !important; }
.ct-card.is-playable { box-shadow: 0 0 0 2px var(--gold), 0 0 12px 2px rgba(255, 213, 79, .55); animation: ctGlow 1.6s ease-in-out infinite; }
.ct-card.is-playable:hover { transform: translateY(-6px); }
.ct-card.is-dim { opacity: .35; }
.ct-card.is-hint { outline: 3px dashed #69f0ae; outline-offset: 2px; }
/* who played each pegging card */
.ct-pile .is-mine { box-shadow: 0 0 0 2px var(--me), 2px 2px 6px rgba(0, 0, 0, .4); }
.ct-pile .is-theirs { box-shadow: 0 0 0 2px var(--opp), 2px 2px 6px rgba(0, 0, 0, .4); }
.ct-pile [data-who]::after {
  content: attr(data-who); position: absolute; left: 50%; bottom: 3px; transform: translateX(-50%); z-index: 2;
  font: 700 9px/1 system-ui, sans-serif; padding: 2px 4px; border-radius: 4px; color: #0b1a10;
}
.ct-pile .is-mine::after { background: #a5d6a7; }
.ct-pile .is-theirs::after { background: #90caf9; }
.ct-callout {
  position: absolute; left: 50%; top: -4px; transform: translateX(-50%); z-index: 6; white-space: nowrap;
  font-weight: 800; font-size: .88em; padding: 3px 10px; border-radius: 999px; pointer-events: none; color: #0b1a10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4); animation: ctCallout 2.2s ease-out forwards;
}
.ct-callout.is-mine { background: var(--me); }
.ct-callout.is-theirs { background: var(--opp); }
.ct-fly { position: fixed; z-index: 60; pointer-events: none; margin: 0; }

/* ── Buttons ── */
.ct-btn { display: inline-flex; align-items: center; justify-content: center; height: 40px; padding: 0 18px; border: none; border-radius: 9px; font: 700 .95em 'Maven Pro', system-ui, sans-serif; cursor: pointer; text-decoration: none; white-space: nowrap; transition: opacity .15s, transform .15s; }
.ct-btn:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.ct-btn:disabled { opacity: .45; cursor: not-allowed; }
.ct-btn-sm { height: 30px; padding: 0 10px; font-size: .78em; }
.ct-btn-primary { background: #43a047; color: #fff; }
.ct-btn-warning { background: #fb8c00; color: #fff; }
.ct-btn-ghost { background: rgba(255, 255, 255, .13); color: #fff; border: 1px solid rgba(255, 255, 255, .25); }
.ct-btn-daily, .ct-btn-share { background: #f5b731; color: #222; }
.ct-btn.is-ready { animation: ctReady 1.2s ease-in-out infinite; }

/* ── Overlays ── */
.ct-overlay { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 14px; background: #08140d; border-radius: 12px; overflow: auto; animation: ctFade .25s ease-out; }
.ct-gameover { z-index: 30; text-align: center; }
.ct-res-title { font-weight: 800; color: var(--gold); font-size: 1.05em; text-align: center; }
.ct-res-grid { display: grid; grid-template-columns: max-content max-content max-content; column-gap: 10px; row-gap: 2px; align-items: center; justify-content: center; max-width: 100%; }
.ct-res-label { font-weight: 700; font-size: .88em; text-align: right; white-space: nowrap; }
.ct-res-cards { display: flex; align-items: center; gap: 3px; }
.ct-res-cards .ct-card { width: var(--mw); height: calc(var(--mw) * 1.4); }
.ct-res-cards .ct-starter { margin-left: 5px; box-shadow: 0 0 0 2px var(--gold); }
.ct-res-pts { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; text-align: right; min-width: 2.6em; }
.ct-res-detail { grid-column: 2 / 4; font-size: .74em; color: rgba(255, 255, 255, .6); margin: 0 0 6px; line-height: 1.3; }
.ct-res-foot { margin-top: 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .9em; color: rgba(255, 255, 255, .75); }
.ct-go-title { font-size: 1.9em; font-weight: 800; color: var(--gold); }
.ct-go-sub { color: rgba(255, 255, 255, .75); }
.ct-go-scores { display: flex; gap: 22px; }
.ct-go-score { background: rgba(255, 255, 255, .06); border-radius: 10px; padding: 8px 18px; }
.ct-go-score small { display: block; font-size: .75em; color: rgba(255, 255, 255, .55); }
.ct-go-score b { font-size: 1.6em; color: #fff; }
.ct-go-stats { font-size: .85em; color: rgba(255, 255, 255, .6); min-height: 1.2em; }
.ct-go-actions { display: flex; flex-direction: column; gap: 8px; width: min(260px, 100%); }
.ct-go-actions .ct-btn { width: 100%; }
.ct-go-note { font-size: .85em; color: #81c784; min-height: 1.1em; }

/* ── Animations ── */
@keyframes ctGlow { 0%, 100% { box-shadow: 0 0 0 2px rgba(255, 213, 79, .55), 0 0 8px 1px rgba(255, 213, 79, .4); } 50% { box-shadow: 0 0 0 3px rgba(255, 224, 130, .85), 0 0 16px 4px rgba(255, 213, 79, .8); } }
@keyframes ctPulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes ctReady { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 213, 79, 0); } 50% { box-shadow: 0 0 0 6px rgba(255, 213, 79, .35); } }
@keyframes ctDelta { 0% { opacity: 0; transform: translateY(6px) scale(.8); } 15% { opacity: 1; transform: translateY(0) scale(1.08); } 75% { opacity: 1; transform: translateY(-4px); } 100% { opacity: 0; transform: translateY(-10px); } }
@keyframes ctCallout { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.9); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 80% { opacity: 1; transform: translate(-50%, -6px); } 100% { opacity: 0; transform: translate(-50%, -14px); } }
@keyframes ctFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ctDeal { from { opacity: 0; transform: translateY(-16px) scale(.92); } to { opacity: 1; transform: none; } }
.ct-card.is-dealt { animation: ctDeal .35s ease-out both; }

/* Breadcrumbs under the board */
.ct-crumbs { margin: 14px 0 4px; }
.ct-crumbs .breadcrumbs { margin: 0; }

/* Phones: the table runs edge to edge, out of the page's side padding (.container: --space-lg, and
   --space-md at 480px and below). Not 100vw, which counts a desktop scrollbar and would overhang. */
@media (max-width: 600px) {
  .ct { --bleed: var(--space-lg, 24px); width: calc(100% + 2 * var(--bleed)); max-width: none;
        margin-left: calc(-1 * var(--bleed)); margin-right: calc(-1 * var(--bleed)); border-radius: 0;
        --cw: clamp(40px, calc((100vw - 52px) / 6.4), 62px); }
}
@media (max-width: 480px) {
  .ct { --bleed: var(--space-md, 16px); }
  /* the mode's buttons go under the scoreboard so names have the full width */
  .ct-board { flex-direction: column; gap: 4px; }
  .ct-tools { flex-direction: row; justify-content: flex-end; }
}
@media (max-width: 420px) {
  .ct { padding: 8px; }
  .ct-board { padding: 5px 6px; }
  .ct-player { gap: 6px; padding: 2px 4px; }
  .ct-btn { padding: 0 14px; }
  .ct-status { font-size: .88em; }
}
@media (prefers-reduced-motion: reduce) {
  .ct *, .ct-fly { animation: none !important; transition: none !important; }
  .ct-delta.is-on { opacity: 1; }
}
