:root {
  color-scheme: dark;
  --bg: #071413;
  --felt: #0f7a4d;
  --felt-dark: #085239;
  --gold: #f3c45b;
  --red: #d94848;
  --blue: #3e86ff;
  --text: #fff7e8;
  --muted: rgba(255, 247, 232, 0.66);
  --panel: rgba(8, 19, 18, 0.82);
  --line: rgba(255, 255, 255, 0.16);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text);
  background:
    radial-gradient(circle at 18% 18%, rgba(243, 196, 91, 0.16), transparent 24%),
    linear-gradient(145deg, #071413, #10211f 48%, #081210);
}

body.in-room {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 800;
  line-height: 1.1;
}

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

input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  outline: none;
}

.hidden {
  display: none !important;
}

.app {
  width: 100%;
  min-height: 100vh;
  padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  gap: 8px;
  align-items: center;
  max-width: 980px;
  height: 34px;
  margin: 0 auto 6px;
}

.topbar strong,
.topbar span {
  display: block;
  text-align: center;
}

.topbar strong {
  font-size: 14px;
}

.topbar span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 10px;
}

.icon-btn {
  width: 34px;
  height: 32px;
  padding: 0;
  font-size: 13px;
}

.primary {
  border-color: rgba(243, 196, 91, 0.65);
  background: linear-gradient(180deg, #ffe08b, #f2ad32);
  color: #3a2100;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.small {
  padding: 8px 12px;
}

.lobby {
  display: grid;
  gap: 18px;
  max-width: 520px;
  margin: 8vh auto 0;
}

.brand {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(8, 19, 18, 0.7);
}

.brand span {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
}

.brand h1 {
  margin: 8px 0;
  font-size: 76px;
  line-height: 0.94;
  letter-spacing: 0;
}

.brand p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.actions {
  display: grid;
  gap: 12px;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 10px;
}

.room {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 5px;
  max-width: 980px;
  height: calc(100dvh - 42px);
  margin: 0 auto;
  overflow: hidden;
}

.room.playing {
  grid-template-rows: 1fr;
}

.room-status,
.room-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}

.room-status > div {
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.room-status span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.room-status strong {
  display: block;
  margin-top: 1px;
  font-size: 13px;
}

.room.playing .room-status {
  display: none;
}

.playfield {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.table {
  position: relative;
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(243, 196, 91, 0.62);
  border-radius: 999px;
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.12), transparent 44%),
    linear-gradient(180deg, var(--felt), var(--felt-dark));
  box-shadow:
    inset 0 0 0 5px rgba(0, 0, 0, 0.18),
    0 10px 22px rgba(0, 0, 0, 0.32);
  overflow: hidden;
}

.table-core {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: min(44%, 300px);
  min-height: 72px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(2, 24, 17, 0.5);
  text-align: center;
}

.table-core strong {
  font-size: 15px;
}

.table-core span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.room.playing .table-core {
  width: min(46%, 340px);
  min-height: 66px;
  transform: translate(-50%, -68%);
}

.room.playing .table-core > strong,
.room.playing .table-core > span {
  display: none;
}

.seats {
  position: absolute;
  inset: 0;
}

.seat {
  position: absolute;
  display: grid;
  place-items: center;
  width: 66px;
  min-height: 54px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(3, 13, 12, 0.72);
  text-align: center;
}

.seat:nth-child(1) { left: 50%; bottom: 8px; transform: translateX(-50%); }
.seat:nth-child(2) { right: 5%; bottom: 21%; }
.seat:nth-child(3) { right: 5%; top: 18%; }
.seat:nth-child(4) { left: 50%; top: 8px; transform: translateX(-50%); }
.seat:nth-child(5) { left: 5%; top: 18%; }
.seat:nth-child(6) { left: 5%; bottom: 21%; }

.avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-weight: 900;
}

.seat.occupied .avatar {
  background: var(--gold);
  color: #302000;
}

.seat.ai .avatar {
  background: #6e7881;
  color: #fff;
}

.seat.local {
  border-color: var(--gold);
}

.seat strong {
  display: block;
  max-width: 58px;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

.seat span {
  color: var(--muted);
  font-size: 9px;
}

.seat em {
  margin-top: 1px;
  color: var(--gold);
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
}

.room-actions {
  grid-template-columns: 1fr 1fr 1fr;
}

.room.playing .room-actions {
  display: none;
}

.game-panel {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  display: grid;
  grid-template-columns: 1fr 128px;
  grid-template-rows: 22px 1fr;
  gap: 4px 8px;
  padding: 6px;
  border: 1px solid rgba(243, 196, 91, 0.46);
  border-radius: 8px;
  background: rgba(5, 18, 15, 0.82);
}

.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  grid-column: 1 / 2;
  min-width: 0;
}

.game-bar strong {
  font-size: 12px;
}

.game-bar span {
  color: var(--muted);
  font-size: 11px;
}

.hand {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, 52px);
  grid-auto-columns: 24px;
  gap: 2px 0;
  min-height: 106px;
  max-height: 116px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 18px 2px 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.card {
  display: grid;
  place-items: center;
  width: 36px;
  min-height: 50px;
  margin-left: 0;
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 4px;
  background: #fffdf5;
  color: #1e2425;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.28);
}

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

.card.selected {
  transform: translateY(-7px);
  outline: 2px solid var(--gold);
}

.card.red {
  color: #c82424;
}

.table-play {
  min-height: 28px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--muted);
  font-size: 12px;
}

.play-actions {
  display: grid;
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  grid-template-columns: 1fr;
  align-content: end;
  gap: 7px;
}

.play-actions button {
  min-height: 38px;
}

.chat {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 12;
  display: grid;
  gap: 8px;
  width: min(300px, calc(100vw - 16px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.chat.collapsed {
  display: none;
}

.chat-fab {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 13;
  min-width: 58px;
  min-height: 32px;
}

.chat-fab.open {
  bottom: 176px;
}

.messages {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 58px;
  max-height: 88px;
  overflow: auto;
  color: var(--muted);
  font-size: 12px;
}

.message-line strong {
  color: var(--text);
}

.chat-input {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.82);
  color: var(--text);
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.58);
}

.modal-card {
  display: grid;
  gap: 10px;
  width: min(360px, 100%);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0c1b19;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal-card header {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 10px;
  align-items: center;
}

.modal-card strong {
  font-size: 18px;
}

.modal-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.rotate-tip {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 28px;
  background: linear-gradient(180deg, #071413, #0f7a4d);
  text-align: center;
}

.rotate-tip strong {
  font-size: 28px;
}

.rotate-tip span {
  color: var(--muted);
}

@media (orientation: portrait) {
  body.in-room {
    width: 100vh;
    height: 100vw;
    min-height: 100vw;
    transform: rotate(90deg) translateY(-100%);
    transform-origin: top left;
    overflow: hidden;
  }

  body.in-room .app {
    width: 100vh;
    height: 100vw;
    min-height: 100vw;
    overflow: hidden;
    padding: 8px max(12px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
  }

  body.in-room .room {
    height: calc(100vw - 40px);
  }

  body.in-room .chat {
    width: min(330px, calc(100vh - 24px));
  }

  body.in-room .rotate-tip {
    display: none !important;
  }
}

@media (max-width: 720px) {
  .app {
    padding-inline: 8px;
  }

  .brand h1 {
    font-size: 58px;
  }

  .room-status {
    grid-template-columns: 1fr 1fr;
  }

  .room-status button {
    grid-column: 1 / -1;
  }

  .table {
    border-radius: 28px;
  }

  .seat {
    width: 62px;
  }

  .seat:nth-child(2),
  .seat:nth-child(3) { right: 2%; }
  .seat:nth-child(5),
  .seat:nth-child(6) { left: 2%; }
}
