/* gin.css — chrome for the Gin Rummy UI. Card geometry itself comes from
   cards.css (the library). Mobile-first. */

:root {
  --felt: #1f4a3d;
  --felt-edge: #143128;
  --chrome-ink: #e9f1ec;
  --dim: #9db8ad;
  --accent: #ffcf5c;
  --meld-a: #5aa9ff;
  --meld-b: #7bd88f;
  --meld-c: #d98cff;
  --meld-d: #ff9f68;
}
.dark { --felt: #14261f; --felt-edge: #0b1712; --dim: #7f978c; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--chrome-ink);
  background: radial-gradient(130% 120% at 50% -10%, var(--felt) 0%, var(--felt-edge) 100%) fixed;
}

.page { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.page__head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px clamp(10px, 3vw, 18px);
}
.page__head h1 { font-size: clamp(16px, 4.2vw, 22px); margin: 0; letter-spacing: -0.01em; }
.difficulty { display: flex; gap: 6px; }
.difficulty button {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--chrome-ink);
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px; padding: 5px 11px; cursor: pointer;
}
.difficulty button[aria-pressed="true"] { background: var(--accent); color: #1a1200; border-color: var(--accent); }

#app { flex: 1; display: flex; }
.gin {
  position: relative; flex: 1;
  display: grid; grid-template-rows: auto 1fr auto 1fr auto;
  gap: clamp(6px, 1.5vh, 14px);
  padding: clamp(8px, 2.4vw, 18px);
}

.gin__scores { display: flex; align-items: center; justify-content: space-between; }
.score { display: grid; grid-auto-flow: column; align-items: baseline; gap: 6px; }
.score b { font-weight: 700; }
.score span { font-size: 20px; font-weight: 800; color: var(--accent); }
.score small { color: var(--dim); font-size: 11px; }
.gin__meta { color: var(--dim); font-size: 12px; text-align: center; }

.gin__hand { display: flex; align-items: center; justify-content: center; min-height: 0; position: relative; }
.gin__hand .card + .card { margin-left: calc(var(--card-w) * -1 * var(--ov)); }
.gin__hand--opp { align-items: flex-start; }
.gin__hand--you { align-items: flex-end; }
.gin__hand--you .card { touch-action: none; cursor: grab; }
.gin__hand--you .card.selectable { cursor: pointer; }
.card.dragging { transition: none !important; z-index: 30; cursor: grabbing;
  box-shadow: 0 14px 26px rgba(0,0,0,0.5); }
.drop-marker { position: absolute; top: 4%; bottom: 4%; width: 3px; margin-left: -1px;
  background: var(--accent); border-radius: 2px; box-shadow: 0 0 6px var(--accent);
  pointer-events: none; z-index: 25; }

.gin__center { display: flex; align-items: center; justify-content: center; gap: clamp(14px, 6vw, 48px); }
.pile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile__label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; }
.pile .slot {
  width: var(--card-w, 88px); aspect-ratio: 5 / 7; border-radius: calc(var(--card-w) * 0.09);
  border: 2px dashed rgba(255,255,255,0.28);
}
.card.is-stacked {
  box-shadow: calc(var(--card-w)*0.03) calc(var(--card-w)*0.03) 0 calc(var(--card-w)*-0.006) rgba(0,0,0,0.4),
              calc(var(--card-w)*0.06) calc(var(--card-w)*0.06) 0 calc(var(--card-w)*-0.012) rgba(0,0,0,0.3);
}
.pile.targetable { cursor: pointer; }
.pile.targetable .card, .pile.targetable .slot { box-shadow: 0 0 0 3px var(--accent); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,207,92,0.35); } }

/* human hand interactions */
.card.selectable { cursor: pointer; transition: transform 140ms ease; }
.card.selectable:hover { transform: translateY(-8px); }
.card.selected { transform: translateY(-16px); z-index: 6; }
.card.just-drew { box-shadow: 0 0 0 3px var(--accent); }

/* meld highlight on revealed / your hand */
.card.melded { border-radius: calc(var(--card-w) * 0.09); }
.card.meld-a { box-shadow: 0 0 0 3px var(--meld-a); }
.card.meld-b { box-shadow: 0 0 0 3px var(--meld-b); }
.card.meld-c { box-shadow: 0 0 0 3px var(--meld-c); }
.card.meld-d { box-shadow: 0 0 0 3px var(--meld-d); }
.card.deadcard { filter: grayscale(0.4) brightness(0.65); }

.gin__status { display: flex; flex-direction: column; gap: 8px; align-items: center; padding-top: 4px; }
.gin__msg { min-height: 20px; text-align: center; font-size: 14px; }
.gin__msg .s-hearts, .gin__msg .s-diamonds { color: #ff8a8a; font-weight: 700; }
.gin__msg .s-spades, .gin__msg .s-clubs { color: #fff; font-weight: 700; }
.gin__btns, .gin__util { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.gin__status button {
  font: inherit; font-size: 14px; font-weight: 650; cursor: pointer;
  border-radius: 999px; padding: 9px 18px; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08); color: var(--chrome-ink);
}
.gin__status button.primary { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.gin__status button.knock { background: #ff6b6b; color: #240000; border-color: #ff6b6b; }
.gin__status button.ghost { background: transparent; font-size: 12px; padding: 6px 12px; }
.gin__status button:disabled { opacity: 0.4; cursor: default; }

/* end-of-round reveal: both hands laid out by meld, result between them */
.gin--reveal { grid-template-rows: auto 1fr auto 1fr auto; }
.gin__reveal { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 0; }
.reveal__name { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.07em; }
.reveal__dw { font-size: 12px; color: var(--dim); }
.reveal__groups { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; }
.meldgrp { display: flex; padding: 3px; border-radius: 10px; }
.meldgrp .card + .card { margin-left: calc(var(--card-w) * -1 * var(--ov)); }
.meldgrp.meld-a { box-shadow: 0 0 0 2px var(--meld-a); }
.meldgrp.meld-b { box-shadow: 0 0 0 2px var(--meld-b); }
.meldgrp.meld-c { box-shadow: 0 0 0 2px var(--meld-c); }
.meldgrp.meld-d { box-shadow: 0 0 0 2px var(--meld-d); }
.meldgrp.deadgrp { flex-wrap: wrap; gap: 3px; max-width: 100%; }
.meldgrp.deadgrp .card + .card { margin-left: 0; }
.meldgrp.deadgrp .card { filter: grayscale(0.4) brightness(0.65); }

.gin__result { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; }
.gin__result-title { font-size: clamp(18px, 5vw, 24px); font-weight: 800; }
.gin__result-title.win { color: var(--accent); }
.gin__result-body { color: var(--dim); font-size: 13px; }
.gin__result-body .s-hearts, .gin__result-body .s-diamonds { color: #ff8a8a; }
.gin__result-final { margin-top: 4px; font-weight: 700; }

.gin__matchstats {
  display: grid; grid-template-columns: 1fr auto auto; gap: 2px 16px;
  margin: 8px auto 0; width: fit-content; font-size: 13px;
}
.ms-row { display: contents; }
.ms-label { text-align: left; color: var(--dim); }
.ms-val { text-align: right; font-variant-numeric: tabular-nums; min-width: 3ch; }
.ms-head .ms-label, .ms-head .ms-val {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dim);
}
.ms-total .ms-label, .ms-total .ms-val {
  font-weight: 800; padding-top: 3px; margin-top: 1px;
  border-top: 1px solid rgba(255,255,255,0.18);
}
.ms-total .ms-val { color: var(--accent); }

/* the end-of-round reveal restructures the whole board, so it fades in rather
   than FLIP-animating every card (which reads as chaotic). */
@keyframes ginReveal { from { opacity: 0; } to { opacity: 1; } }
.gin--reveal .gin__reveal, .gin--reveal .gin__result { animation: ginReveal 240ms ease both; }

@media (prefers-reduced-motion: reduce) {
  .gin--reveal .gin__reveal, .gin--reveal .gin__result { animation: none; }
}

@media (prefers-reduced-motion: reduce) { .pile.targetable .card, .pile.targetable .slot { animation: none; } .card { transition: none; } }

/* ---- header controls + settings modal --------------------------------- */
.head-controls { display: flex; gap: 6px; align-items: center; }
.head-controls button {
  font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.08); color: #fff;
}
.head-controls .gear { font-size: 16px; padding: 4px 9px; line-height: 1; }
.head-controls button:active { transform: translateY(1px); }

.gin-modal-overlay {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); padding: 20px; animation: ginModalIn 140ms ease;
}
.gin-modal {
  width: 100%; max-width: 340px; background: #23312c; color: #fff;
  border: 1px solid rgba(255,255,255,0.14); border-radius: 16px; padding: 18px 18px 16px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
}
.gin-modal__title { margin: 0 0 14px; font-size: 18px; }
.gin-modal__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.gin-modal__label { font-size: 14px; color: rgba(255,255,255,0.85); }
.gin-modal__seg { display: inline-flex; border-radius: 9px; overflow: hidden; border: 1px solid rgba(255,255,255,0.2); }
.seg-btn {
  font: inherit; font-size: 13px; padding: 6px 12px; cursor: pointer; color: #fff;
  background: rgba(255,255,255,0.06); border: none; border-right: 1px solid rgba(255,255,255,0.12);
}
.gin-modal__seg .seg-btn:last-child { border-right: none; }
.seg-btn.is-on { background: var(--accent); color: #1a1a1a; font-weight: 700; }
.seg-btn.toggle { border-radius: 9px; border: 1px solid rgba(255,255,255,0.2); min-width: 52px; }

.gin-modal__warn {
  display: none; font-size: 12.5px; color: #ffd166; background: rgba(255,209,102,0.1);
  border: 1px solid rgba(255,209,102,0.3); border-radius: 8px; padding: 8px 10px; margin: 4px 0 12px;
}
.gin-modal__warn.show { display: block; }
.gin-modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.gin-modal__actions button {
  font: inherit; font-size: 14px; padding: 8px 16px; border-radius: 9px; cursor: pointer; border: none;
}
.gin-modal__actions .ghost { background: rgba(255,255,255,0.1); color: #fff; }
.gin-modal__actions .primary { background: var(--accent); color: #1a1a1a; font-weight: 700; }
@keyframes ginModalIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .gin-modal-overlay { animation: none; } }
