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

:root {
  --bg-main: #0f1a14;
  --bg-panel: #16241c;
  --bg-box: #1d3025;
  --felt: #1f4a32;
  --line: #2f5a43;
  --gold: #f0c040;
  --text: #eef3ee;
  --muted: #9db3a5;
  --primary: #3b8f5f;
  --primary-hover: #47a76f;
  --danger: #f85149;
  --win: #5fd38d;
  --radius: 10px;
  --cw: min(12.6vw, 58px);
}

body {
  min-height: 100vh;
  padding-top: 44px;
  background: var(--bg-main);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* TEND page shell */
.tend-game-nav {
  position: fixed;
  inset: 0 0 auto;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 16px;
  background: rgba(15, 26, 20, 0.96);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.tend-game-nav a {
  color: var(--text);
  text-decoration: none;
}

.tend-game-nav a:first-child {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.nav-room {
  margin-left: auto;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.1em;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 12px 40px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 16px;
}

.title {
  font-size: 1.8rem;
  color: var(--gold);
}

.title small {
  font-size: 1rem;
  color: var(--muted);
  margin-left: 6px;
}

.lead {
  color: var(--muted);
  margin: 4px 0 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input,
.field select {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-main);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.suits {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  border: 0;
}

.suits legend {
  width: 100%;
  margin-bottom: 4px;
}

.suit-opt {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-main);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.suit-opt.red {
  color: #ff6b6b;
}

.room-rules {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-box);
  color: var(--gold);
  font-size: 0.9rem;
}

.hand.leftover .card {
  opacity: 0.35;
  cursor: default;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.box {
  background: var(--bg-box);
  border-radius: var(--radius);
  padding: 14px;
}

.box h2,
.sub {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.sub {
  margin-top: 18px;
}

.btn {
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-box);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  width: 100%;
}

.btn:hover:not(:disabled) {
  border-color: var(--gold);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 700;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.gold {
  background: var(--gold);
  border-color: var(--gold);
  color: #2a1f00;
  font-weight: 700;
}

.btn.small {
  width: auto;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.row-btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.msg {
  min-height: 1.5em;
  margin-top: 10px;
  color: var(--gold);
  font-size: 0.9rem;
}

.hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.rules {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.88rem;
}

.rules summary {
  cursor: pointer;
  color: var(--text);
}

.rules ul {
  margin: 8px 0 0 1.2em;
}

/* 等候室 */
.room-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.label {
  color: var(--muted);
  font-size: 0.85rem;
}

.room-code {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.qr {
  background: #fff;
  padding: 6px;
  border-radius: 6px;
  line-height: 0;
}

.player-list {
  list-style: none;
}

.player-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

/* 牌桌 */
.table-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 8px;
}

.timer {
  min-width: 3em;
  text-align: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-box);
}

.timer.urgent {
  background: var(--danger);
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-box);
  color: var(--muted);
}

.chip.done {
  color: var(--win);
}

.chip.off {
  opacity: 0.5;
}

.rows {
  background: var(--felt);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  cursor: pointer;
}

.rows.locked .row {
  cursor: default;
  border-style: solid;
}

.row-label {
  width: 3.4em;
  flex: none;
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
}

.row-label em {
  font-style: normal;
  color: var(--gold);
  font-size: 0.75rem;
  min-height: 1.2em;
}

.slots {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

.warn {
  margin-top: 8px;
  color: var(--danger);
  font-weight: 700;
  text-align: center;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 12px;
  min-height: calc(var(--cw) * 1.4);
}

.card {
  position: relative;
  width: var(--cw);
  height: calc(var(--cw) * 1.4);
  flex: none;
  border-radius: 6px;
  border: 1px solid #c9c9c9;
  background: #fdfdfb;
  color: #1a1a1a;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card.red {
  color: #c62828;
}

.card .rank {
  font-size: calc(var(--cw) * 0.42);
  font-weight: 800;
}

.card .suit {
  font-size: calc(var(--cw) * 0.4);
}

.card.selected {
  transform: translateY(-10px);
  box-shadow: 0 0 0 3px var(--gold);
}

.card.empty {
  background: rgba(255, 255, 255, 0.06);
  border: 1px dashed rgba(255, 255, 255, 0.25);
  cursor: inherit;
}

.action-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.action-bar .btn.gold,
.action-bar .btn.primary {
  grid-column: span 2;
}

/* 結果 */
.results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.result.mine {
  border-color: var(--gold);
}

.result header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.pts {
  font-size: 1.2rem;
  font-weight: 800;
}

.pts.win {
  color: var(--win);
}

.pts.lose {
  color: var(--danger);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.badge {
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-box);
  color: var(--muted);
}

.badge.gold {
  background: var(--gold);
  color: #2a1f00;
}

.badge.hot {
  background: #e67e22;
  color: #fff;
}

.badge.bad {
  background: var(--danger);
  color: #fff;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
}

.result-label {
  width: 6.5em;
  flex: none;
  font-size: 0.78rem;
  color: var(--muted);
}

.mini-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.card.mini {
  --cw: min(8.4vw, 36px);
  cursor: default;
}

.vs {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.scoreboard {
  margin-left: 1.4em;
}

.scoreboard li {
  padding: 3px 0;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay-box {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.overlay-box p {
  margin-bottom: 14px;
}

[hidden] {
  display: none !important;
}
