:root {
  color-scheme: dark;
  --bg: #06100b;
  --bg-2: #0a1a12;
  --felt: #0d3d2a;
  --felt-2: #092c1e;
  --panel: #0c241a;
  --panel-2: #103325;
  --panel-3: #15402f;
  --ink: #f7f2e6;
  --muted: #b9cbc1;
  --dim: #8fa79a;
  --line: #2b5542;
  --line-2: #3a6b55;
  --gold: #e8c66d;
  --gold-2: #c9a049;
  --red: #ff8a7d;
  --red-suit: #d84a3f;
  --green: #7fd6a3;
  --warn: #f0b35a;
  --focus: #ffe08a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --font-body: "Segoe UI", system-ui, -apple-system, "Noto Sans", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(36, 107, 77, 0.35), transparent 38rem),
    radial-gradient(circle at 90% 15%, rgba(232, 198, 109, 0.08), transparent 30rem),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 60%, #07140e 100%);
  background-attachment: fixed;
}

::selection {
  background: var(--gold);
  color: #102015;
}

a {
  color: var(--gold);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
  font-weight: 700;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 4.6rem);
  letter-spacing: -0.02em;
}

h2 {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.4vw, 1.75rem);
}

h3 {
  font-size: 1.05rem;
}

p {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.primary {
  background: linear-gradient(180deg, #f1d489, var(--gold));
  border-color: #f7dfa0;
  color: #17251b;
  font-weight: 700;
}

.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #ffe4a1, #e6bd5a);
}

.secondary {
  background: #143527;
  border-color: var(--line-2);
  color: var(--ink);
}

.secondary:hover:not(:disabled) {
  background: #1a4732;
  border-color: var(--gold-2);
}

.ghost-btn {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  min-height: 38px;
  padding: 0.4rem 0.6rem;
}

.ghost-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.danger-link {
  background: transparent;
  border-color: transparent;
  color: var(--red);
  padding: 0.4rem 0.6rem;
}

.danger-link:hover {
  background: rgba(255, 117, 101, 0.1);
}

.danger-btn {
  background: #7e2d2b;
  border-color: #a94743;
  color: #fff3ef;
  font-weight: 700;
}

.small-btn {
  min-height: 38px;
  padding: 0.4rem 0.8rem;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: #071b12;
  color: var(--ink);
  padding: 0.55rem 0.75rem;
}

input::placeholder {
  color: var(--dim);
}

select {
  cursor: pointer;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
  color: var(--muted);
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.skip-link {
  position: absolute;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  transform: translateY(-160%);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: var(--gold);
  color: #142015;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 0.9rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid rgba(232, 198, 109, 0.18);
  background: rgba(6, 16, 11, 0.9);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 50%;
  border: 1px solid var(--gold-2);
  background: radial-gradient(circle at 35% 30%, #1c5a40, #082318 70%);
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem 0.5rem;
}

.conn-status {
  margin-right: 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.5rem);
}

.hero {
  display: grid;
  gap: 1rem;
  max-width: 880px;
  padding: clamp(1.5rem, 5vw, 3.5rem) 0 clamp(1.5rem, 4vw, 3rem);
}

.eyebrow {
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.lead {
  max-width: 66ch;
  color: var(--muted);
  font-size: clamp(1.02rem, 1.6vw, 1.2rem);
}

.feature-list {
  display: grid;
  gap: 0.5rem;
  padding-left: 1.2rem;
  color: var(--muted);
}

.feature-list li::marker {
  color: var(--gold);
}

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.03), transparent 35%),
    var(--panel);
  box-shadow: var(--shadow);
  padding: clamp(1rem, 2.5vw, 1.5rem);
}

.panel > h2 {
  margin-bottom: 0.8rem;
}

.panel label:not(.choice) {
  margin-top: 0.9rem;
}

.panel label:first-of-type {
  margin-top: 0;
}

.field-hint,
.hint {
  margin-top: 0.35rem;
  color: var(--dim);
  font-size: 0.88rem;
}

.choice-group,
.trump-group {
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0;
  font-weight: 400;
  color: var(--muted);
}

.choice input {
  width: auto;
  min-height: auto;
  margin-top: 0.25rem;
  accent-color: var(--gold-2);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.local-status {
  min-height: 1.3rem;
  margin-top: 0.7rem;
  color: var(--warn);
  font-size: 0.92rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.panel-head h2 {
  margin: 0;
}

.lobby-panel {
  min-height: 220px;
}

.rooms-list {
  display: grid;
  gap: 0.6rem;
  margin: 0.8rem 0;
  list-style: none;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

.room-meta {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.room-meta strong {
  overflow-wrap: anywhere;
}

.room-meta span {
  color: var(--dim);
  font-size: 0.88rem;
}

.resume {
  margin-bottom: 1rem;
  border-color: var(--gold-2);
}

.access-note {
  margin-top: 1rem;
  padding: 1rem 1.2rem;
  border-left: 3px solid var(--gold-2);
  border-radius: 0 12px 12px 0;
  background: rgba(232, 198, 109, 0.05);
  color: var(--muted);
}

.access-note h2 {
  margin-bottom: 0.4rem;
  color: var(--ink);
  font-size: 1.05rem;
}

.game-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  margin-bottom: 0.8rem;
}

.room-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  color: var(--muted);
}

.room-info strong {
  color: var(--gold);
  font-size: 1.1rem;
  letter-spacing: 0.12em;
}

.room-label {
  color: var(--dim);
}

.table {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 30rem;
  padding: clamp(1rem, 2.5vw, 2rem);
  border: 1px solid rgba(232, 198, 109, 0.3);
  border-radius: clamp(18px, 4vw, 36px);
  background:
    radial-gradient(ellipse at center, rgba(35, 115, 82, 0.55) 0%, rgba(8, 42, 29, 0.95) 62%, #061b12 100%);
  box-shadow:
    inset 0 0 80px rgba(0, 0, 0, 0.45),
    var(--shadow);
}

.seats {
  display: grid;
  list-style: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.seat {
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid rgba(43, 85, 66, 0.85);
  border-radius: 14px;
  background: rgba(6, 27, 18, 0.72);
}

.seat.is-turn {
  border-color: var(--gold);
  background: rgba(24, 72, 51, 0.9);
  box-shadow: 0 0 0 2px rgba(232, 198, 109, 0.2);
}

.seat.is-me {
  border-style: double;
}

.seat.is-offline {
  opacity: 0.72;
}

.seat-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.3rem;
}

.seat-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.seat-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.badge {
  display: inline-block;
  padding: 0.05rem 0.38rem;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.badge-me,
.badge-declarer {
  border-color: var(--gold-2);
  color: var(--gold);
}

.badge-turn {
  border-color: var(--gold);
  background: var(--gold);
  color: #17251b;
  font-weight: 700;
}

.badge-offline {
  border-color: var(--red);
  color: var(--red);
}

.seat-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.8rem;
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.seat-score {
  color: var(--ink);
  font-weight: 700;
}

.seat-hand-info {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.hand-backs {
  display: inline-flex;
}

.hand-backs img {
  display: block;
  width: 1.35rem;
  height: auto;
  margin-left: -0.55rem;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.hand-backs img:first-child {
  margin-left: 0;
}

.table-center {
  display: grid;
  gap: 0.8rem;
  align-content: start;
  min-height: 13rem;
  padding: clamp(0.8rem, 2vw, 1.2rem);
  border-radius: 20px;
  background: rgba(4, 18, 12, 0.46);
  border: 1px solid rgba(43, 85, 66, 0.55);
}

.center-topline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 1rem;
}

.phase-banner {
  color: var(--gold);
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 700;
}

.timer {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.center-title {
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mini-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mini-card {
  display: block;
  width: clamp(52px, 7vw, 72px);
  height: auto;
  border-radius: 7px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.35);
}

.trick-area {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  min-height: 5.5rem;
}

.trick-empty {
  align-self: center;
  color: var(--dim);
}

.trick-card {
  margin: 0;
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  max-width: 7rem;
}

.trick-card img {
  display: block;
  width: clamp(48px, 6.5vw, 64px);
  height: auto;
  border-radius: 6px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.35);
}

.trick-card figcaption {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.last-trick {
  color: var(--dim);
  font-size: 0.9rem;
}

.revealed-area {
  padding-top: 0.6rem;
  border-top: 1px solid rgba(43, 85, 66, 0.55);
}

.revealed-hands {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.revealed-hand {
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 27, 18, 0.55);
}

.revealed-hand h3 {
  margin-bottom: 0.25rem;
  color: var(--gold);
  font-size: 0.92rem;
}

.revealed-hand p {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.revealed-discard {
  grid-column: 1 / -1;
  color: var(--dim);
  font-size: 0.9rem;
}

.hand-zone {
  display: grid;
  gap: 0.45rem;
  padding-top: 0.3rem;
}

.hand-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
}

.hand-head h2 {
  font-size: 1.15rem;
}

.hand-meta {
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(0.35rem, 1vw, 0.7rem);
  min-height: 6.5rem;
  list-style: none;
}

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

.hand-item {
  display: block;
}

.card-button {
  position: relative;
  display: block;
  width: clamp(64px, 9vw, 94px);
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  transition: transform 0.16s ease, filter 0.16s ease;
}

.card-button img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.card-button:hover {
  transform: translateY(-5px);
}

.card-button.is-selected {
  transform: translateY(-12px);
  filter: drop-shadow(0 0 0.55rem rgba(232, 198, 109, 0.75));
}

.card-button.is-selected::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 3px solid var(--gold);
  border-radius: 11px;
  pointer-events: none;
}

.card-button.is-illegal {
  filter: grayscale(0.75) brightness(0.62);
}

.card-button.is-illegal:hover {
  transform: none;
}

.card-position {
  position: absolute;
  top: -0.45rem;
  left: -0.45rem;
  display: inline-grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  background: var(--gold);
  color: #17251b;
  font-size: 0.78rem;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.card-button:focus-visible {
  outline-offset: 5px;
}

.game-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 1rem;
  margin-top: 1rem;
  align-items: start;
}

.actions > h2 {
  margin-bottom: 0.6rem;
}

.turn-status {
  margin-bottom: 0.8rem;
  color: var(--gold);
  font-weight: 700;
}

.control-note {
  margin-bottom: 0.6rem;
  color: var(--muted);
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: end;
}

.inline-controls input {
  width: min(9rem, 100%);
}

.action-feedback {
  min-height: 1.4rem;
  margin-top: 0.7rem;
  color: var(--red);
}

.log-panel {
  min-width: 0;
}

.log {
  max-height: 19rem;
  overflow: auto;
  padding: 0.2rem 0.2rem 0.2rem 0;
  list-style: none;
  scrollbar-color: var(--line-2) transparent;
}

.log-item {
  padding: 0.35rem 0.55rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.log-item + .log-item {
  margin-top: 0.15rem;
}

.log-marriage,
.log-trick_won,
.log-round_scored,
.log-finished {
  border-color: var(--gold-2);
  color: var(--ink);
}

.log-timeout,
.log-player_disconnected {
  border-color: var(--warn);
}

.log-item:focus-visible {
  outline-offset: 0;
}

.site-footer {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 2.5rem;
  border-top: 1px solid rgba(232, 198, 109, 0.14);
  color: var(--dim);
  font-size: 0.88rem;
}

.credits {
  margin-top: 0.5rem;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.clipboard-helper {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.noscript {
  position: fixed;
  inset: auto 1rem 1rem 1rem;
  z-index: 200;
  padding: 1rem 1.2rem;
  border: 1px solid var(--red);
  border-radius: 12px;
  background: #2a1110;
  color: var(--ink);
}

.dialog {
  width: min(760px, 94vw);
  max-height: 86vh;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
}

.dialog::backdrop {
  background: rgba(2, 8, 5, 0.72);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.dialog-head h2 {
  font-size: 1.45rem;
}

.dialog-body {
  overflow: auto;
  max-height: calc(86vh - 4.5rem);
  padding: 1rem 1.2rem 1.5rem;
}

.dialog-body h3 {
  margin: 1.1rem 0 0.35rem;
  color: var(--gold);
}

.dialog-body h3:first-child {
  margin-top: 0;
}

.dialog-body p {
  color: var(--muted);
}

.rules-table {
  width: 100%;
  margin: 0.6rem 0;
  border-collapse: collapse;
}

.rules-table th,
.rules-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.rules-table thead th {
  color: var(--gold);
}

.keys-table th {
  width: 9rem;
  white-space: nowrap;
}

@media (max-width: 1020px) {
  .lobby-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lobby-panel {
    grid-column: 1 / -1;
  }

  .game-bottom {
    grid-template-columns: minmax(0, 1fr);
  }

  .log {
    max-height: 14rem;
  }
}

@media (max-width: 720px) {
  .site-header {
    align-items: flex-start;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .lobby-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .seats {
    grid-template-columns: minmax(0, 1fr);
  }

  .revealed-hands {
    grid-template-columns: minmax(0, 1fr);
  }

  .room-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-button {
    width: clamp(58px, 17vw, 82px);
  }

  .hand {
    gap: 0.45rem;
  }

  .room-info {
    font-size: 0.92rem;
  }

  .conn-status {
    width: 100%;
  }
}

@media (max-width: 420px) {
  main {
    padding: 0.8rem;
  }

  .table {
    padding: 0.7rem;
  }

  .seat {
    padding: 0.6rem;
  }

  .card-button {
    width: clamp(56px, 20vw, 74px);
  }

  .card-position {
    width: 1.25rem;
    height: 1.25rem;
    font-size: 0.7rem;
  }

  .inline-controls {
    align-items: stretch;
  }

  .inline-controls input {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --muted: #e8f0eb;
    --dim: #cfded5;
    --line: #527d68;
    --line-2: #7aa78f;
    --panel: #081b12;
    --panel-2: #0b291c;
    --felt: #0a3a26;
  }

  .panel,
  .seat,
  .table-center,
  .table {
    border-width: 2px;
  }

  .card-button.is-illegal {
    filter: grayscale(1) brightness(0.5);
  }
}

@media (forced-colors: active) {
  .primary,
  .secondary,
  .ghost-btn,
  .danger-btn,
  .danger-link {
    border: 1px solid ButtonText;
  }

  .badge,
  .seat,
  .panel,
  .table,
  .table-center {
    border: 1px solid CanvasText;
  }

  .card-button.is-selected {
    outline: 3px solid Highlight;
  }
}
