:root {
  --bg: #050a10;
  --panel: rgba(9, 18, 28, 0.92);
  --ink: #f5fbff;
  --muted: #9eb1be;
  --line: rgba(255, 255, 255, 0.14);
  --cyan: #64d7ff;
  --green: #52f59a;
  --amber: #f3c969;
  --rose: #ff6f91;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  touch-action: manipulation;
}
html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 4%, rgba(100, 215, 255, 0.13), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(82, 245, 154, 0.1), transparent 30%),
    linear-gradient(180deg, #050a10, #07111a 60%, #050a10);
}

button, select { font: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
}

.site-header {
  height: 68px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 9, 15, 0.82);
  backdrop-filter: blur(16px);
}

.container {
  width: min(1180px, calc(100% - 24px));
  margin-inline: auto;
}

.nav {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.mark {
  display: grid;
  width: 42px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid rgba(100, 215, 255, 0.42);
  border-radius: 12px;
  color: var(--cyan);
  font-weight: 950;
  background: rgba(100, 215, 255, 0.08);
}

.brand-copy strong, .brand-copy span { display: block; }
.brand-copy span { color: var(--muted); font-size: 0.72rem; }
.nav a:last-child { color: var(--muted); text-decoration: none; }

.game-wrap { padding: 14px 0 28px; }

.game-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: clamp(1.75rem, 5vw, 3.3rem); line-height: 0.95; }

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.score-chip {
  min-width: 84px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: rgba(255,255,255,.045);
  font-size: .7rem;
}
.score-chip b { display: block; margin-top: 2px; color: var(--ink); font-size: .98rem; }

.card-shell {
  overflow: hidden;
  border: 1px solid rgba(100, 215, 255, 0.26);
  border-radius: var(--radius);
  background: rgba(5, 12, 19, 0.88);
  box-shadow: 0 24px 70px rgba(0,0,0,.38);
}

.table {
  position: relative;
  min-height: 580px;
  padding: 14px;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(29, 100, 86, .28), transparent 58%),
    #071712;
  background-size: 28px 28px, 28px 28px, auto, auto;
}

.table::after {
  position: absolute;
  inset: 0;
  z-index: 18;
  border-radius: inherit;
  content: "";
  opacity: 0;
  pointer-events: none;
}

.table.is-player-take::after {
  animation: player-take-flash .82s ease-out;
}

.table.is-computer-take::after {
  animation: computer-take-flash .82s ease-out;
}

@keyframes player-take-flash {
  0% {
    opacity: .92;
    background: rgba(30, 255, 125, .34);
    box-shadow: inset 0 0 0 5px rgba(82, 245, 154, .94);
  }
  100% {
    opacity: 0;
    background: rgba(30, 255, 125, 0);
    box-shadow: inset 0 0 0 1px rgba(82, 245, 154, 0);
  }
}

@keyframes computer-take-flash {
  0% {
    opacity: .92;
    background: rgba(255, 49, 82, .34);
    box-shadow: inset 0 0 0 5px rgba(255, 92, 113, .94);
  }
  100% {
    opacity: 0;
    background: rgba(255, 49, 82, 0);
    box-shadow: inset 0 0 0 1px rgba(255, 92, 113, 0);
  }
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: rgba(6, 13, 21, 0.95);
}

.status-row strong { color: var(--ink); }

.actions { display: flex; flex-wrap: wrap; gap: 7px; }

.btn {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255,255,255,.055);
}
.btn:hover { border-color: rgba(100,215,255,.5); }
.btn:disabled { cursor: not-allowed; opacity: .42; }
.btn-primary {
  border-color: rgba(100,215,255,.5);
  background: linear-gradient(135deg, rgba(100,215,255,.22), rgba(82,245,154,.14));
  font-weight: 900;
}

.playing-card {
  --card-color: #263b4b;
  position: relative;
  width: clamp(58px, 9vw, 82px);
  aspect-ratio: .69;
  flex: 0 0 auto;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--card-color) 56%, white);
  border-radius: 10px;
  color: #101820;
  background: linear-gradient(150deg, #ffffff, #e8eef2);
  box-shadow: 0 7px 18px rgba(0,0,0,.38);
  user-select: none;
  -webkit-user-select: none;
}

button.playing-card { padding: 0; }
button.playing-card:hover, button.playing-card:focus-visible {
  outline: none;
  transform: translateY(-7px);
  box-shadow: 0 0 22px color-mix(in srgb, var(--card-color) 56%, transparent), 0 10px 20px rgba(0,0,0,.42);
}

.playing-card.is-selected {
  transform: translateY(-10px);
  box-shadow: 0 0 0 3px var(--green), 0 0 28px rgba(82,245,154,.7);
}

.playing-card.is-back {
  border-color: rgba(100,215,255,.48);
  background:
    repeating-linear-gradient(45deg, rgba(100,215,255,.18) 0 5px, transparent 5px 10px),
    linear-gradient(145deg, #101c2a, #07101a);
}
.playing-card.is-back::after {
  position: absolute;
  inset: 11%;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 7px;
  content: "MC";
  display: grid;
  place-items: center;
  color: rgba(255,255,255,.52);
  font-weight: 950;
}

.card-corner {
  position: absolute;
  top: 5px;
  left: 6px;
  z-index: 2;
  font-size: clamp(.72rem, 2vw, .92rem);
  font-weight: 950;
  line-height: .9;
  text-align: center;
}
.card-corner.bottom { inset: auto 6px 5px auto; transform: rotate(180deg); }
.card-suit { display: block; margin-top: 3px; font-size: .78em; }
.card-center {
  position: absolute;
  inset: 17%;
  display: grid;
  place-items: center;
  color: var(--card-color);
  font-size: clamp(1.55rem, 5vw, 2.6rem);
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(255,255,255,.8);
}

.napoletana-card {
  aspect-ratio: 0.585;
}

.napoletana-card:not(.is-back) {
  border: 1px solid rgba(23, 31, 35, .34);
  background-color: #fff;
  background-image: url("carte-napoletane-atlas.webp");
  background-repeat: no-repeat;
  background-position: var(--napoletana-x) var(--napoletana-y);
  background-size: 1000% 400%;
  box-shadow:
    0 7px 18px rgba(0,0,0,.42),
    inset 0 0 0 1px rgba(255,255,255,.35);
}

.napoletana-suit {
  display: block;
  width: 100%;
  height: 100%;
  color: var(--card-color);
}

.hand {
  display: flex;
  justify-content: center;
  gap: clamp(3px, 1vw, 9px);
  min-height: 120px;
}

.opponent-hand .playing-card { margin-inline: -22px; }
.opponent-hand .playing-card:first-child { margin-left: 0; }
.opponent-hand .playing-card:last-child { margin-right: 0; }

.trick-zone {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  width: min(290px, 80%);
  min-height: 150px;
  margin: 20px auto;
}
.trick-slot {
  position: relative;
  display: grid;
  place-items: center;
  padding: 25px 6px 6px;
  border: 1px dashed rgba(255,255,255,.16);
  border-radius: 13px;
  color: var(--muted);
  font-size: .7rem;
}

.trick-slot::before {
  position: absolute;
  inset: 6px 7px auto;
  color: var(--muted);
  content: attr(data-owner);
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-align: center;
  text-transform: uppercase;
}

.briscola-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--amber);
  font-weight: 900;
}

.setup-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3,8,13,.72);
  backdrop-filter: blur(10px);
}
.setup-overlay[hidden] { display: none; }
.setup-card {
  width: min(430px, 100%);
  padding: 18px;
  border: 1px solid rgba(100,215,255,.4);
  border-radius: 15px;
  background: rgba(8,17,27,.97);
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.setup-card h2 { margin: 0; font-size: 1.65rem; }
.setup-card p { color: var(--muted); }
.setup-grid { display: grid; gap: 10px; margin: 14px 0; }
.setup-grid label { display: grid; gap: 5px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.setup-grid select,
.setup-grid input[type="number"] {
  min-height: 42px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #0b1621;
}
.toggle { display: flex !important; grid-template-columns: auto 1fr; align-items: center; }

.rules {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(5,11,18,.9);
  font-size: .77rem;
}
.rules summary { color: var(--soft); cursor: pointer; font-weight: 900; }
.rules p { margin: 8px 0 0; }

@media (min-width: 901px) and (max-height: 900px) and (pointer: fine) {
  :root { --header: 54px; }

  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .site-header { height: var(--header); }
  .container { width: min(100% - 24px, 1120px); }
  .mark { width: 36px; height: 36px; border-radius: 10px; }
  .brand-copy strong { display: none; }
  .brand-copy span { color: var(--ink); font-size: .82rem; font-weight: 850; }

  .game-wrap {
    height: calc(100dvh - var(--header));
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 6px 0;
    overflow: hidden;
  }

  .game-head {
    flex: 0 0 auto;
    align-items: center;
    margin-bottom: 5px;
  }

  .game-head .eyebrow { display: none; }
  .game-head h1 { font-size: clamp(1.35rem, 3dvh, 2rem); line-height: 1; }
  .scoreboard { flex-wrap: nowrap; gap: 4px; }
  .score-chip { min-width: 72px; padding: 4px 7px; font-size: .62rem; }
  .score-chip b { margin-top: 1px; font-size: .82rem; }

  .card-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .status-row {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 4px 8px;
  }

  .status-row > strong {
    min-width: 0;
    overflow: hidden;
    font-size: .72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .actions { flex-wrap: nowrap; gap: 4px; }
  .actions .btn {
    min-height: 30px;
    padding: 4px 7px;
    font-size: .68rem;
    white-space: nowrap;
  }

  .table {
    flex: 1 1 auto;
    min-height: 0;
    padding: 7px 9px;
    overflow: hidden;
  }

  .playing-card { width: clamp(52px, 8dvh, 68px); }
  .hand { gap: 5px; min-height: 94px; }
  .opponent-hand .playing-card { margin-inline: -18px; }
  .trick-zone {
    width: min(250px, 74%);
    min-height: 128px;
    margin: 8px auto;
    gap: 10px;
  }

  .setup-overlay { padding: 8px; }
  .setup-card {
    max-height: 100%;
    padding: 12px;
    overflow-y: auto;
  }
  .setup-card h2 { font-size: 1.35rem; }
  .setup-card p { margin-block: 7px; font-size: .76rem; }
  .setup-grid { gap: 7px; margin: 8px 0; }
  .setup-grid select,
  .setup-grid input[type="number"] { min-height: 34px; }
  .setup-card > .btn { min-height: 34px; padding-block: 5px; }

  .rules { display: none; }
}

@media (min-width: 901px) and (max-height: 700px) and (pointer: fine) {
  .playing-card { width: clamp(48px, 7.4dvh, 60px); }
  .hand { min-height: 82px; }
  .trick-zone { min-height: 106px; margin-block: 5px; }
}

@media (max-width: 680px), (max-height: 620px) and (pointer: coarse) {
  .site-header { height: 54px; }
  .container { width: 100%; padding-inline: 7px; }
  .mark { width: 36px; border-radius: 10px; }
  .brand-copy { display: block; }
  .brand-copy strong { display: none; }
  .brand-copy span { color: var(--ink); font-size: .78rem; font-weight: 850; }
  .game-wrap {
    display: flex;
    flex-direction: column;
    padding-top: 5px;
  }
  .card-shell { order: 1; }
  .game-head {
    position: sticky;
    top: 0;
    z-index: 35;
    order: 0;
    display: grid;
    align-items: start;
    gap: 4px;
    margin: 0 0 6px;
    padding: 5px 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(5, 12, 19, .96);
    backdrop-filter: blur(14px);
  }
  .game-head > div:first-child { display: none; }
  .scoreboard {
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
    gap: 4px;
    width: 100%;
  }
  .score-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-width: 0;
    min-height: 30px;
    padding: 4px 8px;
  }
  .score-chip b { margin-top: 0; }
  .table {
    min-height: calc(100svh - 205px);
    min-height: calc(100dvh - 205px);
    padding: 8px 5px;
  }
  .playing-card { width: clamp(45px, 13.2vw, 64px); border-radius: 8px; }
  .hand {
    flex-wrap: wrap;
    align-content: center;
    gap: 4px;
    min-height: 96px;
  }
  .opponent-hand .playing-card { margin-inline: -17px; }
  .trick-zone {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(112px, auto);
    gap: 8px;
    width: min(300px, 92%);
    min-height: 112px;
    margin-block: 10px;
  }
  .status-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 6px;
    min-height: 0;
    padding: 7px;
  }
  .status-row > strong {
    display: block;
    min-width: 0;
    overflow: visible;
    font-size: .73rem;
    line-height: 1.35;
    white-space: normal;
  }
  .actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 5px;
  }
  .actions .btn {
    width: 100%;
    min-height: 36px;
    padding: 6px 8px;
    font-size: .72rem;
    white-space: normal;
  }
}

@media (min-width: 681px) and (max-width: 1100px) and (min-height: 621px) and (pointer: coarse) {
  .site-header { height: 58px; }
  .mark { width: 38px; border-radius: 10px; }
  .brand-copy strong { display: none; }
  .brand-copy span { color: var(--ink); font-size: .82rem; font-weight: 850; }
  .game-wrap {
    display: flex;
    flex-direction: column;
    padding-top: 6px;
  }
  .card-shell { order: 1; }
  .game-head {
    order: 2;
    display: grid;
    align-items: start;
    gap: 8px;
    margin: 10px 0 0;
    padding-inline: 4px;
  }
  .game-head .eyebrow { display: none; }
  .game-head h1 { font-size: 1.55rem; line-height: 1.05; }
  .scoreboard {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }
  .score-chip { min-width: 0; padding: 6px 8px; }
  .table {
    min-height: calc(100svh - 112px);
    min-height: calc(100dvh - 112px);
    padding-block: 8px;
  }
  .status-row {
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 5px 8px;
  }
  .status-row > strong {
    display: -webkit-box;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    font-size: .76rem;
    line-height: 1.2;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 5px;
  }
  .actions .btn {
    min-height: 34px;
    padding: 5px 8px;
    font-size: .72rem;
    white-space: nowrap;
  }
}

@media (max-height: 620px) and (pointer: coarse) {
  :root { --header: 54px; }
  .site-header { height: 54px; }
  .mark { width: 36px; height: 36px; }
  .game-wrap { padding-top: 5px; }
  .game-head h1 { font-size: clamp(1.35rem, 5vw, 2rem); }
  .table {
    min-height: calc(100dvh - 100px);
    padding-block: 5px;
  }
  .playing-card { width: clamp(48px, 7vw, 60px); }
  .hand { min-height: 104px; }
  .trick-zone {
    min-height: 112px;
    margin-block: 6px;
  }
  .table:has(> #overlay:not([hidden])) {
    height: calc(100dvh - 100px);
    min-height: calc(100dvh - 100px);
    overflow: hidden;
  }
  .table:has(> #overlay:not([hidden])) > :not(.setup-overlay) {
    display: none;
  }
  .setup-overlay { padding: 6px; }
  .setup-card {
    width: min(620px, 100%);
    max-height: 100%;
    padding: 10px 12px;
    overflow-y: auto;
  }
  .setup-card h2 { font-size: 1.3rem; }
  .setup-card p {
    margin: 6px 0;
    font-size: .75rem;
    line-height: 1.3;
  }
  .setup-grid {
    grid-template-columns: 1fr;
    align-items: end;
    gap: 8px;
    margin: 7px 0;
  }
  .setup-grid select,
  .setup-grid input[type="number"] {
    min-height: 34px;
  }
  .setup-card > .btn {
    min-height: 34px;
    padding-block: 5px;
  }
  .status-row { min-height: 36px; padding-block: 5px; }
}
