:root {
  --felt: #35654d;                 /* gui.py's TABLE_COLOR, (53, 101, 77) */
  --felt-light: #3f7459;
  --felt-dark: #284d3b;
  --ink: #fff;
  --muted: rgba(255, 255, 255, 0.7);
  --accent: #ffd54a;

  --card-w: clamp(48px, min(16vw, 16dvh), 170px);
  --card-h: calc(var(--card-w) * 661 / 400);    /* the card art's aspect ratio */
  --radius: calc(var(--card-w) * 0.08);
  --gap: calc(var(--card-w) * 0.22);
  --peek: 0.6;                                   /* how much of the briscola shows under the deck */
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
  background: var(--felt-dark);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button {
  font: inherit;
  color: inherit;
}

/* --- Header and footer --- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 8px;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  background: rgba(0, 0, 0, 0.2);
}

.bar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.actions { display: flex; gap: 8px; }

.actions button,
.result-card button,
.rules form button {
  padding: 6px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.actions button:hover,
.result-card button:hover,
.rules form button:hover { background: rgba(255, 255, 255, 0.2); }

.actions .icon {
  min-width: 2.2em;
  padding-inline: 8px;
  border-radius: 999px;
  font-weight: 700;
}

.actions button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #1d2b22;
}

footer.bar {
  font-size: 12px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font: inherit;
  text-align: center;
}

@media (hover: none) {
  .keys { display: none; }
}

/* --- The table --- */

.felt {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, var(--felt-light) 0%, var(--felt) 55%, var(--felt-dark) 100%);
}

.card,
.card-img {
  display: block;
  flex: none;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.card img,
.card-img {
  object-fit: cover;
  user-select: none;
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
}

.hand {
  display: flex;
  justify-content: center;
  gap: var(--gap);
  padding-inline: 16px;
}

/* Both hands run off the edge of the table, as in the Pygame window. */
.hand.opponent {
  min-height: calc(var(--card-h) * 0.78);
  margin-top: calc(var(--card-h) * -0.22);
}

.hand.player {
  min-height: calc(var(--card-h) * 0.8);
  margin-bottom: calc(var(--card-h) * -0.2);
}

.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.play:disabled { cursor: default; }

.empty { visibility: hidden; }

.play .key {
  font-weight: 700;
  font-size: clamp(13px, 2.2dvh, 22px);
}

.hand.player:not(.active) .key { opacity: 0.35; }

@media (hover: hover) {
  .hand.player.active .play:hover { transform: translateY(calc(var(--card-h) * -0.08)); }
}

.hand.player.active .play:focus-visible { transform: translateY(calc(var(--card-h) * -0.08)); }
.play:focus-visible { outline: none; }
.play:focus-visible .card { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- Scores, trick, deck --- */

.middle {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-block: calc(var(--card-h) * 0.1);
  padding-inline: 16px;
}

.scores {
  justify-self: start;
  display: flex;
  flex-direction: column;
  gap: calc(var(--card-h) * 0.3);
}

.score { margin: 0; }

.score .who {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.score .pts {
  font-size: clamp(22px, 4.5dvh, 42px);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.trick {
  display: flex;
  gap: var(--gap);
}

.slot {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  outline: 1.5px dashed rgba(255, 255, 255, 0.16);
}

.slot .card { transition: transform 0.35s ease-in, opacity 0.35s ease-in; }
.slot .card.from-below { animation: from-below 0.25s ease-out; }
.slot .card.from-above { animation: from-above 0.25s ease-out; }
.slot .card.collect.to-you { transform: translateY(140%) scale(0.85); opacity: 0; }
.slot .card.collect.to-ai { transform: translateY(-140%) scale(0.85); opacity: 0; }

@keyframes from-below { from { transform: translateY(70%) scale(0.9); opacity: 0; } }
@keyframes from-above { from { transform: translateY(-70%) scale(0.9); opacity: 0; } }

.stock {
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.pile {
  position: relative;
  width: calc(var(--card-w) + var(--card-h) * var(--peek));
  height: var(--card-h);
}

.pile .deck {
  position: absolute;
  top: 0;
  right: 0;
}

/* Turned sideways and tucked under the deck, as gui.py draws it. Counterclockwise, so the
   top of the card -- the part that says which card it is -- points away from the deck. */
.pile .briscola {
  position: absolute;
  top: 0;
  left: calc(var(--card-h) / 2 - var(--card-w) / 2);
  transform: rotate(-90deg);
  transition: opacity 0.3s;
}

.pile .briscola.drawn { opacity: 0.4; }

.count {
  position: absolute;
  top: 50%;
  right: calc(var(--card-w) / 2);
  transform: translate(50%, -50%);
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.trump,
.endgame {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.endgame {
  margin-top: 2px;
  color: var(--accent);
}

.status {
  min-height: 1.6em;
  margin: 0;
  padding-block: 2px 8px;
  padding-inline: 16px;
  text-align: center;
  font-size: clamp(13px, 2dvh, 17px);
}

/* --- Overlays --- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 30, 20, 0.55);
  text-align: center;
  font-size: 16px;
}

.result-card {
  min-width: min(280px, 100%);
  padding: 24px 32px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  background: #1f4434;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.result-card h2 {
  margin: 0 0 4px;
  font-size: clamp(26px, 5vw, 38px);
}

.result-card p {
  margin: 0 0 18px;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* --- Splash screen --- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow: auto;
  padding-block: 24px;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  background: radial-gradient(ellipse at 50% 40%, var(--felt-light) 0%, var(--felt) 55%, var(--felt-dark) 100%);
  text-align: center;
}

.menu {
  --fan-w: clamp(64px, 18vw, 96px);
  --fan-h: calc(var(--fan-w) * 661 / 400);
  width: min(340px, 100%);
  animation: rise 0.4s ease-out;
}

@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

.fan {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: calc(var(--fan-h) * 1.1);
  margin-bottom: 8px;
}

.fan img {
  width: var(--fan-w);
  height: var(--fan-h);
  border-radius: calc(var(--fan-w) * 0.08);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  transform-origin: 50% 130%;
  user-select: none;
}

.fan img:nth-child(1) { transform: rotate(-16deg); margin-right: calc(var(--fan-w) * -0.25); }
.fan img:nth-child(2) { position: relative; z-index: 1; transform: translateY(-4%); }
.fan img:nth-child(3) { transform: rotate(16deg); margin-left: calc(var(--fan-w) * -0.25); }

.logo {
  margin: 12px 0 6px;
  font-size: clamp(40px, 10vw, 58px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.logo span { color: var(--accent); }

.tagline {
  margin: 0 0 24px;
  font-size: 15px;
  color: var(--muted);
  text-wrap: balance;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choices button,
.choices a {
  display: block;
  width: 100%;
  padding: 12px 20px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}

.choices button:hover:not(:disabled),
.choices a:hover { background: rgba(255, 255, 255, 0.2); }

.choices button:focus-visible,
.choices a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.choices .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1d2b22;
}

.choices .primary:hover:not(:disabled) { background: #ffe07a; }

.choices .primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.choices small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.note {
  min-height: 1.4em;
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--accent);
}

/* --- Rules --- */

dialog.rules {
  width: min(560px, calc(100% - 32px));
  max-height: min(85dvh, calc(100% - 32px));
  margin: auto;
  padding: 24px 28px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  background: #1f4434;
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

dialog.rules::backdrop { background: rgba(10, 30, 20, 0.6); }

.rules h2 {
  margin: 0 0 8px;
  font-size: 24px;
  outline: none;
}

.rules h3 {
  margin: 18px 0 4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.rules p,
.rules ul {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.5;
}

.rules ul { padding-left: 20px; }

.rules li { margin: 4px 0; }

.rules i { font-style: italic; }

.rules .values {
  margin: 4px 0 10px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.rules .values th,
.rules .values td {
  padding: 3px 20px 3px 0;
  text-align: left;
  font-size: 15px;
}

.rules .values th {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.rules .values td:nth-child(2) {
  font-style: italic;
  color: var(--muted);
}

.rules .values th:last-child,
.rules .values td:last-child {
  padding-right: 0;
  text-align: right;
}

.rules form {
  margin: 22px 0 0;
  text-align: right;
}

/* --- Narrow screens --- */

/* A phone has height to spare and no width: the scores and the deck share a row above the
   trick, and the deck gets smaller cards of its own, so the hands and the trick stay big. */
@media (max-width: 560px) {
  :root {
    --card-w: clamp(48px, min(24vw, 13dvh), 170px);
  }

  .middle {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "scores stock"
      "trick  trick";
    row-gap: calc(var(--card-h) * 0.12);
  }

  .scores {
    grid-area: scores;
    flex-direction: row;
    gap: 28px;
  }

  .trick {
    grid-area: trick;
    justify-self: center;
  }

  .stock {
    grid-area: stock;
    --card-w: 44px;
    --card-h: calc(var(--card-w) * 661 / 400);
    --radius: calc(var(--card-w) * 0.08);
  }

  .bar h1 { font-size: 16px; }
  footer.bar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .slot .card,
  .play,
  .pile .briscola,
  .menu {
    animation: none !important;
    transition: none !important;
  }
}
