/* =========================================================================
   SKYJO — UI
   Concept: a typeset scorepad. Skyjo is one long piece of arithmetic —
   every card is a number, every turn nudges a sum, the whole game is a
   race to keep your total below everyone else's before someone hits 100
   and loses. So numerals lead, and colour does the reading for you:
   cards sit on a diverging violet -> teal -> amber -> brick scale
   (cool = good, hot = bad), and each player carries a "heat bar" that
   fills toward 100 — the scoreboard reimagined as a race to lose.
   ========================================================================= */

:root {
  color-scheme: light dark;

  --paper:      #F4F1EA;
  --surface:    #FFFFFF;
  --ink:        #1C1B18;
  --ink-dim:    #6E6A5E;
  --rule:       #DAD4C6;
  --accent:     #1E3AE0;
  --accent-ink: #FFFFFF;
  --danger:     #C4402C;

  /* diverging card scale (value -2 .. 12) */
  --c-neg:  #5A32A3;
  --c-zero: #2F7DA8;
  --c-low:  #4E9E7E;
  --c-mid:  #D99A2B;
  --c-high: #C4402C;

  --card-back-bg:   #2A251F;
  --card-back-line: rgba(255,255,255,0.20);

  --font-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --font-ui: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --card-radius: 14px;
  --gap: clamp(4px, 1.6vw, 8px);
  --shadow: 0 1px 2px rgba(0,0,0,0.08), 0 10px 28px -14px rgba(0,0,0,0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #151411;
    --surface:    #211F1B;
    --ink:        #ECE7DA;
    --ink-dim:    #9A9484;
    --rule:       #332F27;
    --accent:     #7E90FF;
    --accent-ink: #0B0B14;
    --danger:     #E8604A;

    --c-neg:  #9B7BE0;
    --c-zero: #5AB0D8;
    --c-low:  #63C9A0;
    --c-mid:  #F0B44A;
    --c-high: #E8604A;

    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 14px 34px -16px rgba(0,0,0,0.65);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

.hidden { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- shared bits ------------------------------------------------------- */
.btn {
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn:not(:disabled):hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--rule); color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  line-height: 1;
  color: var(--ink);
}
.wordmark-dot { color: var(--accent); }
.wordmark-sm { font-size: 1.15rem; }

.eyebrow {
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: center;
}

.error {
  color: var(--danger);
  font-size: 0.88rem;
  min-height: 1.2em;
  text-align: center;
}

/* ---- screens --------------------------------------------------------- */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* ---- menu ------------------------------------------------------------- */
#screen-menu { position: relative; overflow: hidden; }
#screen-menu::before,
#screen-menu::after {
  content: "";
  position: absolute;
  border: 2px solid var(--rule);
  pointer-events: none;
}
#screen-menu::before {
  width: min(66vw, 360px); aspect-ratio: 5 / 7;
  border-radius: 24px; transform: rotate(-12deg) translate(-30px, 0);
  opacity: 0.55;
}
#screen-menu::after {
  width: min(44vw, 220px); aspect-ratio: 5 / 7;
  border-radius: 18px; transform: rotate(10deg) translate(70px, 30px);
  opacity: 0.3;
}

.menu-card, .lobby-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tagline { color: var(--ink-dim); font-size: 0.95rem; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
input {
  font: inherit;
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ink);
}
input::placeholder { color: var(--ink-dim); }
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--ink-dim); font-size: 0.8rem; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--rule); }

.join-row { display: flex; gap: 8px; }
.code-input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.4em;
  font-family: var(--font-display);
  font-weight: 700;
}

/* ---- lobby ---------------------------------------------------------- */
.lobby-card { text-align: center; }
.room-code {
  align-self: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 12vw, 3rem);
  letter-spacing: 0.22em;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px 4px 12px;
  border-radius: 10px;
}
.room-code:hover { background: var(--paper); }
.room-code::after { content: " ⧉"; font-size: 0.36em; color: var(--ink-dim); letter-spacing: 0; vertical-align: middle; }
.room-code.copied::after { content: " copié ✓"; color: var(--c-low); }
.room-code-hint { color: var(--ink-dim); font-size: 0.82rem; }

.seat-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.seat-list li {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.seat-list li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c-low); flex: 0 0 auto; }
.seat-list li.disconnected { opacity: 0.5; }
.seat-list li.disconnected::before { background: var(--ink-dim); }

.wait-note { color: var(--ink-dim); font-size: 0.9rem; }

/* ---- game shell --------------------------------------------------- */
#screen-game {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px 40px;
  min-height: 100dvh;
}

.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}
.round-chip {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.round-chip:empty { display: none; }

/* ---- opponents rail --------------------------------------------- */
.opp-rail {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scroll-snap-type: x proximity;
}
.opp-rail:empty { display: none; }
.opp {
  flex: 0 0 auto;
  scroll-snap-align: start;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 128px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.opp.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.opp.disconnected { opacity: 0.45; }
.opp-head {
  display: flex;
  align-items: center;
  gap: 6px;
  align-self: stretch;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
}
.turn-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
  animation: pulse 1.6s ease-in-out infinite;
}
.opp-total {
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--ink-dim);
}
.opp .heat { align-self: stretch; }

/* ---- table (piles) -------------------------------------------- */
.table {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(18px, 7vw, 48px);
  padding: 6px 0;
}
.pile-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: clamp(66px, 20vw, 92px);
}
.pile { width: 100%; }
.pile-label {
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.pile-count {
  position: absolute;
  bottom: -7px;
  right: -7px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-dim);
}
#pending-wrap .card { animation: pulse-ring 1.6s ease-in-out infinite; }

/* ---- hint ---------------------------------------------------- */
.hint {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1rem, 3.6vw, 1.35rem);
  min-height: 1.5em;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--ink-dim);
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.hint--you {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 32%, transparent);
}

/* ---- my area ------------------------------------------------ */
.my-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.my-footer {
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.my-name { font-weight: 600; }
.my-score {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
}
.my-heat { width: min(90vw, 360px); }

/* ---- cards ------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  perspective: 900px;
}
.grid-lg { width: min(90vw, 360px); }
.grid-sm { width: clamp(94px, 24vw, 120px); gap: 3px; }

.card {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: var(--card-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: #fff;
  box-shadow: var(--shadow);
}
.grid-lg .card { font-size: clamp(1.4rem, 7vw, 2.1rem); }
.grid-sm .card { font-size: 0.6rem; border-radius: 6px; box-shadow: none; }

.card-neg  { background: var(--c-neg);  color: #F4EEFF; }
.card-zero { background: var(--c-zero); color: #ECF7FD; }
.card-low  { background: var(--c-low);  color: #082019; }
.card-mid  { background: var(--c-mid);  color: #2A1D00; }
.card-high { background: var(--c-high); color: #FFF1EE; }

.card-back {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.06), rgba(0,0,0,0.14)),
    var(--card-back-bg);
  color: transparent;
  border: 1px solid var(--card-back-line);
}
.card-back::after {
  content: "";
  position: absolute;
  width: 32%;
  aspect-ratio: 1;
  transform: rotate(45deg);
  border: 1.5px solid var(--card-back-line);
  border-radius: 3px;
}
.grid-sm .card-back::after { border-width: 1px; }
.card-empty {
  background: transparent;
  border: 1.5px dashed var(--rule);
  box-shadow: none;
}
.card-removed { background: transparent; box-shadow: none; }

.card.clickable { cursor: pointer; }
.grid-lg .card.clickable { transition: transform 0.12s ease; }
.grid-lg .card.clickable:hover { transform: translateY(-6px); }
.card.clickable::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  border: 2px solid var(--accent);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.card.clickable:hover::before,
.card.clickable:focus-visible::before { opacity: 1; }

.card--flip { animation: flip-in 0.32s ease-out; backface-visibility: hidden; }

@keyframes flip-in {
  0%   { transform: rotateY(90deg); opacity: 0; }
  60%  { transform: rotateY(-8deg); }
  100% { transform: rotateY(0); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@keyframes pulse-ring {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent), var(--shadow); }
}

/* ---- heat bar (signature) --------------------------------- */
.heat {
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  overflow: hidden;
}
.heat-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 0.4s ease, background 0.4s ease;
}

/* ---- scoreboard ------------------------------------------ */
.scoreboard {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(300px, 82vw);
  background: var(--surface);
  border-left: 1px solid var(--rule);
  padding: 20px 18px;
  z-index: 25;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.28s ease;
}
.scoreboard--open { transform: translateX(0); }
.scoreboard h2 {
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 14px;
}
#scoreboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.score-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 2px 10px;
}
.score-row .nm { font-weight: 600; }
.score-row .val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}
.score-row .heat { grid-column: 1 / -1; margin-top: 7px; }
.score-row.me .nm { color: var(--accent); }
.scoreboard-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-size: 0.74rem;
  color: var(--ink-dim);
  text-align: center;
}

#scores-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 24;
}

/* ---- overlay ------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}
.overlay-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 20px;
  padding: 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}
.overlay-card h2 { font-family: var(--font-display); font-size: 1.5rem; color: var(--ink); }
.overlay-sub { color: var(--ink-dim); }
.overlay-scores {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.overlay-scores li {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* ---- reconnect banner --------------------------------- */
.reconnect-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 10px 14px;
  z-index: 50;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.reconnect-banner .btn-ghost { border-color: rgba(255,255,255,0.55); color: #fff; }

/* ---- desktop ----------------------------------------- */
@media (min-width: 1080px) {
  #screen-game { max-width: 620px; padding-top: 24px; gap: 14px; }

  .opp-rail { flex-wrap: wrap; justify-content: center; overflow: visible; }
  .grid-lg { width: 320px; }
  .my-heat { width: 320px; }
  .table { gap: 40px; }

  .scoreboard {
    position: fixed;
    top: 50%;
    right: 24px;
    left: auto;
    height: auto;
    max-height: 82vh;
    width: 252px;
    border: 1px solid var(--rule);
    border-radius: 16px;
    box-shadow: var(--shadow);
    transform: translateY(-50%);
  }
  .scoreboard--open { transform: translateY(-50%); }

  #btn-scores-toggle { display: none; }
  #scores-backdrop { display: none !important; }
}
