:root {
  color-scheme: dark;
  --felt: #0d6a35;
  --felt-dark: #064821;
  --felt-light: #128845;
  --paper: #fffaf1;
  --ink: #171b1e;
  --muted: rgba(255, 255, 255, 0.72);
  --line: rgba(255, 255, 255, 0.18);
  --panel: rgba(3, 24, 14, 0.72);
  --accent: #ffd764;
  --danger: #e24545;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #050807;
  color: #f7fbf8;
}

button {
  font: inherit;
}

.table-shell {
  width: 100%;
  height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow: hidden;
  background:
    radial-gradient(circle at 0 86%, rgba(114, 58, 23, 0.7) 0 9%, transparent 10%),
    radial-gradient(circle at 100% 68%, rgba(114, 58, 23, 0.82) 0 7%, transparent 8%),
    linear-gradient(135deg, #111 0, #050807 100%);
}

@supports (height: 100dvh) {
  .table-shell {
    height: 100dvh;
  }
}

.game-table {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 8px solid #171717;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 47%, rgba(34, 159, 78, 0.58) 0 16%, transparent 31%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 9px),
    radial-gradient(circle at 50% 54%, var(--felt-light) 0, var(--felt) 42%, var(--felt-dark) 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), 0 28px 70px rgba(0, 0, 0, 0.48);
}

.game-table::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 47%;
  width: min(25vw, 260px);
  aspect-ratio: 1;
  border: 4px solid rgba(255, 255, 255, 0.13);
  border-left-color: transparent;
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  pointer-events: none;
}

.topbar {
  position: absolute;
  z-index: 5;
  top: 22px;
  left: 26px;
  right: 26px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 0.95;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.38);
}

.topbar p,
.player-role {
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #fff;
  background: rgba(1, 25, 13, 0.5);
  font-weight: 850;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.ghost-link {
  text-decoration: none;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #fff;
  background: rgba(1, 25, 13, 0.5);
  font-size: 25px;
  font-weight: 900;
  cursor: pointer;
}

.mode-table::before {
  top: 54%;
  width: min(38vw, 390px);
  opacity: 0.55;
}

.mode-header {
  position: absolute;
  z-index: 3;
  top: clamp(28px, 6vh, 64px);
  left: clamp(30px, 6vw, 84px);
  right: clamp(30px, 6vw, 84px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.mode-header p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.mode-choice {
  position: absolute;
  z-index: 3;
  top: 53%;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 300px));
  gap: clamp(18px, 4vw, 44px);
  transform: translate(-50%, -50%);
}

.mode-button {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 16px;
  min-height: 104px;
  padding: 16px 20px;
  border: 2px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  color: #fff;
  background: rgba(2, 31, 17, 0.78);
  text-align: left;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.mode-button-primary {
  border-color: var(--accent);
}

.mode-button:active {
  transform: translateY(1px);
}

.mode-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #a9d5ff;
  font-size: 31px;
}

.mode-icon-group {
  background: #ffd764;
}

.mode-button strong {
  align-self: end;
  font-size: 22px;
}

.mode-button > span:last-child {
  align-self: start;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.connection-badge {
  align-self: center;
  padding: 5px 10px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.72);
  background: rgba(0, 0, 0, 0.28);
  font-size: 11px;
  font-weight: 850;
}

.connection-badge.is-connected {
  color: #d9ffe6;
}

.players-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.opponent,
.human-area,
.activity-panel {
  position: absolute;
  z-index: 2;
}

.opponent {
  width: 330px;
  min-height: 178px;
  pointer-events: none;
}

.opponent-top {
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
}

.opponent-left {
  left: 54px;
  top: 38%;
  transform: translateY(-50%);
}

.opponent-right {
  right: 54px;
  top: 38%;
  transform: translateY(-50%);
}

.player-row {
  position: relative;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 16px;
  min-width: 235px;
  min-height: 46px;
  padding: 7px 18px 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
}

.player-avatar {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border: 3px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  background: linear-gradient(180deg, #dff3ff, #8ec2ff);
  font-size: 24px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.22);
}

.player-meta {
  display: grid;
  gap: 2px;
}

.player-name {
  font-size: 17px;
  font-weight: 850;
}

.player-role {
  font-size: 13px;
  font-weight: 700;
}

.turn-badge {
  position: absolute;
  right: -8px;
  top: -10px;
  display: none;
  min-width: 62px;
  padding: 5px 9px;
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  color: #251b08;
  background: var(--accent);
}

.is-turn .turn-badge {
  display: block;
}

.finish-badge {
  position: absolute;
  left: 58px;
  bottom: -12px;
  display: none;
  min-width: 92px;
  padding: 5px 10px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  background: #ffd45f;
  color: #241a07;
  text-align: center;
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.finish-badge.is-visible {
  display: block;
}

.pass-badge {
  position: absolute;
  right: -7px;
  bottom: -10px;
  display: none;
  min-width: 50px;
  padding: 5px 9px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  background: #e94b4b;
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.pass-badge.is-visible {
  display: block;
}

.opponent.is-disconnected .player-row {
  opacity: 0.58;
}

.card-backs {
  display: flex;
  height: 72px;
  margin-top: 10px;
  margin-left: 40px;
}

.card-back {
  width: 46px;
  height: 66px;
  margin-left: -18px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 7px;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.55) 0 1px, transparent 2px 5px),
    linear-gradient(135deg, #2d75b7, #1f4d82);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.3);
  transform: rotate(-6deg);
}

.card-back:first-child {
  margin-left: 0;
}

.personal-pile-wrap {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.opponent .personal-pile-wrap {
  position: absolute;
  left: 188px;
  top: 86px;
  width: 170px;
}

.opponent-left .personal-pile-wrap {
  left: 185px;
}

.opponent-right .personal-pile-wrap {
  left: -24px;
}

.pile-title {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
}

.played-pile {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 72px;
  padding: 5px;
  overflow: visible;
}

.played-pile-human {
  min-height: 96px;
}

.pile-card {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 66px;
  margin-left: -16px;
  border: 1px solid #d8cfbf;
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.32);
}

.pile-card:first-child {
  margin-left: 0;
}

.opponent .pile-card {
  margin-left: -22px;
}

.opponent .pile-card:first-child {
  margin-left: 0;
}

.pile-card.red {
  color: var(--danger);
}

.pile-card.latest-play {
  z-index: 3;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 215, 100, 0.75), 0 10px 16px rgba(0, 0, 0, 0.36);
  transform: translateY(-6px);
}

.pile-card-rank {
  position: absolute;
  top: 5px;
  left: 6px;
  font-size: 17px;
  font-weight: 950;
}

.pile-card-suit {
  position: absolute;
  right: 6px;
  bottom: 4px;
  font-size: 18px;
  font-weight: 950;
}

.human-area {
  left: 50%;
  bottom: 88px;
  display: grid;
  grid-template-columns: minmax(0, 860px);
  grid-template-rows: 108px minmax(128px, 1fr);
  grid-template-areas:
    "header"
    "handrow";
  gap: 8px;
  width: min(900px, calc(100% - 180px));
  transform: translateX(-50%);
}

.hand-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 34px;
}

.human-pill {
  position: relative;
  display: grid;
  justify-items: center;
  min-width: 146px;
  padding: 8px 22px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.24);
}

.human-avatar {
  position: absolute;
  left: -42px;
  top: 50%;
  width: 54px;
  height: 54px;
  transform: translateY(-50%);
}

.hand-header h2 {
  font-size: 18px;
}

.turn-hint {
  flex: 0 0 auto;
  min-height: 42px;
  min-width: 190px;
  max-width: 250px;
  padding: 8px 14px;
  border-radius: 999px;
  color: #251b08;
  background: var(--accent);
  text-align: center;
  font-weight: 900;
  opacity: 0;
}

.human-area.is-turn .turn-hint {
  opacity: 1;
}

.human-area .personal-pile-wrap {
  width: min(250px, 34vw);
}

.hand-row {
  grid-area: handrow;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 18px;
  min-width: 0;
}

.hand {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 0;
  min-height: 132px;
  padding: 12px 4px 18px;
  overflow: visible;
}

.card {
  position: relative;
  flex: 0 0 82px;
  width: 82px;
  height: 124px;
  margin-left: -18px;
  border: 1px solid #d8cfbf;
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 130ms ease, box-shadow 130ms ease;
}

.card:first-child {
  margin-left: 0;
}

.card.selected {
  transform: translateY(-20px);
  box-shadow: 0 22px 28px rgba(0, 0, 0, 0.38);
}

.card.locked {
  cursor: default;
  box-shadow: 0 0 0 4px rgba(255, 215, 100, 0.8), 0 22px 28px rgba(0, 0, 0, 0.38);
}

.card.disabled {
  cursor: default;
  opacity: 0.72;
}

.card-rank {
  position: absolute;
  top: 8px;
  left: 9px;
  font-size: 28px;
  font-weight: 950;
}

.card-suit {
  position: absolute;
  right: 9px;
  bottom: 7px;
  font-size: 30px;
  font-weight: 950;
}

.card.red {
  color: var(--danger);
}

.controls {
  position: absolute;
  right: 32px;
  bottom: 44px;
  z-index: 8;
  display: flex;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #251b08;
}

.secondary-button {
  color: #fff;
  background: rgba(1, 25, 13, 0.56);
  border: 1px solid var(--line);
}

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

.activity-panel {
  left: 24px;
  bottom: 38px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  width: min(430px, calc(100% - 300px));
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(3, 24, 14, 0.62);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.22);
}

.activity-panel ol {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  list-style: none;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.82);
  white-space: nowrap;
}

.activity-panel li {
  flex: 0 0 auto;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.version-label {
  position: absolute;
  right: 18px;
  bottom: 14px;
  z-index: 9;
  color: rgba(255, 255, 255, 0.42);
  font-size: 10px;
  font-weight: 800;
  pointer-events: none;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 20px;
  background: #11382f;
  color: #f7fbf8;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.52);
}

.settings-overlay[hidden] {
  display: none;
}

.settings-dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 20px;
  background: #11382f;
  color: #f7fbf8;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.settings-section {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.settings-section label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.settings-section input,
.settings-section select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(2, 20, 12, 0.58);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 750;
  -webkit-user-select: text;
  user-select: text;
}

.name-keyboard {
  display: grid;
  gap: 6px;
}

.name-key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.name-key {
  width: 34px;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.name-key-row:last-child .name-key:first-child {
  width: 150px;
}

.name-key-row:last-child .name-key:last-child {
  width: 74px;
}

.exchange-hand {
  justify-content: flex-start;
  margin-top: 14px;
  overflow-x: auto;
}

.results-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.dialog-note {
  margin-top: 14px;
  color: var(--muted);
}

.lobby-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(1, 13, 8, 0.74);
  backdrop-filter: blur(8px);
}

.lobby-overlay[hidden],
.lobby-dialog [hidden] {
  display: none;
}

.lobby-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 26px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #0d4031;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.48);
}

.lobby-dialog h2 {
  font-size: 30px;
}

.lobby-kicker {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.lobby-field {
  display: grid;
  gap: 7px;
  margin-top: 22px;
}

.lobby-field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.lobby-field input,
.room-code-input,
.lobby-field select {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 0 13px;
  color: #fff;
  background: rgba(2, 20, 12, 0.65);
  font: inherit;
  font-size: 17px;
  font-weight: 800;
}

.lobby-setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.lobby-field select {
  width: 100%;
}

.lobby-actions {
  display: grid;
  gap: 13px;
  margin-top: 18px;
}

.lobby-divider {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.room-code-input {
  letter-spacing: 4px;
  text-transform: uppercase;
}

.room-code {
  margin: 2px 0 16px;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 44px;
  font-weight: 950;
  letter-spacing: 8px;
}

.lobby-players {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.lobby-player {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.15);
}

.lobby-player-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #a9d5ff;
}

.lobby-player span:last-child,
.lobby-note {
  color: var(--muted);
  font-size: 12px;
}

.lobby-note {
  margin-top: 14px;
}

.lobby-start {
  width: 100%;
  margin-top: 18px;
}

.lobby-error {
  min-height: 20px;
  margin-top: 12px;
  color: #ffb3b3;
  font-size: 13px;
  font-weight: 800;
}

@media (max-width: 900px) {
  .mode-choice {
    grid-template-columns: repeat(2, minmax(200px, 260px));
  }

  .opponent {
    width: 265px;
  }

  .opponent-left {
    left: 30px;
  }

  .opponent-right {
    right: 30px;
  }

  .opponent .personal-pile-wrap {
    left: 146px;
    width: 146px;
  }

  .opponent-right .personal-pile-wrap {
    left: -12px;
  }

  .human-area {
    grid-template-columns: minmax(0, 1fr);
    width: calc(100% - 70px);
  }

  .card {
    flex-basis: 70px;
    width: 70px;
    height: 106px;
    margin-left: -18px;
  }

  .card-rank {
    font-size: 23px;
  }

  .card-suit {
    font-size: 24px;
  }
}
