:root {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  color: #1b1208;
  background: #f4d89b;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  /* Rotated WebView shells can map visual vertical panning onto the layout x-axis. */
  overflow-x: auto;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: visible;
  overscroll-behavior-x: auto;
  overscroll-behavior-y: none;
}

#app {
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

button,
input {
  font: inherit;
  min-width: 0;
}

button {
  max-width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 13px;
  padding: 0 14px;
  color: #fff8df;
  background: #8b310e;
  box-shadow: 0 5px 0 #4d1b09;
  cursor: pointer;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  white-space: normal;
}

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

button.primary {
  background: #116149;
  box-shadow: 0 5px 0 #06392a;
}

button.ghost {
  color: #3b210d;
  background: #f1c66d;
  box-shadow: 0 5px 0 #a36d24;
}

input {
  min-width: 0;
  width: 100%;
  min-height: 40px;
  border: 2px solid #7a3d12;
  border-radius: 12px;
  padding: 0 12px;
  color: #281306;
  background: #fff5d6;
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid #ffe06b;
  outline-offset: 2px;
}

.app {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  overflow-wrap: anywhere;
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 241, 179, 0.9), transparent 28%),
    linear-gradient(135deg, #f2ca72, #c5511c 48%, #61310f);
}

.app.phase-calling,
.app.phase-redeal,
.app.phase-robbing,
.app.phase-doubling {
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 238, 153, 0.9), transparent 30%),
    linear-gradient(135deg, #ffd166, #d65f22 52%, #4b2a0c);
}

.app.phase-playing {
  background:
    radial-gradient(circle at 85% 10%, rgba(122, 219, 174, 0.75), transparent 30%),
    linear-gradient(135deg, #e0bd64, #237a57 48%, #173c30);
}

.app.phase-result {
  background:
    radial-gradient(circle at 50% 5%, rgba(255, 248, 202, 0.9), transparent 30%),
    linear-gradient(135deg, #f1b34d, #9f321e 52%, #2f170c);
}

.hero,
.panel {
  border: 3px solid #3c1b07;
  border-radius: 24px;
  background: rgba(255, 245, 214, 0.94);
  box-shadow: 0 16px 0 rgba(60, 27, 7, 0.35);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin: 0 auto 22px;
  max-width: 1440px;
  padding: 22px;
}

.hero > * {
  min-width: 0;
}

.app.has-room .hero {
  margin-bottom: 16px;
  padding: 14px 18px;
}

.app.has-room h1 {
  font-size: clamp(30px, 3.8vw, 46px);
}

.app.has-room .subtitle {
  margin-bottom: 0;
}

.app.has-session {
  padding-top: 18px;
}

.app.has-session .hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 18px;
}

.app.has-session .eyebrow,
.app.has-session .subtitle {
  display: none;
}

.app.has-session h1 {
  margin: 0;
  font-size: clamp(24px, 2.7vw, 34px);
  line-height: 1;
}

.app.has-session .status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  min-width: 0;
  text-align: right;
}

.app.has-session .status span {
  align-self: center;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #8b310e;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(34px, 6vw, 72px);
  line-height: 0.95;
}

.subtitle,
.muted,
small {
  color: #66411c;
}

.status {
  display: grid;
  gap: 8px;
  max-width: 100%;
  min-width: 160px;
  text-align: right;
}

.status strong,
.chips span {
  border-radius: 999px;
  padding: 8px 12px;
  color: #fff7db;
  background: #3c1b07;
}

.route-bar,
.page-shell {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

.route-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  border: 3px solid #3c1b07;
  border-radius: 20px;
  padding: 10px 12px;
  background: rgba(255, 245, 214, 0.92);
  box-shadow: 0 10px 0 rgba(60, 27, 7, 0.28);
}

.route-title {
  display: grid;
  flex: 1 1 220px;
  gap: 2px;
  min-width: 0;
}

.route-title strong {
  font-size: 18px;
}

.route-title span {
  color: #66411c;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  min-width: 0;
  max-width: 100%;
}

.route-actions button,
.back-button {
  box-shadow: none;
  min-height: 48px;
}

.page-stack {
  display: block;
}

.panel {
  min-width: 0;
  max-width: 100%;
  padding: 18px;
}

.lobby {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.lobby.sub-page {
  grid-template-columns: 1fr;
}

.side {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.full {
  width: 100%;
  margin: 12px 0;
}

label,
.section-title {
  display: flex;
  justify-content: space-between;
  margin: 14px 0 8px;
  font-weight: 800;
}

.rooms {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.feed-list {
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  min-height: 220px;
  max-height: min(52vh, 520px);
  overflow-y: auto;
  padding: 2px 2px 6px;
  -webkit-overflow-scrolling: touch;
}

.settings-card,
.message-block,
.room-card,
.player,
.center,
.settlement,
.hand {
  max-width: 100%;
  min-width: 0;
  border: 2px solid #7a3d12;
  border-radius: 18px;
  padding: 12px;
  background: #ffe8a9;
}

.room-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-card p,
.room-card small {
  margin: 4px 0 0;
}

.room-actions {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.table {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.42fr);
  grid-template-areas:
    "head head"
    "players players"
    "center center"
    "settlement settlement"
    "hand actions";
  gap: 16px;
  align-self: start;
  max-width: 100%;
  min-width: 0;
}

.table-head {
  grid-area: head;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 18px;
  padding: 14px;
  color: #fff7db;
  background: #3c1b07;
  min-width: 0;
}

.table-head > * {
  min-width: 0;
}

.table-head p {
  margin-bottom: 0;
  color: #ffe9a8;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  min-width: 0;
}

.chips span {
  color: #241104;
  background: #ffd66f;
  min-width: 0;
  overflow-wrap: anywhere;
}

.players {
  grid-area: players;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.player,
.player strong,
.player small,
.status strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.player.active {
  outline: 4px solid #116149;
  background: #d8ffe8;
}

.player.mine {
  background: #fff2c6;
  box-shadow: inset 0 0 0 3px rgba(17, 97, 73, 0.18);
}

.player em {
  border-radius: 999px;
  padding: 2px 6px;
  color: #fff8df;
  background: #8b310e;
  font-style: normal;
  font-size: 12px;
}

.player > span,
.player > small {
  display: block;
  margin-top: 6px;
}

.public-hand {
  margin-top: 8px;
  padding: 2px 2px 5px;
}

.center {
  grid-area: center;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-width: 0;
}

.wallet {
  border-radius: 14px;
  padding: 10px 12px;
  background: #fff2c6;
}

.settlement {
  grid-area: settlement;
  grid-column: 1 / -1;
}

.settlement span {
  display: inline-block;
  margin: 0 6px 6px 0;
  border-radius: 999px;
  padding: 5px 9px;
  color: #fff7db;
  background: #3c1b07;
}

.actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-content: end;
  border: 2px solid #3c1b07;
  border-radius: 18px;
  padding: 12px;
  background: #fff2c6;
  min-width: 0;
}

.actions button {
  min-height: 52px;
}

.action-summary {
  grid-column: 1 / -1;
  margin: 0;
  border-radius: 12px;
  padding: 9px 10px;
  color: #3b210d;
  background: #ffe8a9;
  font-weight: 900;
  text-align: center;
}

.phase-playing .actions .primary,
.phase-result .actions .primary {
  grid-column: 1 / -1;
}

.card-strip,
.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  max-width: 100%;
  min-width: 0;
}

.card-strip--scrollable {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-overflow-scrolling: touch;
  -webkit-user-select: none;
}

.card-strip--mini {
  gap: 6px;
}

.card-strip--hand {
  scrollbar-width: thin;
}

.cards.compact {
  min-height: 52px;
}

.card {
  --card-w: 56px;
  --card-h: 76px;
  --card-corner-size: 15px;
  --card-center-size: 31px;
  --card-joker-size: 12px;
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: stretch;
  justify-content: stretch;
  width: var(--card-w);
  min-width: var(--card-w);
  height: var(--card-h);
  min-height: var(--card-h);
  padding: 0;
  border: 2px solid #3c1b07;
  border-radius: 10px;
  color: #15100a;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.95), transparent 28%),
    linear-gradient(145deg, #fffdf2, #f4dfaa);
  box-shadow: 0 5px 0 #9c7a4b;
  font-weight: 900;
  line-height: 1;
  overflow: hidden;
  transition:
    background 120ms ease,
    box-shadow 120ms ease,
    transform 120ms ease;
}

.card--hand {
  --card-w: 62px;
  --card-h: 84px;
  --card-corner-size: 16px;
  --card-center-size: 34px;
  --card-joker-size: 13px;
}

.card--table {
  --card-w: 58px;
  --card-h: 78px;
}

.card--mini {
  --card-w: 42px;
  --card-h: 58px;
  --card-corner-size: 10px;
  --card-center-size: 20px;
  --card-joker-size: 9px;
  border-width: 1px;
  border-radius: 7px;
  box-shadow: 0 3px 0 #9c7a4b;
}

.card--interactive {
  cursor: pointer;
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-tap-highlight-color: rgba(17, 97, 73, 0.2);
  -webkit-user-select: none;
}

.card--interactive:focus-visible {
  outline: 4px solid #ffe06b;
  outline-offset: 3px;
}

.card.is-selected {
  transform: translateY(-16px);
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.95), transparent 28%),
    linear-gradient(145deg, #eefff4, #c8f6dc);
  box-shadow: 0 9px 0 #116149;
}

.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  padding: 0 14px;
  color: #fff7db;
  background: #3c1b07;
}

.hand h3 {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: space-between;
}

.hand {
  grid-area: hand;
  min-width: 0;
  max-width: 100%;
}

.hand .cards {
  padding: 24px 4px 12px;
}

.hand .card--hand {
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.alert {
  border-radius: 12px;
  padding: 10px;
  color: #fff7db;
  background: #9f321e;
}

.storage-alert {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 800;
}

.inline-alert {
  margin: 0 0 12px;
  font-weight: 800;
}

.chat p,
.events p {
  margin: 0;
  border-radius: 12px;
  padding: 8px 10px;
  background: #ffe8a9;
}

.feed-empty {
  color: #66411c;
  text-align: center;
}

.events .danger {
  color: #fff7db;
  background: #9f321e;
}

.events .success {
  color: #fff7db;
  background: #116149;
}

@media (max-width: 1360px) {
  .lobby {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  }

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

  .rooms {
    max-height: none;
  }
}

@media (max-width: 980px) {
  .table {
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "players"
      "center"
      "settlement"
      "hand"
      "actions";
  }

  .actions {
    align-content: stretch;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  }

  .app.has-session .hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .app.has-session .status {
    justify-content: flex-start;
    text-align: left;
  }

  .table-head {
    flex-direction: column;
  }

  .chips {
    justify-content: flex-start;
  }

  .players {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  }

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

  .room-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (orientation: landscape) and (min-width: 900px) and (max-height: 900px) {
  .app.route-table.has-session {
    padding: 10px 14px 14px;
  }

  .app.route-table.has-session .hero {
    margin-bottom: 8px;
    padding: 8px 12px;
    box-shadow: 0 8px 0 rgba(60, 27, 7, 0.28);
  }

  .app.route-table.has-session .route-bar {
    margin-bottom: 8px;
    padding: 6px;
    box-shadow: 0 7px 0 rgba(60, 27, 7, 0.24);
  }

  .app.route-table.has-session .route-actions button,
  .app.route-table.has-session .back-button {
    min-height: 44px;
  }

  .app.route-table.has-session .panel {
    padding: 12px;
    border-radius: 18px;
    box-shadow: 0 10px 0 rgba(60, 27, 7, 0.3);
  }

  .app.route-table.has-session .table {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.34fr);
    gap: 10px;
  }

  .app.route-table.has-session .table-head {
    padding: 10px 12px;
  }

  .app.route-table.has-session .table-head h2 {
    margin-bottom: 4px;
  }

  .app.route-table.has-session .players {
    gap: 8px;
  }

  .app.route-table.has-session .player {
    padding: 9px 10px;
  }

  .app.route-table.has-session .center,
  .app.route-table.has-session .hand,
  .app.route-table.has-session .actions {
    padding: 10px;
  }

  .app.route-table.has-session .actions {
    gap: 8px;
  }

  .app.route-table.has-session .actions button {
    min-height: 58px;
    font-weight: 900;
  }

  .app.route-table.has-session .hand h3 {
    margin-bottom: 4px;
  }

  .app.route-table.has-session .hand .cards {
    padding-top: 22px;
    padding-bottom: 8px;
  }

  .app.route-table.has-session .card--hand {
    --card-w: 58px;
    --card-h: 76px;
    --card-corner-size: 15px;
    --card-center-size: 31px;
    --card-joker-size: 12px;
  }
}

@media (max-width: 820px) {
  .lobby,
  .side {
    grid-template-columns: 1fr;
  }
}

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

  .hero,
  .table-head,
  .center {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .hero,
  .panel {
    border-radius: 18px;
    box-shadow: 0 10px 0 rgba(60, 27, 7, 0.32);
  }

  .hero {
    gap: 12px;
    margin-bottom: 14px;
    padding: 16px;
  }

  .app.has-room .hero {
    padding: 12px 14px;
  }

  .app.has-session .hero {
    grid-template-columns: 1fr;
  }

  .app.has-session .status {
    justify-content: flex-start;
    text-align: left;
  }

  .route-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .route-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  h1 {
    font-size: clamp(30px, 12vw, 46px);
  }

  .status {
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    text-align: left;
  }

  .players {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .player {
    padding: 10px 8px;
    font-size: 14px;
  }

  .row,
  .room-card {
    grid-template-columns: 1fr;
    flex-wrap: wrap;
  }

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

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

  .cards {
    gap: 6px;
  }

  .card {
    --card-w: 48px;
    --card-h: 66px;
    --card-corner-size: 13px;
    --card-center-size: 27px;
    --card-joker-size: 10px;
  }

  .card--hand {
    --card-w: 54px;
    --card-h: 74px;
    --card-corner-size: 14px;
    --card-center-size: 30px;
    --card-joker-size: 11px;
  }

  .card--mini {
    --card-w: 38px;
    --card-h: 54px;
    --card-corner-size: 10px;
    --card-center-size: 18px;
    --card-joker-size: 8px;
  }

  .row button {
    flex: 1 1 0;
  }
}

.card-suit-icon {
  display: block;
  fill: currentColor;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.card-face {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  color: #16100a;
}
.card-face--red,
.card-face--joker-red {
  color: #bc241d;
}
.card-face--black,
.card-face--joker-black {
  color: #17110a;
}
.card-face__corner {
  position: absolute;
  z-index: 1;
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 1px;
  min-width: calc(var(--card-corner-size) + 2px);
  line-height: 0.9;
  white-space: nowrap;
}
.card-face__corner--top {
  top: 5px;
  left: 5px;
}
.card-face__corner--bottom {
  right: 5px;
  bottom: 5px;
  transform: rotate(180deg);
}
.card-face__rank {
  font-size: var(--card-corner-size);
  font-weight: 1000;
  letter-spacing: -0.04em;
}
.card-face__corner-icon {
  width: calc(var(--card-corner-size) * 0.72);
  height: calc(var(--card-corner-size) * 0.72);
}
.card-face__center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.card-face__center-icon {
  width: var(--card-center-size);
  height: var(--card-center-size);
  filter: drop-shadow(0 1px 0 rgba(60, 27, 7, 0.18));
}
.card-face--joker-black .card-face__rank,
.card-face--joker-red .card-face__rank {
  font-size: var(--card-joker-size);
  letter-spacing: -0.08em;
  line-height: 0.92;
}
.card--mini .card-face__corner--top {
  top: 3px;
  left: 3px;
}
.card--mini .card-face__corner--bottom {
  right: 3px;
  bottom: 3px;
}
