/* F**K Your Neighbor - a card table on a phone. Green felt, ivory cards,
   brass for anything you can tap. */

:root {
  --felt: #1a6a45;
  --felt-deep: #0e3a27;
  --rail: #3a2416;
  --ivory: #fdfaf2;
  --ink: #1b1b1f;
  --red: #c0162f;
  --brass: #d6b25e;
  --brass-deep: #9c7a2c;
  --back: #8e1b2b;
  --chalk: rgba(253, 250, 242, 0.82);

  --serif: 'Libre Caslon Text', Georgia, 'Times New Roman', serif;
  --sans: 'Libre Franklin', 'Franklin Gothic Medium', system-ui, sans-serif;

  /* Card sizes follow the screen - its width on a phone, its height on a
     tablet or computer - so cards fill the table without crowding it. */
  --cw: min(17vw, 11.5vh, 120px);   /* card width in your hand */
  --tw: min(14vw, 9vh, 96px);       /* card width on the table */
  --mw: clamp(24px, 3.4vh, 40px);   /* other players' face-up cards */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 90% at 50% 45%, var(--felt) 0%, #145a3a 55%, var(--felt-deep) 100%) fixed;
  background-color: var(--felt-deep);
  color: var(--ivory);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

/* --- the menu -------------------------------------------------------------- */

.menu {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  text-align: center;
}
.title {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 0.95;
  margin: 0;
  letter-spacing: -0.01em;
}
.title .word { display: block; font-size: clamp(54px, 19vw, 96px); }
.title .suit { display: inline-block; font-size: 0.82em; transform: translateY(-0.04em); }
.title .suit.red { color: #e8475c; }
.title .rest { display: block; font-size: clamp(26px, 8.4vw, 42px); font-style: italic; font-weight: 400; margin-top: 6px; color: var(--chalk); }

.options { width: min(100%, 340px); display: grid; gap: 14px; text-align: left; }
.option { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.option label, .option .label { font-weight: 600; }
.option small { display: block; font-weight: 400; color: var(--chalk); font-size: 13px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper output { min-width: 2ch; text-align: center; font-family: var(--serif); font-size: 22px; font-weight: 700; }
.stepper button {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--brass); background: transparent; color: var(--brass);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.stepper button:disabled { opacity: 0.3; }
.option input {
  width: 9.5em; padding: 8px 10px; border-radius: 8px; border: 2px solid var(--brass-deep);
  background: rgba(0, 0, 0, 0.18); color: var(--ivory); font: inherit; text-align: right;
}
.menu .actions { display: grid; gap: 10px; width: min(100%, 340px); }

.btn {
  min-height: 48px; padding: 0 22px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--brass); background: transparent; color: var(--brass);
  font-weight: 700; font-size: 17px;
}
.btn.primary { background: var(--brass); color: var(--felt-deep); }
.btn:disabled { opacity: 0.35; cursor: default; }

/* --- the table ------------------------------------------------------------- */

.table {
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  gap: 6px;
}
.topbar { display: flex; align-items: center; gap: 8px; }
.topbar .quit { border: 0; background: none; color: var(--chalk); font-size: 14px; padding: 6px 4px; cursor: pointer; }
.opponents { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 6px; flex: 1; scrollbar-width: none; }
.opponents::-webkit-scrollbar { display: none; }
/* Centred when they fit, still scrollable when they don't. */
.opponents > :first-child { margin-left: auto; }
.opponents > :last-child { margin-right: auto; }

.seat {
  flex: 0 0 auto; min-width: calc(var(--mw) * 3 + 22px); padding: 6px 8px 8px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.16); border: 2px solid transparent; text-align: center;
}
.seat.turn { border-color: var(--brass); background: rgba(214, 178, 94, 0.14); }
.seat .name { font-weight: 700; font-size: clamp(14px, 1.6vh, 18px); white-space: nowrap; }
.seat .held { font-size: clamp(12px, 1.3vh, 15px); color: var(--chalk); margin: 1px 0 4px; }
.seat .slots { --tw: var(--mw); justify-content: center; gap: 3px; }

/* The middle of the table: draw pile, play pile, cleared cards. */
.middle { display: grid; align-content: center; justify-items: center; gap: 10px; min-height: 0; }
.stacks { display: flex; align-items: center; justify-content: center; gap: 22px; }
.stack { display: grid; justify-items: center; gap: 4px; font-size: 12px; color: var(--chalk); }
.stack .card { --cw: var(--tw); }
.stack .empty { width: var(--tw); height: calc(var(--tw) * 1.4); border-radius: 8px; border: 2px dashed rgba(253, 250, 242, 0.25); }

.pile { position: relative; width: calc(var(--cw) * 1.9); height: calc(var(--cw) * 1.9); }
.pile .empty { position: absolute; left: 50%; top: 50%; translate: -50% -50%; width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: 8px; border: 2px dashed rgba(253, 250, 242, 0.25); }
.pile .card { position: absolute; left: 50%; top: 50%; translate: -50% -50%; }
.pile .count {
  position: absolute; right: -6px; bottom: -4px; min-width: 28px; padding: 3px 7px; border-radius: 999px;
  background: var(--felt-deep); border: 2px solid var(--brass-deep); font-size: 13px; font-weight: 700; text-align: center;
}
.pile .card.fresh { animation: drop 260ms ease-out; }
@keyframes drop { from { opacity: 0; scale: 1.25; } to { opacity: 1; scale: 1; } }

.news { min-height: 4em; display: grid; align-content: start; text-align: center; font-family: var(--serif); font-size: clamp(17px, 2.1vh, 24px); line-height: 1.3; max-width: 30ch; }
.news .big { font-weight: 700; font-size: 1.18em; color: var(--brass); }
.news .old { opacity: 0.45; font-size: 15px; }
.news.flash span:not(.old) { animation: flash 500ms ease-out; }
@keyframes flash { from { opacity: 0.2; } to { opacity: 1; } }

.prompt { text-align: center; font-weight: 600; font-size: clamp(15px, 1.7vh, 19px); min-height: 1.4em; color: var(--chalk); }
.prompt.mine { color: var(--ivory); }

/* Your three blind cards, each with a face-up card on top. */
.slots { display: flex; justify-content: center; gap: 10px; }
.slot { position: relative; width: var(--tw); height: calc(var(--tw) * 1.4 + var(--tw) * 0.18); }
.slot .card { --cw: var(--tw); position: absolute; left: 0; }
.slot .card.down { top: 0; }
.slot .card.up { top: calc(var(--tw) * 0.18); }
.mine-table { display: grid; justify-items: center; gap: 4px; }
.mine-table .label { font-size: 12px; color: var(--chalk); }

/* Your hand: fanned out, overlapping when it gets big. */
.hand {
  display: flex; justify-content: center; align-items: flex-end;
  min-height: calc(var(--cw) * 1.4 + 16px); padding-top: 16px;
  overflow-x: auto; scrollbar-width: none;
}
.hand::-webkit-scrollbar { display: none; }
.hand .card + .card { margin-left: var(--overlap, 6px); }
.hand .card.selected { translate: 0 -14px; box-shadow: 0 0 0 3px var(--brass), 0 6px 14px rgba(0, 0, 0, 0.35); }
.hand .empty-note { align-self: center; color: var(--chalk); font-size: 14px; }

.bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(100%, 560px); justify-self: center; }
.bar.single { grid-template-columns: 1fr; }

/* --- cards ----------------------------------------------------------------- */

.card {
  --w: var(--cw);
  position: relative; flex: 0 0 auto;
  width: var(--w); height: calc(var(--w) * 1.4);
  border-radius: calc(var(--w) * 0.1);
  background: var(--ivory); color: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  font-family: var(--serif); padding: 0; cursor: default;
  transition: translate 120ms ease-out;
}
button.card { cursor: pointer; }
.card.red { color: var(--red); }
.card .ix {
  position: absolute; left: 7%; top: 4%;
  display: grid; justify-items: center; line-height: 0.95;
  font-weight: 700; font-size: calc(var(--w) * 0.27);
}
.card .ix i { font-style: normal; font-size: 0.8em; }
.card .ix.bottom { left: auto; top: auto; right: 7%; bottom: 4%; rotate: 180deg; }
.card .pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--w) * 0.5); line-height: 1; }
.card .pip.face { font-weight: 700; font-size: calc(var(--w) * 0.4); }
/* Tiny cards (other players' face-up cards) only show the corner. */
.card.mini .ix.bottom, .card.mini .pip { display: none; }
.card.mini .ix { left: 0; right: 0; top: 10%; font-size: calc(var(--w) * 0.42); }

.card.back {
  background:
    repeating-linear-gradient(45deg, transparent 0 5px, rgba(255, 255, 255, 0.12) 5px 6px),
    repeating-linear-gradient(-45deg, transparent 0 5px, rgba(255, 255, 255, 0.12) 5px 6px),
    var(--back);
  border: calc(var(--w) * 0.06) solid var(--ivory);
}
button.card.back.can-flip { box-shadow: 0 0 0 3px var(--brass), 0 2px 4px rgba(0, 0, 0, 0.3); }
.card.up.can-play, .card.can-swap { box-shadow: 0 0 0 3px var(--brass), 0 2px 4px rgba(0, 0, 0, 0.3); }
.card.up.selected, .card.picked { box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--brass); }
.card.dim { filter: brightness(0.6); }

/* --- end of the game ------------------------------------------------------- */

.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: rgba(8, 30, 20, 0.72);
}
.overlay .box { text-align: center; display: grid; gap: 18px; }
.overlay h2 { font-family: var(--serif); font-size: 44px; margin: 0; }
.overlay p { margin: 0; color: var(--chalk); font-size: 17px; }

.toast { z-index: 60;
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); translate: -50% 0;
  background: var(--ink); color: var(--ivory); padding: 10px 16px; border-radius: 10px; font-size: 15px;
  max-width: calc(100vw - 32px); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .pile .card.fresh, .news.flash span { animation: none; }
  .card { transition: none; }
}

/* --- menu groups, joining, the lobby ---------------------------------------- */

.group { width: min(100%, 340px); display: grid; gap: 14px; }
.group h2 {
  margin: 0; padding-top: 14px; border-top: 1px solid rgba(253, 250, 242, 0.18);
  font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 20px; color: var(--chalk); text-align: left;
}
.menu .group .actions { width: 100%; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.join input {
  min-width: 0; width: 100%;
  min-height: 48px; border-radius: 999px; border: 2px solid var(--brass-deep); background: rgba(0, 0, 0, 0.18);
  color: var(--ivory); font-family: var(--serif); font-size: 22px; font-weight: 700; letter-spacing: 0.3em;
  text-align: center; text-transform: uppercase; padding: 0 12px;
}
.join input::placeholder { letter-spacing: 0.05em; font-weight: 400; font-size: 17px; color: rgba(253, 250, 242, 0.45); }
.btn.quiet { border-color: transparent; color: var(--chalk); font-weight: 600; }
.waiting { margin: 0; color: var(--chalk); font-size: 16px; }

.lobby { justify-content: flex-start; padding-top: max(36px, env(safe-area-inset-top)); }
.code-block { display: grid; justify-items: center; gap: 12px; }
.code-block p { margin: 0; color: var(--chalk); }
.code { display: flex; gap: 10px; }
.code .tile {
  width: 58px; height: 80px; display: grid; place-items: center; border-radius: 8px;
  background: var(--ivory); color: var(--ink); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  font-family: var(--serif); font-weight: 700; font-size: 40px;
}
.code .tile:nth-child(even) { color: var(--red); }
.seats { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.seats li {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 6px 4px 14px;
  border-radius: 10px; background: rgba(0, 0, 0, 0.16);
}
.seats li.away { opacity: 0.55; }
.seats .who { flex: 1; font-weight: 600; }
.seats .who em { font-style: normal; font-weight: 400; color: var(--chalk); }
.seats .what { color: var(--chalk); font-size: 14px; }
.seats .remove { width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; color: var(--chalk); font-size: 16px; cursor: pointer; }
.seat.away { opacity: 0.55; }
.lost {
  position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); translate: -50% 0; margin: 0;
  background: var(--ink); color: var(--ivory); padding: 8px 14px; border-radius: 999px; font-size: 14px;
}

/* A card on its way somewhere (see fly() in app.js). */
.flyer { position: fixed; z-index: 50; pointer-events: none; transform-origin: 0 0; }
.flyer .card { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4); }

.switch {
  min-width: 64px; height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--brass); background: transparent; color: var(--brass); font-weight: 700;
}
.switch[aria-checked="true"] { background: var(--brass); color: var(--felt-deep); }

/* The big 3, and the words that go with it. */
.flyer.three { z-index: 56; }
.flyer.three .card { box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55); }
.caption {
  position: fixed; left: 16px; right: 16px; z-index: 57;
  text-align: center; pointer-events: none;
  font-family: var(--serif); font-weight: 700; font-size: clamp(28px, min(9vw, 5.5vh), 64px); line-height: 1.05;
  color: var(--brass); text-shadow: 0 3px 0 var(--felt-deep), 0 0 24px rgba(0, 0, 0, 0.6);
}
.dimmer { position: fixed; inset: 0; z-index: 55; pointer-events: none; background: rgba(6, 24, 16, 0.6); }
