:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  font-synthesis: none;
  --ink: #f8f5e9;
  --muted: #c2cbbb;
  --gold: #e9c784;
  --line: rgba(233, 199, 132, .28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 50% -10%, #32443a, #0d1c19 57%, #091210);
}
button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid #ffe5a0; outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .48; }
.app-shell { max-width: 1440px; margin: auto; padding: 0 24px 30px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  min-height: 84px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px;
  color: #132b28; background: linear-gradient(145deg, #ffe8b5, #d5a95d);
  box-shadow: inset 0 2px 1px #fff7dc, 0 6px 16px #0005; font-size: 29px;
}
.brand strong { display: block; font-size: 18px; line-height: 1; letter-spacing: 0; }
.brand small { display: block; margin-top: 5px; color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: 1.5px; }
.top-actions { display: flex; gap: 8px; }
.utility-button {
  min-height: 39px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink); border: 1px solid var(--line); background: #ffffff0e; border-radius: 6px;
  text-decoration: none; font-weight: 700;
}
.utility-button:hover { background: #ffffff1e; }
.game-heading { display: flex; justify-content: space-between; align-items: end; gap: 18px; padding: 24px 4px 19px; }
.eyebrow, .feedback-label, .table-kicker { color: var(--gold); font-size: 11px; font-weight: 900; letter-spacing: 1.6px; }
h1 { margin: 3px 0 0; font-family: Georgia, serif; font-size: clamp(34px, 4vw, 52px); line-height: 1; font-weight: 700; letter-spacing: 0; }
.round-info { display: flex; align-items: center; gap: 13px; color: #e0e7d8; font-size: 13px; font-weight: 700; white-space: nowrap; }
.round-divider { height: 18px; width: 1px; background: var(--line); }
.table-wrap { border: 1px solid #d2b67b80; border-radius: 12px; padding: 5px; background: #563d26; box-shadow: 0 22px 48px #0008, inset 0 0 0 1px #efd8a46b; }
.table-scene {
  position: relative; min-height: 500px; height: min(61vw, 650px); overflow: hidden; border-radius: 8px;
  background: #0d4035 url("assets/table.jpg") center center / cover no-repeat;
  isolation: isolate;
}
.table-scene::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, #07181422 0%, transparent 28%, transparent 57%, #0718146b 100%); pointer-events: none; z-index: -1; }
.opponent {
  position: absolute; z-index: 2; display: flex; align-items: center; gap: 9px;
  min-width: 116px; padding: 8px 10px; border: 1px solid #f7eac24a; border-radius: 8px;
  color: white; background: #102a28d9; backdrop-filter: blur(12px); box-shadow: 0 10px 24px #0006;
}
.opponent.active {
  border-color: #ffe09a; background: #1b5147;
  box-shadow: 0 0 0 3px #f5cc75, 0 0 28px #f5cc7580, 0 12px 24px #0007;
  animation: turn-pulse 1.35s ease-in-out infinite;
}
.opponent.active::after {
  content: "TURN"; position: absolute; top: -13px; right: 7px; padding: 3px 7px;
  border-radius: 4px; color: #183128; background: #ffe09a; box-shadow: 0 3px 8px #0007;
  font-size: 9px; font-weight: 900; letter-spacing: 1px;
}
.player-zone.active .player-line {
  border-color: #ffe09a; background: #16483f;
  box-shadow: 0 0 0 3px #f5cc75, 0 0 30px #f5cc7570, 0 12px 24px #0007;
  animation: turn-pulse 1.35s ease-in-out infinite;
}
@keyframes turn-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.16); }
}
.opponent-top { top: 24px; left: 50%; transform: translateX(-50%); }
.opponent-left { top: 39%; left: 27px; }
.opponent-right { top: 39%; right: 27px; }
.avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; color: #142923; background: #e9d2a7; font-family: Georgia, serif; font-size: 18px; font-weight: 800; }
.opponent:nth-of-type(2) .avatar { background: #8ed6ca; }
.opponent:nth-of-type(3) .avatar { background: #e9a98c; }
.opponent-label { display: flex; flex-direction: column; line-height: 1.12; }
.opponent-label strong { font-size: 13px; }
.opponent-label small { color: #cfddcf; margin-top: 4px; font-size: 11px; }
.opponent-backs { display: flex; padding-left: 9px; }
.mini-back { width: 19px; height: 29px; margin-left: -9px; border: 1px solid #f0d598; border-radius: 3px; background: #080808 url("assets/cards/card-back-black.svg") center / cover; box-shadow: 1px 2px 3px #0008; transform: rotate(4deg); }
.mini-back:nth-child(2) { transform: rotate(-4deg) translateY(-2px); }
.mini-back:nth-child(3) { transform: rotate(7deg); }
.table-center { position: absolute; z-index: 1; inset: 19% 17% 29%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; pointer-events: none; }
.table-kicker { color: #f0d8a3; text-shadow: 0 2px 4px #000; }
.pile-cards { position: relative; width: min(430px, 74vw); min-height: 190px; display: grid; place-items: center; }
.pile-caption { min-height: 26px; padding: 4px 10px; color: #f9f6e9; background: #0e352ac7; border: 1px solid #d9cc9a5c; border-radius: 5px; font-size: 13px; font-weight: 800; text-align: center; }
.open-emblem { color: #e9c782; font-family: Georgia, serif; font-size: 83px; line-height: 1; opacity: .9; text-shadow: 0 4px 12px #0009; }
.pile-layer {
  position: absolute; left: 50%; top: 50%; display: flex; align-items: center; justify-content: center;
  gap: clamp(2px, .45vw, 7px); transform-origin: 50% 62%;
  transform: translate(-50%, calc(-50% + (var(--depth) * 18px))) rotate(calc((var(--depth) - 2) * -4deg)) scale(calc(1 - (var(--depth) * .045)));
  z-index: calc(20 - var(--depth)); opacity: calc(1 - (var(--depth) * .14)); filter: brightness(calc(1 - (var(--depth) * .08))) saturate(calc(1 - (var(--depth) * .08)));
}
.pile-layer::before {
  content: ""; position: absolute; inset: 8% -5%; border-radius: 16px;
  background: radial-gradient(ellipse at center, #07150f80 0%, #07150f30 52%, transparent 76%);
  filter: blur(4px); transform: translateY(18px); z-index: -1;
}
.pile-layer.is-current {
  transform: translate(-50%, -67%) rotate(-1deg) scale(1.08);
  z-index: 40; opacity: 1; filter: none;
}
.player-zone { position: absolute; z-index: 3; left: 50%; bottom: 16px; width: min(860px, calc(100% - 36px)); transform: translateX(-50%); }
.player-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 820px; min-height: 49px; margin: 0 auto 16px; padding: 5px 9px; border-radius: 7px; background: #0e2a27db; border: 1px solid #ffffff26; backdrop-filter: blur(9px); }
.player-identity { display: flex; align-items: center; gap: 9px; }
.avatar-you { background: var(--gold); }
.player-identity strong, .player-identity small { display: block; }
.player-identity strong { font-size: 13px; }
.player-identity small { color: #d3dfd1; font-size: 11px; }
.turn-indicator { padding: 7px 11px; color: #11251d; background: var(--gold); border-radius: 5px; font-size: 12px; font-weight: 900; white-space: nowrap; }
.turn-indicator.waiting { color: #e4e9e1; background: #ffffff2a; }
.hand { position: relative; width: 100%; height: 132px; }
.playing-card {
  width: 80px; height: auto; aspect-ratio: 5 / 7; flex: none; padding: 0; appearance: none;
  border-radius: 7px; border: 0;
  color: #13232e; background: #fff;
  box-shadow: 0 5px 10px #0007;
  display: block; position: relative; overflow: hidden; line-height: 0; user-select: none;
}
.playing-card.red { color: #bb3541; }
.playing-card.black { color: #172e40; }
.hand .playing-card { position: absolute; left: 0; bottom: 0; transition: transform .17s ease, filter .17s ease; }
.hand .playing-card:hover { transform: translateY(-9px); filter: brightness(1.05); }
.hand .playing-card.selected, .hand .playing-card.selected:hover { transform: translateY(-20px); box-shadow: 0 0 0 4px #d9a23d, 0 7px 18px #000a; }
.card-face-image { display: block; width: 100%; height: 100%; border-radius: inherit; object-fit: contain; pointer-events: none; }
.pile-cards .playing-card {
  width: clamp(48px, 5.2vw, 74px); height: auto; aspect-ratio: 5 / 7;
  margin-left: calc(var(--card) * -10px);
  transform: translateY(var(--lift)) rotate(var(--angle));
}
.pile-cards .playing-card:first-child { margin-left: 0; }
.pile-layer.is-current .playing-card { box-shadow: 0 8px 17px #0009, 0 0 0 1px #ffe1a74f; }
.control-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 17px 3px 0; }
.feedback { min-width: 215px; }
.feedback-label { font-size: 10px; }
.feedback p { margin: 4px 0 0; color: #ecf0e5; font-size: 14px; line-height: 1.35; }
.game-actions { display: flex; justify-content: end; flex-wrap: wrap; gap: 8px; }
.action-button { min-height: 43px; padding: 0 16px; border-radius: 6px; font-size: 13px; font-weight: 900; white-space: nowrap; }
.action-button.secondary { color: #e9eadc; border: 1px solid var(--line); background: #ffffff10; }
.action-button.secondary:hover:not(:disabled) { background: #ffffff23; }
.action-button.pass { color: #f7eee4; border: 1px solid #ae7265; background: #6a3732; }
.action-button.pass:hover:not(:disabled) { background: #81433c; }
.action-button.primary, .modal-button { color: #173229; border: 1px solid #ffe7a4; background: linear-gradient(#ffe5a0, #ddb468); box-shadow: inset 0 1px #fff2c9, 0 4px 0 #8d6332; }
.action-button.primary { min-width: 138px; }
.action-button.primary:hover:not(:disabled), .modal-button:hover { filter: brightness(1.07); }
.modal { width: min(580px, calc(100% - 28px)); max-height: calc(100vh - 36px); padding: 0; color: #eaf1e8; background: #162a27; border: 1px solid #b99660; border-radius: 10px; box-shadow: 0 25px 70px #000b; }
.modal::backdrop { background: #03100dcc; backdrop-filter: blur(4px); }
.modal-content { padding: 27px; }
.modal-top { display: flex; justify-content: space-between; align-items: start; }
.close-button { border: 0; color: white; background: transparent; font-size: 28px; line-height: 1; }
.modal h2 { margin: 6px 0 14px; font-family: Georgia, serif; font-size: 32px; }
.modal p { color: #d5e0d2; line-height: 1.5; }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 15px 0; border-top: 1px solid var(--line); }
.rule-grid strong { color: var(--gold); }
.rule-grid p { margin: 7px 0 0; font-size: 14px; }
.modal-button { width: 100%; min-height: 44px; margin-top: 12px; border-radius: 6px; font-weight: 900; }
.result-scores { display: grid; gap: 7px; margin: 20px 0; }
.result-scores div { display: flex; justify-content: space-between; padding: 10px 12px; border: 1px solid var(--line); border-radius: 5px; }
.result-scores span { color: var(--gold); }
.rules-overview { margin-top: 28px; padding: 22px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.rules-overview-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.rules-overview-heading h2 { max-width: 560px; margin: 0; font-family: Georgia, serif; font-size: 24px; line-height: 1.15; }
.rules-overview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 24px; margin-top: 20px; }
.rules-overview-grid div { display: grid; gap: 5px; }
.rules-overview-grid strong { color: #ffdc94; font-size: 14px; }
.rules-overview-grid span { color: #cfdbd1; font-size: 13px; line-height: 1.45; }
.rules-overview > p { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.rules-overview > p strong { color: var(--gold); }
.room-entry {
  width: min(920px, 100%); min-height: 600px; margin: 32px auto 0; padding: clamp(24px, 5vw, 58px);
  border: 1px solid #d2b67b80; border-radius: 10px;
  background: linear-gradient(120deg, #0b1d1cfa, #143c37eb), url("assets/table.jpg") center / cover;
  box-shadow: 0 22px 48px #0008;
}
.entry-heading p { margin: 11px 0 0; color: var(--muted); font-size: 17px; }
.entry-controls { margin-top: 35px; }
.entry-controls label, .join-row label { display: block; margin-bottom: 9px; color: var(--gold); font-size: 13px; font-weight: 900; }
.entry-controls input {
  width: min(360px, 100%); min-height: 46px; padding: 0 14px; color: #182a28;
  border: 1px solid #c5d2c3; border-radius: 5px; background: #faf9f1; font: inherit;
}
.entry-controls input:focus-visible { outline: 3px solid #f7cc71; outline-offset: 2px; }
.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; margin: 27px 0; }
.mode-button {
  min-height: 128px; padding: 19px; text-align: left; color: var(--ink);
  border: 1px solid #d0bd86a6; border-radius: 7px; background: #123c37db;
  box-shadow: inset 0 1px #ffffff1c, 0 5px 0 #08211e;
}
.mode-button:hover:not(:disabled) { background: #1b524a; transform: translateY(-2px); }
.mode-button strong { display: block; margin-bottom: 9px; color: #ffdd99; font-family: Georgia, serif; font-size: 21px; }
.mode-button span { display: block; color: #d1e0d6; font-size: 13px; line-height: 1.45; }
.join-row { padding-top: 24px; border-top: 1px solid var(--line); }
.join-row > div { display: flex; gap: 10px; align-items: center; }
.join-row input { max-width: 210px; text-transform: uppercase; letter-spacing: 2px; }
.join-row .modal-button { width: auto; min-width: 108px; min-height: 44px; margin: 0 0 4px; padding: 0 16px; }
.entry-error { margin: 19px 0 0; color: #ffe2ac; font-weight: 700; }
.waiting-entry { max-width: 640px; min-height: 0; }
.waiting-entry h1 { margin-top: 11px; }
.waiting-code { display: flex; align-items: center; flex-wrap: wrap; gap: 13px; margin: 32px 0; }
.waiting-code > span { color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: 1px; }
.waiting-code strong { color: #ffdf99; font-family: Georgia, serif; font-size: 30px; letter-spacing: 3px; }
.waiting-list { display: grid; gap: 7px; }
.waiting-list > div { display: flex; justify-content: space-between; gap: 15px; padding: 12px 15px; border: 1px solid #ffffff2b; border-radius: 5px; background: #ffffff0c; }
.waiting-list span { color: var(--muted); font-size: 13px; }
.waiting-entry p { margin: 19px 0; color: #d5e3d6; line-height: 1.5; }
.waiting-entry .action-button { min-width: 180px; }

@media (max-width: 900px) {
  .table-scene { height: 590px; }
  .opponent-left { left: 14px; }
  .opponent-right { right: 14px; }
  .table-center { inset: 22% 12% 34%; }
  .control-panel { align-items: stretch; flex-direction: column; }
  .game-actions { justify-content: stretch; }
  .game-actions .action-button { flex: 1 1 auto; }
}
@media (max-width: 600px) {
  .app-shell { padding: 0 10px 20px; }
  .topbar { min-height: 67px; }
  .topbar { flex-wrap: wrap; padding: 10px 0; }
  .top-actions { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); }
  .brand-mark { width: 36px; height: 36px; font-size: 25px; }
  .brand strong { font-size: 15px; }
  .brand small { font-size: 8px; }
  .utility-button { min-height: 36px; padding: 0 8px; font-size: 11px; }
  .game-heading { padding: 19px 2px 15px; }
  h1 { font-size: 36px; }
  .eyebrow { font-size: 9px; }
  .round-info { align-items: end; flex-direction: column; gap: 3px; font-size: 11px; }
  .round-divider { display: none; }
  .table-scene { height: 540px; min-height: 540px; background-position: center; }
  .opponent { min-width: 0; padding: 6px; gap: 5px; }
  .opponent .avatar { width: 25px; height: 25px; font-size: 14px; }
  .opponent-label strong { font-size: 10px; }
  .opponent-label small { font-size: 9px; }
  .opponent-backs { display: none; }
  .opponent-top { top: 17px; }
  .opponent-left { top: 27%; left: 9px; }
  .opponent-right { top: 27%; right: 9px; }
  .table-center { inset: 32% 3% 29%; gap: 8px; }
  .pile-cards { min-height: 100px; }
  .player-zone { bottom: 9px; width: calc(100% - 16px); }
  .player-line { margin-bottom: 13px; }
  .hand { height: 106px; }
  .hand .playing-card { width: 64px; height: auto; aspect-ratio: 5 / 7; border-radius: 5px; }
  .feedback { min-width: 0; }
  .game-actions { display: grid; grid-template-columns: repeat(6, 1fr); }
  .game-actions .secondary { grid-column: span 2; }
  .game-actions .pass, .game-actions .primary { grid-column: span 3; }
  .action-button { padding: 0 7px; font-size: 12px; }
  .rule-grid { grid-template-columns: 1fr; gap: 15px; }
  .modal-content { padding: 22px; }
  .room-entry { min-height: 0; margin-top: 18px; padding: 24px 18px 28px; }
  .rules-overview-heading { align-items: start; flex-direction: column; gap: 5px; }
  .rules-overview-heading h2 { font-size: 21px; }
  .rules-overview-grid { grid-template-columns: 1fr; gap: 13px; }
  .entry-controls { margin-top: 26px; }
  .mode-grid { grid-template-columns: 1fr; gap: 10px; margin: 22px 0; }
  .mode-button { min-height: 0; padding: 14px 16px; }
  .mode-button strong { margin-bottom: 4px; font-size: 19px; }
  .join-row > div { align-items: stretch; }
  .join-row input { min-width: 0; }
  .waiting-code { align-items: start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .hand .playing-card { transition: none; }
  .opponent.active, .player-zone.active .player-line { animation: none; }
}
