/* Rook (games/rook.html) */

/* Team colors: Team 1 = navy, Team 2 = accent green */
.rook {
  --t0: var(--navy-400);
  --t1: var(--accent);
  --cw: clamp(46px, 11vw, 82px);      /* card width in your hand */
  --tw: clamp(44px, 11vw, 66px);      /* card width on the table */
  --felt: #1d5a46;
  --felt-dark: #154434;
  max-width: 900px;
  margin: 0 auto;
}

.rook .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Site .btn-outline is built for dark backgrounds; invert it on this light page */
.rook .btn-outline,
.rook-modal .btn-outline { color: var(--navy); border-color: var(--navy-100); background: var(--white); }
.rook .btn-outline:hover:not(:disabled),
.rook-modal .btn-outline:hover { color: var(--navy); border-color: var(--navy); background: var(--navy-50); }

/* .btn and the flex rows set display, which would otherwise beat the hidden attribute */
.rook [hidden] { display: none !important; }
.rook .neg { color: #c62828; }
.t0-text { color: var(--t0); }
.t1-text { color: var(--t1); }

/* Online status panel */
.rook-online {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  background: var(--warm);
  border: 1px solid var(--warm-dark);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.rook-online[hidden] { display: none; }
.rook-online-msg { margin-right: auto; color: var(--navy); }

.rook-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  margin-right: 0.25rem;
}

.rook-toggle input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.rook-idle {
  text-align: center;
  padding: 2.5rem 1rem;
  background: var(--grey-50);
  border: 1px solid var(--grey-100);
  border-radius: var(--radius-lg);
}

.rook-idle p { margin-bottom: 1rem; color: var(--grey-700); }

/* ---------- Lobby ---------- */
.rook-lobby-teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.rook-lobby-team h3 { font-size: 1rem; margin-bottom: 0.5rem; }

.rook-lobby-seat {
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border: 2px solid var(--grey-100);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--navy);
  font-weight: 600;
}

.rook-lobby-seat.empty { color: var(--grey-500); font-weight: 400; border-style: dashed; }
.rook-lobby-seat small { font-weight: 500; color: var(--grey-500); }
button.rook-lobby-seat { cursor: pointer; transition: border-color var(--transition), background var(--transition); }
button.rook-lobby-seat:hover { border-color: var(--navy-100); background: var(--navy-50); }
.rook-lobby-seat.picked { border-color: var(--warm-darker); background: var(--warm); }

.rook-lobby-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.rook-lobby-hint { text-align: center; font-size: 0.9rem; color: var(--grey-500); margin-bottom: 1rem; }

/* ---------- Scoreboard ---------- */
.rook-scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.rook-team {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  background: var(--grey-50);
  border-left: 4px solid var(--t0);
  min-width: 0;
}

.rook-team.t1 { border-left-color: var(--t1); text-align: right; border-left: 0; border-right: 4px solid var(--t1); }
.rook-team-label { display: block; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--grey-500); }
.rook-team-names { display: block; font-weight: 600; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rook-team-score { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.rook-team.t0 .rook-team-score { color: var(--t0); }
.rook-team.t1 .rook-team-score { color: var(--t1); }
.rook-team-taken { font-size: 0.8rem; color: var(--grey-500); }

.rook-handinfo {
  text-align: center;
  font-size: 0.85rem;
  color: var(--grey-700);
  line-height: 1.6;
}

.rook-handinfo strong { color: var(--navy); }

.rook-suit {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  color: var(--white);
  font-weight: 600;
  font-size: 0.8rem;
}

.rook-suit.r { background: #c62828; }
.rook-suit.g { background: #2e7d32; }
.rook-suit.y { background: #c99a06; }
.rook-suit.b { background: #222; }

.rook-status {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.75rem;
  min-height: 1.8rem;
}

/* ---------- Table ---------- */
.rook-felt {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas:
    ".    top    ."
    "left center right"
    ".    bottom .";
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.rook-seat {
  justify-self: center;
  text-align: center;
  color: var(--white);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  border: 2px solid transparent;
  min-width: 0;
  max-width: 100%;
  transition: border-color var(--transition), background var(--transition);
}

.rook-seat.pos-top { grid-area: top; }
.rook-seat.pos-left { grid-area: left; }
.rook-seat.pos-right { grid-area: right; }
.rook-seat.pos-bottom { grid-area: bottom; }
.rook-seat.turn { border-color: var(--warm-darker); background: rgba(252, 249, 238, 0.12); }
.rook-seat.away { opacity: 0.55; }

.rook-seat-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rook-seat-name::before {
  content: '';
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.35rem;
  background: var(--seat-color);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.rook-seat.t0 { --seat-color: var(--t0); }
.rook-seat.t1 { --seat-color: var(--t1); }
.rook-seat-meta { font-size: 0.75rem; opacity: 0.8; }

.rook-badge {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--warm);
  color: var(--navy);
}

.rook-badge.pass { background: rgba(255, 255, 255, 0.2); color: var(--white); }

.rook-center {
  grid-area: center;
  display: grid;
  grid-template-columns: repeat(3, var(--tw));
  /* Rows are shorter than a card, so the top and bottom cards tuck in toward the middle */
  grid-template-rows: calc(var(--tw) * 0.9) calc(var(--tw) * 0.6) calc(var(--tw) * 0.9);
  grid-template-areas:
    ".    top    ."
    "left mid    right"
    ".    bottom .";
  gap: 0.25rem;
  padding: calc(var(--tw) * 0.7) 0.5rem;
  place-items: center;
}

.rook-center .slot-top { grid-area: top; align-self: end; }
.rook-center .slot-left { grid-area: left; }
.rook-center .slot-right { grid-area: right; }
.rook-center .slot-bottom { grid-area: bottom; align-self: start; }
.rook-center .rook-mid {
  grid-area: mid;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.75);
  text-align: center;
  line-height: 1.3;
}

.rook-cardimg {
  display: block;
  width: var(--tw);
  aspect-ratio: 5 / 8;
  object-fit: cover;
  border-radius: 6px;
  background: var(--white);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 1;
}

.rook-cardimg.winner { box-shadow: 0 0 0 3px var(--warm-darker), 0 2px 10px rgba(0, 0, 0, 0.45); }

/* ---------- Deal animation ---------- */
.rook-felt { position: relative; }   /* flying cards are positioned against the felt */

.rook-deck {
  position: relative;
  width: calc(var(--tw) * 0.8);
  aspect-ratio: 5 / 8;
  z-index: 2;
}

.rook-deck img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.rook-deck img:nth-child(2) { transform: translate(2px, -2px); }
.rook-deck img:nth-child(3) { transform: translate(4px, -4px); }
.rook-deck.shuffling img:nth-child(1) { animation: rook-riffle-left 0.5s ease-in-out infinite; }
.rook-deck.shuffling img:nth-child(3) { animation: rook-riffle-right 0.5s ease-in-out infinite; }

@keyframes rook-riffle-left { 50% { transform: translateX(-70%) rotate(-12deg); } }
@keyframes rook-riffle-right { 50% { transform: translate(4px, -4px) translateX(70%) rotate(12deg); } }

.rook-fly {
  position: absolute;
  width: calc(var(--tw) * 0.6);
  aspect-ratio: 5 / 8;
  object-fit: cover;
  margin: calc(var(--tw) * -0.48) 0 0 calc(var(--tw) * -0.3);   /* center it on left/top */
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 5;
  animation: rook-fly 0.35s ease-out both;
}

@keyframes rook-fly {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(20deg) scale(0.8); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .rook-deck.shuffling img,
  .rook-fly { animation: none; }
  .rook-fly { display: none; }
}

/* ---------- Actions ---------- */
.rook-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
  min-height: 2.5rem;
}

.rook-actions[hidden] { display: none; }

.rook-actions select {
  font: inherit;
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--navy);
}

.rook-trumps { display: inline-flex; gap: 0.35rem; }

.rook-trump {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 2px solid transparent;
  color: var(--white);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity var(--transition), border-color var(--transition);
}

.rook-trump:hover { opacity: 0.85; }
.rook-trump.active { opacity: 1; border-color: var(--warm-darker); box-shadow: 0 0 0 2px var(--white) inset; }
.rook-trump.r { background: #c62828; }
.rook-trump.g { background: #2e7d32; }
.rook-trump.y { background: #c99a06; }
.rook-trump.b { background: #222; }

.rook-count { font-size: 0.9rem; color: var(--grey-700); font-weight: 600; }

/* Hand summary shown between hands */
.rook-summary {
  width: 100%;
  background: var(--warm);
  border: 1px solid var(--warm-dark);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  text-align: center;
  color: var(--grey-700);
}

.rook-summary h3 { color: var(--navy); margin-bottom: 0.5rem; }
.rook-summary p { margin-bottom: 0.35rem; }
.rook-summary .btn { margin-top: 0.5rem; }
.rook-mini-cards { display: inline-flex; gap: 3px; vertical-align: middle; --tw: 30px; }
.rook-mini-cards .rook-cardimg { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); border-radius: 3px; }

/* Face-up widow everyone looks at before the bid winner picks it up */
.rook-widow-cards {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0.5rem 0 0.75rem;
  --tw: clamp(48px, 13vw, 76px);
}

/* Game log: one row per trick, one column per player */
.rook-log details { margin-bottom: 0.75rem; }
.rook-log summary { cursor: pointer; font-weight: 600; color: var(--navy); padding: 0.35rem 0; }
.rook-log td { --tw: 34px; }
.rook-log .rook-cardimg { margin: 0 auto; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); border-radius: 3px; }
.rook-log .rook-cardimg.winner { box-shadow: 0 0 0 2px var(--warm-darker); }
.rook-log-play { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rook-log-play figcaption {
  font-size: 0.75rem;
  font-weight: 600;
  max-width: 5.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rook-log-note { font-size: 0.85rem; color: var(--grey-500); }

/* ---------- Your hand ---------- */
/* Cards shrink their flex box (not the image) when space runs out, so they overlap like a fan */
.rook-hand {
  display: flex;
  justify-content: center;
  padding: 1.1rem 0 0.25rem;
  min-height: calc(var(--cw) * 1.6 + 1.35rem);
}

.rook-hand:empty { min-height: 0; padding: 0; }

.rook-card {
  flex: 0 1 var(--cw);
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: default;
  transition: transform 0.15s ease;
}

.rook-card:last-child { flex-shrink: 0; }

.rook-card img {
  display: block;
  width: var(--cw);
  max-width: none;
  aspect-ratio: 5 / 8;
  object-fit: cover;
  border-radius: 6px;
  background: var(--white);
  box-shadow: -2px 1px 5px rgba(20, 54, 66, 0.35);
  transition: filter var(--transition);
}

.rook-card.live { cursor: pointer; }
.rook-card.live:hover { transform: translateY(-8px); }
.rook-card.dim img { filter: brightness(0.6) grayscale(0.4); }
.rook-card.sel { transform: translateY(-16px); }
.rook-card.sel img { box-shadow: 0 0 0 3px var(--warm-darker), -2px 1px 5px rgba(20, 54, 66, 0.35); }
.rook-card.new img { outline: 3px solid var(--accent); outline-offset: -3px; }

.rook-hand-hint { text-align: center; font-size: 0.85rem; color: var(--grey-500); min-height: 1.3rem; }

/* ---------- Last trick + history ---------- */
.rook-last {
  text-align: center;
  font-size: 0.85rem;
  color: var(--grey-700);
  margin-top: 0.75rem;
}

.rook-history { margin-top: 1.5rem; overflow-x: auto; }
.rook-history h3 { color: var(--navy); font-size: 1rem; margin-bottom: 0.5rem; }

.rook-history table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.rook-history th,
.rook-history td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--grey-100);
  text-align: center;
  white-space: nowrap;
}

.rook-history th { color: var(--grey-500); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

/* ---------- Modal ---------- */
.rook-modal {
  width: min(600px, calc(100% - 32px));
  margin: auto;
  border: 0;
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  color: var(--grey-700);
}

.rook-modal::backdrop {
  background: rgba(20, 54, 66, 0.6);
  backdrop-filter: blur(3px);
}

.rook-modal h2 {
  color: var(--navy);
  margin-bottom: 1.25rem;
  text-align: center;
}

.rook-modal-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey-500);
  margin-bottom: 0.4rem;
}

.rook-name { margin-bottom: 1.5rem; text-align: center; }

.rook-modal input {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--grey-300);
  border-radius: var(--radius-sm);
  min-width: 0;
}

.rook-name input { width: min(280px, 100%); text-align: center; font-weight: 600; }
.rook-name input.invalid { border-color: #c62828; box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.2); }
.rook-name-error { color: #c62828; font-size: 0.85rem; margin-top: 0.35rem; }
.rook-name-error[hidden] { display: none; }

.rook-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.rook-mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  padding: 1.25rem 1rem;
  border: 2px solid var(--grey-100);
  border-radius: var(--radius);
  background: var(--grey-50);
}

.rook-mode strong { color: var(--navy); font-size: 1.1rem; }
.rook-mode-icon { font-size: 2rem; line-height: 1; }
.rook-mode-desc { font-size: 0.9rem; margin-bottom: 0.5rem; }
.rook-mode .btn { justify-content: center; width: 100%; margin-top: auto; }

.rook-join { display: flex; gap: 0.4rem; width: 100%; margin-top: auto; }
.rook-join input { flex: 1; font-size: 0.9rem; padding: 0.4rem 0.6rem; text-transform: lowercase; }
.rook-join .btn { width: auto; }

@media (max-width: 560px) {
  .rook-modal { padding: 1.5rem 1.25rem; }
  .rook-modes { grid-template-columns: 1fr; }
  .rook-lobby-teams { grid-template-columns: 1fr; }
  .rook-scoreboard { grid-template-columns: 1fr 1fr; }
  .rook-handinfo { grid-column: 1 / -1; grid-row: 2; }
  .rook-felt { padding: 0.5rem 0.25rem; gap: 0.25rem; }
  .rook-seat { padding: 0.3rem 0.35rem; font-size: 0.85rem; }
}

/* ---------- Collapsible sections (same look as Cardoku) ---------- */
.rook-section > summary {
  position: relative;
  display: block;
  list-style: none;
  cursor: pointer;
  padding-right: 2.5rem;
  margin-bottom: 0;
}

.rook-section > summary::-webkit-details-marker { display: none; }

/* Arrow on the right that turns when the section opens */
.rook-section > summary::after {
  content: '';
  position: absolute;
  right: 0.5rem;
  top: 0.7rem;
  width: 0.6rem;
  height: 0.6rem;
  border-right: 2px solid var(--navy-400);
  border-bottom: 2px solid var(--navy-400);
  transform: rotate(-45deg);
  transition: transform var(--transition);
}

.rook-section[open] > summary::after { transform: rotate(45deg); }
.rook-section[open] > summary { margin-bottom: 1.5rem; }
.rook-section:not([open]) > summary .text-muted { display: none; }
.rook-section > summary:hover h2 { color: var(--navy-400); }

.rook-section > summary:focus-visible {
  outline: 3px solid var(--navy-400);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

.rook-rules-text { max-width: 820px; margin: 3rem auto 0; }
.rook-rules-text h3 { color: var(--navy); margin: 1.25rem 0 0.4rem; }
.rook-rules-text ol,
.rook-rules-text ul { padding-left: 1.25rem; list-style: revert; }
.rook-rules-text li { margin-bottom: 0.35rem; }
