@font-face {
  font-family: 'Stanley';
  src: url('/assets/fonts/subset-StanleyRegular.woff2') format('woff2');
  font-display: swap;
}

@font-face {
  font-family: 'Montserrat';
  font-weight: 400;
  src: url('/assets/fonts/montserrat-v14-latin-ext_latin-regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Montserrat';
  font-weight: 500;
  src: url('/assets/fonts/montserrat-v14-latin-ext_latin-500.woff2') format('woff2');
}

:root {
  --greenOne: #2A7D50;
  --greenTwo: #27744A;
  --greenThree: #21633F;
  --greenFour: #1C5435;
  --yellow: #FCC537;
  --white: #ECECEC;
  --red: #9A0000;

  /* the game */
  --felt: #2A7D50;
  --felt-light: #34915F;
  --felt-deep: #226841;
  --rail: #1A4D31;
  --panel: rgba(14, 50, 31, 0.78);
  --panel-solid: #1A4D31;
  --ink: #143322;
  --cream: #F6EEDC;
  --gold: #FCC537;
  --line: rgba(246, 238, 220, 0.35);
}

/* the game is sized in rem, and a rem follows the viewport height (as in the Vue client) */
html { font-size: max(4px, 1vh); }
@media (min-height: 960px) { html { font-size: max(10px, 1vh); } }
/* mobile browsers: size by the viewport with their toolbars shown (svh), so the game always fits */
@supports (height: 1svh) {
  html { font-size: max(4px, 1svh); }
  @media (min-height: 960px) { html { font-size: max(10px, 1svh); } }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--greenOne);
  color: var(--yellow);
  font-family: 'Montserrat', sans-serif;
  font-weight: 500;
}

a { color: var(--yellow); cursor: pointer; }
a:hover { color: var(--white); }

h1, h2, h3 { font-weight: 500; }

/* buttons */

.ui-button {
  padding: max(7px, 1.1rem) max(12px, 1.8rem);
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--panel-solid);
  color: var(--cream);
  font: inherit;
  font-size: max(13px, 1.8rem);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.ui-button:hover:not(:disabled) { background: var(--felt-deep); }
.ui-button:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }
.ui-button.active, .ui-button.active:hover:not(:disabled) { background: var(--gold); color: var(--ink); }
.ui-button.mandatory { border: 2px dashed var(--gold); }
.ui-button.primary, .ui-button.primary:hover:not(:disabled) { background: var(--gold); color: var(--ink); }
.ui-button:disabled { opacity: 0.4; cursor: default; }
.ui-button.secondary { background: transparent; border-color: var(--line); color: var(--cream); }

.spinner {
  width: max(28px, 5rem);
  height: max(28px, 5rem);
  margin: 2rem auto;
  border: max(3px, 0.5rem) solid rgba(236, 236, 236, 0.25);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/*
 * The landing page: the title, a hand of four heart courts held as a fan, and what to do next. Two columns on
 * wide screens and phones held sideways, stacked on phones held upright. Sized in px: it scrolls when short.
 */

.landing-page {
  --card: clamp(92px, min(13vw, 23vh), 200px);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 4vh, 40px);
  padding: clamp(16px, 4vh, 40px) 16px 16px;
  background: radial-gradient(ellipse 60% 55% at 50% 52%, var(--felt-light), var(--felt) 70%);
  color: var(--cream);
  font-size: 16px;
}

/* the title and the hand sit together in the middle, the footer at the bottom */
.landing-title { width: min(720px, 100%); margin-top: auto; }
.landing-title h1 { margin: 0; }
.landing-title img { display: block; width: 100%; height: auto; }

.landing-main {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: 1fr minmax(280px, 400px);
  align-items: center;
  gap: clamp(24px, 6vw, 80px);
}

/* the hand: cards turn about a point below them, as fingers hold them */
.fan {
  position: relative;
  justify-self: center;
  width: calc(var(--card) * 3.1);
  height: calc(var(--card) * 1.73 * 1.18);
}
.fan-card {
  position: absolute;
  left: calc(50% - var(--card) / 2);
  bottom: 0;
  width: var(--card);
  aspect-ratio: 401 / 694;
  /* the images carry their own rounded, transparent corners: the shadow follows them */
  filter: drop-shadow(0 6px 9px rgba(0, 0, 0, 0.3));
  transform-origin: 50% 165%;
  rotate: calc(-21deg + var(--i) * 14deg);
  animation: fan-open 700ms cubic-bezier(0.2, 0.8, 0.2, 1) 150ms backwards;
}
@keyframes fan-open { from { rotate: 0deg; } }
.fan.dealt .fan-card { animation: none; }

.landing-panel { display: flex; flex-direction: column; gap: 18px; }
.greeting { margin: 0 0 24px; font-size: 24px; color: var(--cream); }
.greeting .username { color: var(--gold); }
.main-buttons, .login-controls, .registration-controls { display: flex; flex-direction: column; gap: 12px; }

.btn-big {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 14px 20px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--cream);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 120ms, border-color 120ms;
}
.btn-big .label { font-size: 19px; }
.btn-big .hint { font-size: 14px; font-weight: 400; opacity: 0.75; }
.btn-big:hover:not(:disabled) { border-color: var(--cream); background: rgba(246, 238, 220, 0.06); }
.btn-big.primary { border-color: var(--gold); background: var(--gold); color: var(--ink); }
.btn-big.primary:hover:not(:disabled) { border-color: #FFD45E; background: #FFD45E; }
.btn-big:focus-visible { outline: 3px solid var(--cream); outline-offset: 3px; }
.btn-big:disabled { opacity: 0.6; cursor: default; }
/* sign-in links: alike, light, each with its provider's own mark (brand marks are drawn on light grounds) */
.login-controls { gap: 10px; }
.login-controls .btn-big {
  position: relative;
  align-items: center;
  padding: 12px 16px 12px 52px;
  border-color: var(--cream);
  background: var(--cream);
  color: var(--ink);
  font-size: 16px;
}
.login-controls .btn-big:hover { border-color: #fff; background: #fff; }
.login-controls .btn-big span { white-space: nowrap; }
/* centred in a 24px slot; sized by eye to one visual weight: the round marks smaller, the open squares larger */
.provider-logo { position: absolute; left: 30px; top: 50%; width: 20px; height: 20px; transform: translate(-50%, -50%); }
.provider-google .provider-logo { width: 20px; height: 20px; }
.provider-facebook .provider-logo { width: 18px; height: 18px; }
.provider-microsoft .provider-logo { width: 22px; height: 22px; }
.provider-x .provider-logo { width: 17px; height: 17px; }
.provider-discord .provider-logo { width: 23px; height: 23px; }
.registration-controls input, .login-controls .dev-login {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
}
.registration-controls input:focus, .login-controls .dev-login:focus { outline: none; border-color: var(--gold); }
/* the test login (dev and test servers only), set apart from the real sign-ins */
.login-controls .dev-login { margin-top: 8px; padding: 12px 16px; border-style: dashed; border-color: var(--gold); font-size: 16px; }

.landing-panel .spinner { margin: 24px auto; }
.landing-panel .error { padding: 6px 12px; border-radius: 6px; background: var(--red); color: var(--white); font-size: 15px; }
.landing-panel .error:empty { display: none; }

/* the private table's options, under its button: a switch drawn by the checkbox itself */
.create-table { display: flex; flex-direction: column; gap: 10px; }
.table-option { display: flex; align-items: center; gap: 12px; padding: 0 20px; color: var(--cream); cursor: pointer; }
.table-option input {
  flex: none;
  width: 42px;
  height: 24px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  background: radial-gradient(circle, var(--cream) 8px, transparent 9px) 3px 50% / 18px 18px no-repeat, rgba(246, 238, 220, 0.14);
  box-shadow: inset 0 0 0 2px var(--line);
  cursor: pointer;
  transition: background-position 160ms, background-color 160ms;
}
.table-option input:checked {
  background-image: radial-gradient(circle, var(--ink) 8px, transparent 9px);
  background-position: 21px 50%;
  background-color: var(--gold);
  box-shadow: none;
}
.table-option input:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
.table-option:has(input:disabled) { opacity: 0.6; cursor: default; }
.option-text { display: flex; flex-direction: column; gap: 1px; }
.option-text .label { font-size: 15px; }
.option-text .hint { font-size: 13px; font-weight: 400; opacity: 0.7; }

.landing-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 24px;
  margin-top: auto;
  font-size: 14px;
  color: rgba(246, 238, 220, 0.7);
}
.landing-foot .menu { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; }
.landing-foot a { color: inherit; text-decoration: none; }
.landing-foot a:hover { color: var(--cream); text-decoration: underline; }
.menu .item { white-space: nowrap; }
.languages { display: flex; padding: 3px; border-radius: 999px; background: var(--panel); }
.language {
  padding: 4px 12px;
  border: none;
  border-radius: 999px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.language.current { background: var(--cream); color: var(--ink); }
.landing-foot .version { font-size: 12px; opacity: 0.7; }

/* a phone held sideways: little height, so a smaller title and hand */
@media (max-height: 500px) and (orientation: landscape) {
  .landing-page { --card: clamp(72px, 24vh, 110px); gap: 12px; padding-top: 12px; }
  .landing-title { width: min(420px, 60vw); }
  .landing-main { grid-template-columns: 1fr minmax(260px, 360px); gap: 24px; }
  .btn-big, .login-controls .btn-big { padding: 8px 16px; }
  .login-controls .btn-big { font-size: 15px; }
  .btn-big .label { font-size: 17px; }
  .btn-big .hint { font-size: 13px; }
  .greeting { font-size: 20px; margin-bottom: 4px; }
}

/* upright or narrow: one column, the hand under the title */
@media (orientation: portrait), (max-width: 640px) {
  .landing-page { --card: clamp(84px, 24vw, 160px); }
  .landing-main { grid-template-columns: 1fr; align-content: start; gap: 24px; max-width: 440px; }
  .greeting { text-align: center; }
}

@media (prefers-reduced-motion: reduce) { .fan-card { animation: none; } }

/* the game: sized by the viewport (a rem is 1vh), laid out for a phone held sideways first */

.game {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  --hdr: clamp(30px, 5.5rem, 52px);
  --gutter: max(8px, 1.6rem);
  /* cards on the table (the trick, the talon); this player's hand is larger, the others' backs smaller */
  /* the card images are 96px wide: drawn larger, they blur */
  --card-w: min(11rem, 7.2vw, 96px);
  --card-h: calc(var(--card-w) * 1.7);
  --hand-w: min(13rem, 9.5vw, 96px);
  --hand-h: calc(var(--hand-w) * 1.7);
  --back-w: calc(var(--card-w) * 0.72);
  --back-h: calc(var(--back-w) * 1.7);
  /* the hand's room: twelve cards, the most one holds, each showing over half of itself, leaving room beside it
     for the discard piles */
  --hand-max: min(calc(var(--hand-w) * 7.2), 100vw - 2 * (var(--card-w) * 1.6 + 1.4rem + var(--gutter)));
  /* above the hand: room for a lifted card, then the name plate */
  --lift: 2.4rem;
  --plate-h: calc(max(12px, 1.9rem) * 1.6);
}
@media (max-height: 560px) { .game { --hand-w: min(15rem, 9.5vw, 96px); } }

/* the header: the logo tab, what the deal is about, the menu */

.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  height: var(--hdr);
  /* a gold stripe along the top, the logo tab and the menu hanging from it */
  border-top: 3px solid var(--gold);
  pointer-events: none;
}
.game-header > * { pointer-events: auto; }
.game-header .logo {
  position: relative;
  flex: none;
  height: 100%;
  padding: 0 calc(var(--hdr) * 0.3) 0 calc(var(--hdr) * 0.4);
  background: var(--gold);
  border-bottom-right-radius: calc(var(--hdr) * 0.45);
  display: flex;
  align-items: center;
}
.game-header .logo a { text-decoration: none; }
.game-header .logo h1 {
  margin: 0;
  color: var(--felt);
  font-family: 'Stanley', serif;
  font-weight: 400;
  font-size: calc(var(--hdr) * 0.5);
  white-space: nowrap;
}
.game-header .menu {
  flex: none;
  height: 100%;
  margin-left: auto;
  padding: 0 calc(var(--hdr) * 0.4);
  background: var(--panel);
  border-bottom-left-radius: calc(var(--hdr) * 0.45);
  display: flex;
  align-items: center;
  gap: 1.2em;
  font-size: max(11px, 1.6rem);
}
.game-header .menu a { color: var(--cream); text-decoration: none; }
.game-header .menu a:hover { color: var(--gold); }

/* what the deal is about, under the logo */
.contract {
  position: absolute;
  top: calc(var(--hdr) + 0.8rem);
  left: var(--gutter);
  z-index: 3;
  max-width: min(30vw, 56rem);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  font-size: max(11px, 1.6rem);
  white-space: nowrap;
}
.contract > span {
  padding: 0.25em 0.75em;
  border-radius: 1em;
  background: var(--panel);
  color: var(--cream);
}
@media (max-height: 560px) { .contract { gap: 0.3em; max-width: 36vw; font-size: 11px; } }

/* cards */

.playing-card {
  display: block;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.07);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* the table: a felt with a rail, lighter where the trick lands */

.playfield { position: absolute; inset: 0; }
.table-surface {
  position: absolute;
  top: calc(var(--hdr) + var(--plate-h) + var(--back-h) * 0.5);
  bottom: calc(var(--hand-h) * 0.6);
  left: max(14vw, calc(50% - 60rem));
  right: max(14vw, calc(50% - 60rem));
  border-radius: 999px;
  background: radial-gradient(ellipse at 50% 50%, var(--felt-light) 0%, var(--felt) 75%);
  box-shadow: 0 0 0 max(4px, 0.7rem) var(--rail), inset 0 0.4rem 2rem rgba(0, 0, 0, 0.2);
}

/* the players: across the top, at the sides, and this player along the bottom */

.players { position: absolute; inset: 0; pointer-events: none; }
.player { position: absolute; display: flex; gap: 1.2rem; pointer-events: auto; }
.player.hidden { visibility: hidden; }
.player-main { position: relative; display: flex; flex-direction: column; gap: 0.6rem; }

.player-top { top: calc(var(--hdr) + 0.8rem); left: 50%; transform: translateX(-50%); align-items: center; }
/* the name plate centred above the cards, the discard pile beside them, out of the centring */
.player-top .player-main { align-items: center; }
.player-top .pile { position: absolute; right: calc(100% + 1.4rem); bottom: 0; }
/* anchored by their name plates, so a discard pile under the cards does not move them */
.player-left, .player-right { top: calc(50% - var(--back-h) * 0.9); flex-direction: column; }
.player-left { left: var(--gutter); align-items: flex-start; }
.player-right { right: var(--gutter); align-items: flex-end; }
.player-left .player-main { align-items: flex-start; }
.player-right .player-main { align-items: flex-end; }
/* a fixed width, so neither the name plate nor the discard piles move as the hand shrinks */
.player-bottom { bottom: 0; left: 50%; width: var(--hand-max); transform: translateX(-50%); justify-content: center; }
.player-bottom .player-main { align-items: center; gap: 0; }
.player-bottom .player-info { max-width: 100%; }
.player-bottom .pile { position: absolute; left: calc(100% + 1.4rem); bottom: max(6px, 1.2rem); padding: 0; min-width: 0; }
.player-bottom .pile-declarer { bottom: calc(max(6px, 1.2rem) + var(--card-h) * 0.5 + 0.8rem); }
.player-top .pile-others, .player-bottom .pile-others { order: -1; }

/* name plates; the player the table waits for is ringed in gold */
.player-info {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  max-width: 40vw;
  padding: 0.25em 0.8em;
  border-radius: 1em;
  background: var(--panel);
  font-size: max(12px, 1.9rem);
  white-space: nowrap;
}
.player-info .nickname { color: var(--cream); overflow: hidden; text-overflow: ellipsis; }
.player-info .nickname.offline { opacity: 0.45; }
.player-info .role {
  padding: 0.1em 0.55em;
  border-radius: 0.8em;
  background: rgba(252, 197, 55, 0.16);
  color: var(--gold);
  font-size: 0.78em;
}
.player-info .role.declarer { background: var(--gold); color: var(--ink); }
.player.to-act .player-info { box-shadow: 0 0 0 2px var(--gold); }
.player.to-act .nickname { color: var(--gold); }
/* a dot on the plate's corner: it never changes the plate's size, so nothing around it moves */
.player.to-act .player-info::before {
  content: '';
  position: absolute;
  top: -0.25em;
  left: -0.25em;
  width: 0.7em;
  height: 0.7em;
  box-shadow: 0 0 0 2px var(--felt-deep);
  border-radius: 50%;
  background: var(--gold);
  animation: waiting 1.4s ease-in-out infinite;
}
@keyframes waiting { 50% { opacity: 0.25; } }

/* speech bubbles: each player's last move, pointing at them; it fades once it is no longer news */
.bubble {
  position: absolute;
  z-index: 4;
  width: max-content;
  max-width: min(40rem, 26vw);
  padding: 0.45em 0.8em;
  border-radius: 0.7em;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  font-size: max(12px, 1.8rem);
  line-height: 1.25;
  white-space: normal;
  animation: bubble-in 160ms ease-out;
  transition: opacity 400ms;
}
.bubble.stale { opacity: 0.6; }
.bubble::before { content: ''; position: absolute; border: 0.45em solid transparent; }
.player-top .bubble, .player-left .bubble { left: calc(100% + 0.9em); top: 0; }
.player-top .bubble::before, .player-left .bubble::before { right: 100%; top: 0.55em; border-right-color: var(--cream); }
.player-right .bubble { right: calc(100% + 0.9em); top: 0; }
.player-right .bubble::before { left: 100%; top: 0.55em; border-left-color: var(--cream); }
@keyframes bubble-in { from { opacity: 0; scale: 0.85; } }

/* the others' cards: how many they hold */
.backs { display: flex; }
.backs .playing-card { width: var(--back-w); height: var(--back-h); }
.backs .playing-card + .playing-card { margin-left: calc(var(--back-w) * -0.72); }

/* this player's hand */
.hand { display: flex; justify-content: center; align-items: flex-end; padding: var(--lift) 0 max(6px, 1.2rem); }
/* positioned so lifted (transformed) cards keep painting in DOM order instead of jumping above their neighbours */
.hand .playing-card {
  position: relative;
  width: var(--hand-w);
  height: var(--hand-h);
  transition: transform 120ms ease-out, filter 150ms;
}
/* each card shows 60% of itself, less only when that would overflow the hand's room */
.hand .playing-card + .playing-card {
  margin-left: calc(min(var(--hand-w) * 0.6, (var(--hand-max) - var(--hand-w)) / max(var(--n) - 1, 1)) - var(--hand-w));
}
.hand .playing-card.active { cursor: pointer; }
@media (hover: hover) { .hand .playing-card.active:hover { transform: translateY(-1.8rem); } }
.hand .playing-card.selected { transform: translateY(-2.4rem); outline: 3px solid var(--gold); outline-offset: -1px; }
.hand .playing-card.unplayable { filter: brightness(0.6) saturate(0.7); }

/* discard piles: each card shows 40% of itself */
.pile { display: flex; align-self: flex-end; min-width: calc(var(--card-w) * 1.2); padding-bottom: 1.2rem; }
.player-left .pile, .player-right .pile, .player-top .pile { align-self: auto; min-width: 0; padding: 0; }
.pile:empty { display: none; }
.pile .playing-card { width: calc(var(--card-w) * 0.5); height: calc(var(--card-h) * 0.5); }
.pile .playing-card + .playing-card { margin-left: calc(var(--card-w) * -0.3); }

/* the middle: the talon while bidding, then the trick */

.talon, .trick { position: absolute; left: 50%; width: 0; height: 0; }
.talon { top: 42%; display: flex; transform: translate(calc(var(--card-w) * -0.65), calc(var(--card-h) * -0.35)); }
/* centred between the top player and the hand */
.trick { top: calc((var(--hdr) + var(--plate-h) + var(--back-h) + 100% - var(--hand-h) - var(--lift)) / 2); }
.talon .playing-card { position: absolute; width: calc(var(--card-w) * 0.7); height: calc(var(--card-h) * 0.7); }
.talon .playing-card:nth-child(2) { left: calc(var(--card-w) * 0.12); }
.talon .playing-card:nth-child(3) { left: calc(var(--card-w) * 0.24); }
.talon .playing-card:nth-child(4) { left: calc(var(--card-w) * 0.36); }
.talon .playing-card:nth-child(5) { left: calc(var(--card-w) * 0.48); }
.talon .playing-card:nth-child(6) { left: calc(var(--card-w) * 0.60); }
.talon-card[class*="fly-to-"] { animation: 320ms ease-in calc(var(--i) * 180ms) forwards; }
.talon-card.fly-to-bottom { animation-name: talon-to-bottom; }
.talon-card.fly-to-top { animation-name: talon-to-top; }
.talon-card.fly-to-left { animation-name: talon-to-left; }
.talon-card.fly-to-right { animation-name: talon-to-right; }
@keyframes talon-to-bottom { to { transform: translate(0, 45vh); opacity: 0; } }
@keyframes talon-to-top { to { transform: translate(0, -40vh); opacity: 0; } }
@keyframes talon-to-left { to { transform: translate(-42vw, 0); opacity: 0; } }
@keyframes talon-to-right { to { transform: translate(42vw, 0); opacity: 0; } }

/* each card comes in from its player's side; the winner of a taken trick is ringed, then all go to the taker */
.trick-card {
  position: absolute;
  --at: translate(-50%, -50%);
  transform: var(--at);
  animation: 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
  transition: box-shadow 150ms;
}
.trick-bottom { --at: translate(-50%, calc(-50% + var(--card-h) * 0.42)); animation-name: from-bottom; }
.trick-top { --at: translate(-50%, calc(-50% - var(--card-h) * 0.42)); animation-name: from-top; }
.trick-left { --at: translate(calc(-50% - var(--card-w) * 0.8), -50%); animation-name: from-left; }
.trick-right { --at: translate(calc(-50% + var(--card-w) * 0.8), -50%); animation-name: from-right; }
@keyframes from-bottom { from { transform: var(--at) translate(0, 40vh); } }
@keyframes from-top { from { transform: var(--at) translate(0, -35vh); } }
@keyframes from-left { from { transform: var(--at) translate(-38vw, 0); } }
@keyframes from-right { from { transform: var(--at) translate(38vw, 0); } }
/* a card seen leaving its hand flies from there instead (GamePage.flyFrom) */
.trick-card.flown { animation: none; }
.trick-card.winner { z-index: 1; box-shadow: 0 0 0 3px var(--gold), 0 4px 12px rgba(0, 0, 0, 0.4); }
.trick.leaving .trick-card { transition: transform 300ms ease-in, opacity 300ms ease-in; opacity: 0; }
.trick.leaving-bottom .trick-card { transform: translate(-50%, -50%) translate(0, 45vh) scale(0.6); }
.trick.leaving-top .trick-card { transform: translate(-50%, -50%) translate(0, -40vh) scale(0.6); }
.trick.leaving-left .trick-card { transform: translate(-50%, -50%) translate(-42vw, 0) scale(0.6); }
.trick.leaving-right .trick-card { transform: translate(-50%, -50%) translate(42vw, 0) scale(0.6); }

/* this player's turn: what to do, and the buttons for it, just above the hand */

.controls {
  position: absolute;
  left: 50%;
  /* the gaps in pixels at least: on a short screen (a phone held sideways) a rem is only 4px */
  bottom: calc(var(--hand-h) + max(6px, 1.2rem) + var(--lift) + var(--plate-h) + max(12px, 1.2rem));
  z-index: 5;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(110rem, 72vw);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: max(8px, 0.8rem);
}
.controls.open { display: flex; }
.controls .prompt {
  padding: 0.3em 0.9em;
  border-radius: 1em;
  background: var(--cream);
  color: var(--ink);
  font-size: max(12px, 1.9rem);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.controls .button-pane { display: flex; flex-wrap: wrap; justify-content: center; gap: max(6px, 0.9rem); }
.controls .button-pane:empty { display: none; }
.controls .button-row { display: flex; flex-wrap: wrap; justify-content: center; gap: max(6px, 0.9rem); }
.controls .ui-button { min-width: 11rem; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
/* the trump to call, and the others in a list behind the triangle */
.split-button { display: inline-flex; border-radius: 999px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
.controls .split-button .ui-button { box-shadow: none; }
.controls .split-button .ui-button:first-child { border-radius: 999px 0 0 999px; }
.controls .split-toggle {
  position: relative;
  min-width: 0;
  padding-left: 1.4em;
  padding-right: 1.6em;
  border-left: 1px solid var(--line);
  border-radius: 0 999px 999px 0;
}
/* the select covers the triangle, unseen: tapping it opens the list */
.split-toggle select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 16px; cursor: pointer; }
/*
 * announcements: the figures, then the button that says the chosen ones, in two rows, the first a little longer (the
 * break is placed by announcementControls)
 */
.controls .announce .figures, .controls .announce .actions { display: contents; }
.controls .announce .break { flex-basis: 100%; height: 0; }
.controls .ui-button.mandatory.active { cursor: default; }
.controls .figures-toggle { display: none; }
.figures-toggle .caret { margin-left: 0.4em; }
/* the finished deal: the scores button sits where the hand was */
.controls[data-phase="game-over"] { bottom: calc(var(--hand-h) * 0.5); }

/* phones, upright or sideways: the figures fold away above the say button until asked for */
@media (max-aspect-ratio: 1/1), (max-height: 560px) {
  .controls .figures-toggle { display: inline-block; }
  .controls .announce { flex-direction: column; align-items: center; }
  .controls .announce .actions { display: flex; gap: max(6px, 0.9rem); }
  .controls .announce .break { display: none; }
  .controls .announce .figures {
    display: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    max-width: calc(100vw - 2 * var(--gutter));
    padding: 10px;
    border-radius: 14px;
    background: var(--panel-solid);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
  .controls .announce.open .figures { display: flex; }
}

/* the log: a corner panel on large screens, behind a button on small ones */

.log-panel {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
}
.log-toggle {
  display: none;
  margin: 0 0 var(--gutter) var(--gutter);
  padding: 0.35em 0.9em;
  border: none;
  border-radius: 1em;
  background: var(--panel);
  color: var(--cream);
  font: inherit;
  font-size: max(12px, 1.7rem);
  cursor: pointer;
}
.action-log {
  width: 30rem;
  max-height: 28rem;
  overflow-y: auto;
  padding: 0.6rem 0;
  border-top-right-radius: 1rem;
  background: var(--panel);
  color: rgba(246, 238, 220, 0.8);
  font-size: max(11px, 1.4rem);
}
.action-log .line { padding: 0.3em 0.9em; }
.action-log .line:last-child { color: var(--cream); }
.action-log .who { color: var(--cream); }
.action-log .who.me { color: var(--gold); }
.action-log .announcement { color: var(--gold); text-align: center; }
@media (max-height: 560px), (max-aspect-ratio: 3/2) {
  .log-toggle { display: block; }
  .action-log { display: none; }
  .log-panel.open .action-log {
    display: block;
    width: min(42rem, 45vw);
    max-height: 60vh;
    margin-left: var(--gutter);
    margin-bottom: 0.8rem;
    border-radius: 1rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
  .log-panel.open .log-toggle { background: var(--gold); color: var(--ink); }
}

/*
 * A phone held upright: sized by the width; the contract wraps under the header, the others sit across the top
 * third, the trick in the middle, and the hand runs edge to edge above the bottom, with the name plate over it.
 */
@media (max-aspect-ratio: 1/1) {
  .game {
    --hdr: clamp(36px, 11vw, 52px);
    --gutter: 10px;
    --card-w: min(16vw, 10rem);
    --hand-w: min(15.5vw, 12rem);
    --back-w: min(8.5vw, 6rem);
  }
  .game-header .menu { gap: 1em; }

  .contract { max-width: calc(100% - 2 * var(--gutter) - 7em); font-size: 12px; }

  .table-surface {
    top: calc(var(--hdr) + var(--back-h) + 18rem);
    bottom: calc(var(--hand-h) + 7rem);
    left: 5vw;
    right: 5vw;
  }

  /* a row below the contract, which can take three lines */
  .player-top { top: calc(var(--hdr) + 15rem); }
  .player-top .player-main { flex-direction: column; gap: 0.5rem; }
  .player-left, .player-right { top: calc(var(--hdr) + var(--back-h) + 28rem); transform: none; }
  .backs .playing-card + .playing-card { margin-left: calc(var(--back-w) * -0.78); }
  .player-info { max-width: 44vw; font-size: 13px; }

  .bubble { max-width: 44vw; font-size: 13px; }
  .player-top .bubble { left: 50%; top: calc(100% + 0.7em); transform: translateX(-50%); }
  .player-top .bubble::before { right: auto; top: auto; bottom: 100%; left: calc(50% - 0.45em); border-color: transparent; border-bottom-color: var(--cream); }
  .player-left .bubble, .player-right .bubble { top: calc(100% + 0.7em); }
  .player-left .bubble { left: 0; }
  .player-right .bubble { left: auto; right: 0; }
  .player-left .bubble::before, .player-right .bubble::before {
    top: auto;
    bottom: 100%;
    border-color: transparent;
    border-bottom-color: var(--cream);
  }
  .player-left .bubble::before { left: 1em; right: auto; }
  .player-right .bubble::before { right: 1em; left: auto; }

  /* the hand: as wide as the screen, the name plate above its left end, the piles above its right end */
  .game { --hand-max: calc(100vw - 2 * var(--gutter)); }
  /* room for a lifted card under the name plate */
  /* the piles beside the name plate: the declarer's at the left, the others' at the right */
  .player-bottom .pile { left: auto; right: 0; bottom: calc(var(--hand-h) + max(6px, 1.2rem) + var(--lift)); }
  .player-bottom .pile-declarer { left: 0; right: auto; }

  .trick { top: calc((var(--hdr) + 2 * var(--back-h) + 30rem + 100% - var(--hand-h) - 6rem) / 2); }
  .talon { top: 40%; }

  .controls {
    bottom: calc(var(--hand-h) + max(6px, 1.2rem) + var(--lift) + 30px + 0.8rem);
    max-width: calc(100% - 2 * var(--gutter));
  }
  .controls .ui-button { min-width: 0; padding: 8px 14px; font-size: 14px; }

  /* the log opens from the top right, under the menu */
  .log-panel { top: calc(var(--hdr) + 0.8rem); bottom: auto; left: auto; right: var(--gutter); flex-direction: column; align-items: flex-end; }
  .log-toggle { display: block; margin: 0; font-size: 12px; }
  .action-log { display: none; }
  .log-panel.open .action-log {
    display: block;
    width: min(320px, calc(100vw - 2 * var(--gutter)));
    max-height: 55vh;
    margin: 0.8rem 0 0;
    border-radius: 1rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
  .log-panel.open .log-toggle { background: var(--gold); color: var(--ink); }
}

/* overlays and dialogs */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: var(--gutter, 12px);
  background: rgba(8, 30, 18, 0.7);
  color: var(--cream);
  font-size: max(13px, 2rem);
}
/* waiting for players: the table stays visible, dimmed */
.overlay.dim { z-index: 8; background: rgba(8, 30, 18, 0.82); color: rgba(246, 238, 220, 0.8); }

.modal {
  max-width: min(max(110rem, 640px), 100%);
  max-height: 100%;
  overflow: auto;
  padding: max(12px, 2rem) max(14px, 3rem);
  border-radius: max(8px, 1.2rem);
  background: var(--panel-solid);
  color: var(--cream);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  font-size: max(13px, 1.9rem);
}
.modal h3, .modal h2 { margin: 0 0 0.6em; color: var(--gold); font-weight: 500; }
.modal-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 3rem; }
.modal .close { background: none; border: none; color: var(--cream); font-size: max(22px, 3rem); line-height: 1; cursor: pointer; }
.modal-buttons { display: flex; gap: 1.5rem; justify-content: flex-end; margin-top: 2rem; }
.modal label { display: block; }
.modal textarea { width: min(80rem, 80vw); margin-top: 1rem; padding: 1rem; border-radius: 0.6rem; border: none; font: inherit; }

.invite { color: var(--cream); }
.invite-link { display: flex; flex-wrap: wrap; gap: 1rem; }
.invite-link input { flex: 1; min-width: 20rem; padding: 0.6em; border: none; border-radius: 0.5em; font: inherit; }
.invite-link .ui-button.done { background: var(--gold); color: var(--ink); }

/*
 * The private table's lobby: who sits at the table, as cards dealt onto it (the free seats are their outlines),
 * then the invite link. Sized in em of the dialog, so it scales with the game.
 */
.lobby {
  width: min(100%, max(600px, 104rem));
  padding: max(16px, 2.6rem) max(16px, 3.4rem);
  border: 1px solid rgba(252, 197, 55, 0.22);
  background: linear-gradient(180deg, var(--panel-solid), #163F28);
}
.lobby-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.6em 1.5em; margin-bottom: 1.2em; }
.lobby-title { display: flex; align-items: center; gap: 0.8em; }
.lobby .lobby-title h2 { margin: 0; font-size: 1.45em; }
.lobby-badge {
  padding: 0.2em 0.75em;
  border: 1px solid var(--gold);
  border-radius: 999px;
  color: var(--gold);
  font-size: 0.68em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.lobby-count { display: flex; align-items: center; gap: 0.7em; color: rgba(246, 238, 220, 0.75); font-size: 0.85em; }
.pips { display: flex; gap: 0.35em; }
.pip { width: 0.7em; height: 0.7em; border: 1.5px solid var(--line); border-radius: 50%; transition: background-color 240ms, border-color 240ms; }
.pip.on { border-color: var(--gold); background: var(--gold); }

.lobby-seats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1em; }
.lobby-seat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  aspect-ratio: 5 / 7;
  min-width: 0;
  padding: 0.8em 0.5em;
  border-radius: 0.7em;
  text-align: center;
}
/* a card face: cream, with a thin frame inside its edge */
.lobby-seat.taken {
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 0.4em 1em rgba(0, 0, 0, 0.35), inset 0 0 0 0.35em var(--cream), inset 0 0 0 calc(0.35em + 1px) rgba(20, 51, 34, 0.22);
  animation: seat-dealt 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.lobby-seat.taken.me {
  box-shadow: 0 0.4em 1em rgba(0, 0, 0, 0.35), 0 0 0 2px var(--gold), inset 0 0 0 0.35em var(--cream), inset 0 0 0 calc(0.35em + 1px) rgba(20, 51, 34, 0.22);
}
@keyframes seat-dealt { from { opacity: 0; transform: translateY(-1.6em) rotate(-6deg) scale(0.95); } }
.seat-index { position: absolute; color: rgba(20, 51, 34, 0.45); font-size: 0.8em; line-height: 1; }
.seat-index.top { top: 1em; left: 1em; }
.seat-index.bottom { right: 1em; bottom: 1em; transform: rotate(180deg); }
.lobby-seat.free {
  border: 2px dashed var(--line);
  background: repeating-linear-gradient(135deg, rgba(246, 238, 220, 0.035) 0 0.5em, transparent 0.5em 1em);
  color: rgba(246, 238, 220, 0.55);
}
.lobby-seat .avatar {
  display: grid;
  place-items: center;
  width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--felt-light), var(--felt-deep));
  box-shadow: inset 0 0 0 2px rgba(252, 197, 55, 0.65);
  color: var(--cream);
  font-size: 1.35em;
}
.lobby-seat.free .avatar { border: 2px dashed var(--line); background: none; box-shadow: none; }
.seat-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.95em; }
.seat-tags { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.3em; min-height: 1.3em; }
/* capitals only: centred by their cap height (trimmed where supported, else by a little more padding on top) */
.tag {
  padding: 0.42em 0.65em 0.32em;
  border-radius: 999px;
  font-size: 0.64em;
  line-height: 1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
@supports (text-box: trim-both cap alphabetic) {
  .tag { padding: 0.45em 0.7em; text-box: trim-both cap alphabetic; }
}
.tag-me { background: var(--gold); color: var(--ink); }
.tag-host { background: var(--ink); color: var(--gold); }
.tag-offline { background: rgba(20, 51, 34, 0.14); color: var(--ink); }
/* a dropped connection: the card greys, its player keeps the seat */
.lobby-seat.taken.offline { background: #D8D1C0; }
.lobby-seat.offline .avatar { filter: grayscale(1); opacity: 0.5; }
.lobby-seat.offline .seat-name { opacity: 0.55; }
.lobby-seat .kick {
  position: absolute;
  top: 0.4em;
  right: 0.4em;
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(20, 51, 34, 0.09);
  color: var(--ink);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
.lobby-seat .kick:hover { background: var(--red); color: var(--cream); }
.lobby-seat .kick:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.lobby-seat .add-bot { margin-top: 0.2em; padding: 0.45em 1em; font-size: 0.8em; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }

.lobby-error { margin-top: 0.8em; padding: 0.4em 0.8em; border-radius: 6px; background: var(--red); color: var(--white); font-size: 0.85em; text-align: center; }
.lobby-error:empty { display: none; }
.lobby-note { margin: 0.9em 0 1.2em; color: rgba(246, 238, 220, 0.6); font-size: 0.82em; text-align: center; }
.lobby .invite { padding-top: 1.1em; border-top: 1px solid rgba(246, 238, 220, 0.14); }
.lobby .invite h3 { margin: 0 0 0.25em; font-size: 1em; }
.lobby .invite p { margin: 0 0 0.7em; color: rgba(246, 238, 220, 0.7); font-size: 0.85em; }

/* a phone held upright: two rows of seats */
@media (max-width: 560px) {
  .lobby-seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7em; }
  .lobby-seat { aspect-ratio: 6 / 5; }
}
/* little height (a phone held sideways): low cards */
@media (max-height: 500px) and (orientation: landscape) {
  .lobby { padding: 12px 16px; }
  .lobby-head { margin-bottom: 0.7em; }
  .lobby-seat { aspect-ratio: auto; min-height: 7.5em; padding: 0.6em 0.4em; gap: 0.3em; }
  .lobby-seat .avatar { width: 2em; height: 2em; font-size: 1.1em; }
  .lobby-note { margin: 0.5em 0 0.7em; }
  .lobby .invite { padding-top: 0.7em; }
  .lobby .invite p { display: none; }
}

.score-table { overflow-x: auto; }
.score-table table { border-collapse: collapse; color: var(--cream); font-variant-numeric: tabular-nums; }
.score-table th, .score-table td { padding: 0.35em 0.8em; text-align: right; white-space: nowrap; }
.score-table th { font-weight: 400; color: rgba(246, 238, 220, 0.7); }
.score-table thead tr:last-child th { color: var(--cream); }
.score-table td.figure { text-align: left; color: var(--cream); padding-left: 0; }
.score-table .me { background: rgba(252, 197, 55, 0.12); }
.score-table thead tr:last-child th.me { color: var(--gold); }
.score-table tr.total td { border-top: 2px solid var(--gold); font-size: 1.15em; color: var(--gold); }
.score-table tr.total td.neg { color: var(--cream); }
@media (max-height: 560px) { .modal.scores { font-size: 12px; } .modal.scores .modal-title h2 { font-size: 16px; } }

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

/* legal pages and admin */

/* the header is sized like the game's (the --hdr it uses is defined per page) */
.legal-page { --hdr: clamp(36px, 5.5rem, 52px); min-height: 100vh; min-height: 100dvh; font-size: max(14px, 1vh); }
.legal-page .game-header { position: static; font-size: max(9px, 0.8rem); }
.formatted-paragraphs { padding: 2em 8em; color: var(--yellow); }
.formatted-paragraphs > ol > li { font-size: 1.5em; }
.formatted-paragraphs .list-item { font-size: 0.75em; }
.formatted-paragraphs ul { margin-bottom: 1rem; }
.formatted-paragraphs table, .formatted-paragraphs th, .formatted-paragraphs td { padding: 0.25em; border: 1px solid black; }
.formatted-paragraphs table tr th { text-align: center; background-color: beige; color: var(--greenFour); }
@media (max-width: 900px) { .formatted-paragraphs { padding: 1em 1.5em; } }

.admin-page { max-width: 1100px; margin: 0 auto; padding: 32px 16px; font-size: 16px; color: var(--white); }
.admin-page h1 { color: var(--yellow); text-align: center; }
.admin-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.admin-card { padding: 16px 20px; background: var(--greenThree); border-radius: 6px; }
.admin-card h2 { margin-top: 0; color: var(--yellow); font-size: 20px; }
.admin-card label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.admin-card input, .admin-card select { padding: 8px; font: inherit; }
.admin-page .ui-button { font-size: 15px; }
.bot-list { list-style: none; padding: 0; }
.bot-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: var(--greenFour); margin-bottom: 4px; }
.bot-list .remove { background: var(--red); color: var(--white); border: none; border-radius: 4px; padding: 2px 10px; cursor: pointer; }
.admin-message { min-height: 1.5em; }

/* server errors (e.g. an annotation that was not saved) */
.toast {
  position: fixed;
  top: calc(max(7px, 0.8rem) * 6 + 2rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 1rem 2rem;
  border-radius: 0.4rem;
  background: var(--red);
  color: var(--white);
  font-size: max(12px, 1.8rem);
}
.toast .close { background: none; border: none; color: var(--white); font-size: max(16px, 2.4rem); cursor: pointer; }

/* debug-only post-game annotation, inside the scores dialog */
.annotation { margin-top: 2rem; }
.annotation textarea { display: block; width: 100%; }
.admin-card .hint { font-size: 13px; opacity: 0.8; }

/* the scores on a narrow screen: four columns of numbers must fit without scrolling */
@media (max-width: 600px) {
  .modal.scores { padding: 14px 12px; }
  .score-table table { font-size: 12px; }
  .score-table th, .score-table td { padding: 0.35em 0.4em; }
  .score-table thead tr:last-child th { max-width: 5.5em; overflow: hidden; text-overflow: ellipsis; }
  .score-table td.figure { white-space: normal; }
}
