:root {
  color-scheme: dark;
  --bg: #101411;
  --panel: #171d19;
  --panel-2: #202820;
  --felt: #126044;
  --felt-dark: #0b3f31;
  --tile: #fff8ea;
  --tile-edge: #d7c59b;
  --ink: #f3f7ee;
  --muted: #aab7a9;
  --gold: #f0bd5d;
  --red: #d94b49;
  --green: #4fc188;
  --blue: #5da7f0;
  --line: rgba(255, 255, 255, 0.12);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at center, #1a2b21 0, var(--bg) 58%);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #25312a;
  color: var(--ink);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: rgba(240, 189, 93, 0.6);
}

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

button.primary {
  border: 0;
  background: linear-gradient(135deg, #d94645, #e39a3d);
  color: white;
  font-weight: 700;
}

button.ghost {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

button.ghost:hover {
  background: rgba(217, 70, 69, 0.16);
  color: #ffd2cf;
  border-color: rgba(217, 70, 69, 0.6);
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #0f1512;
  color: var(--ink);
  outline: none;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.side-panel {
  border-right: 1px solid var(--line);
  background: rgba(15, 20, 17, 0.92);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d94645;
  color: white;
  font-size: 26px;
  font-weight: 900;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.brand p,
.hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.panel-block {
  display: grid;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.consent-banner {
  margin-top: 4px;
  padding: 10px 12px;
  background: rgba(255, 196, 0, 0.12);
  border: 1px solid rgba(255, 196, 0, 0.45);
  border-radius: 8px;
  font-size: 13px;
  color: #ffe7b0;
  display: grid;
  gap: 8px;
}
.consent-banner .consent-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.consent-banner .consent-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}
.consent-banner .consent-tag.ok {
  background: rgba(120, 220, 120, 0.18);
  color: #b5f1b5;
}
.consent-banner .consent-tag.need {
  background: rgba(255, 196, 0, 0.18);
  color: #ffd57a;
}
.consent-banner .consent-actions {
  display: flex;
  gap: 8px;
}
.consent-banner button {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 0;
  cursor: pointer;
}
.consent-banner button.approve {
  background: #2f9e44;
  color: #fff;
}
.consent-banner button.decline {
  background: #c92a2a;
  color: #fff;
}

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

.room-list-block {
  display: grid;
  gap: 10px;
}

.room-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.room-list-head h2 {
  font-size: 15px;
  color: var(--gold);
}

button.small {
  min-height: 30px;
  padding: 4px 12px;
  font-size: 13px;
}

.room-list {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow-y: auto;
}

.room-list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.room-list-row .meta {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.room-list-row .code {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 1px;
}

.room-list-row .sub {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-list-row .right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.tag.waiting {
  color: #8fe3a0;
  border-color: rgba(143, 227, 160, 0.5);
}

.tag.playing {
  color: #e3c08f;
  border-color: rgba(227, 192, 143, 0.5);
}

.room-list-empty,
.room-list .empty {
  font-size: 13px;
  color: var(--muted);
}

.room-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--muted);
}

.room-title strong {
  color: var(--gold);
  font-size: 28px;
  letter-spacing: 2px;
}

.seat-list,
#scoreList {
  display: grid;
  gap: 8px;
}

.seat,
.score-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.score-row strong {
  color: var(--gold);
}

.table-wrap {
  padding: 22px;
  min-width: 0;
}

.mahjong-table {
  position: relative;
  min-height: calc(100vh - 44px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 30%),
    radial-gradient(circle at center, var(--felt) 0, var(--felt-dark) 68%);
  box-shadow: inset 0 0 0 8px rgba(0, 0, 0, 0.18);
}

.center-board {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, 68%);
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(6, 22, 17, 0.78);
  backdrop-filter: blur(4px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.18);
}

.round-info,
.last-discard {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.last-discard strong {
  color: var(--gold);
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
}

.action-bar button {
  padding: 0 14px;
}

.action-status {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  color: var(--gold);
  font-weight: 700;
}

.confirm-action {
  min-width: 132px;
  padding: 0 18px;
  box-shadow: 0 8px 22px rgba(217, 70, 69, 0.24);
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #d8e2d5;
  font-size: 13px;
}

.log-list-side {
  max-height: 240px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.opponent {
  position: absolute;
  display: grid;
  gap: 8px;
  min-width: 210px;
  max-width: 360px;
}

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

.opponent.left {
  top: 36%;
  left: 18px;
}

.opponent.right {
  top: 36%;
  right: 18px;
}

.player-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: white;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.badge.turn {
  background: rgba(240, 189, 93, 0.18);
  color: var(--gold);
}

.badge.win {
  background: rgba(79, 193, 136, 0.2);
  color: #86e0b2;
}

.badge.ready {
  background: rgba(79, 193, 136, 0.22);
  color: #9df0c1;
}

.mini-hand,
.meld-row,
.discard-row,
.hand-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.back-tile {
  width: 28px;
  height: 42px;
  border-radius: 5px;
  background: url("/assets/majiang/pai.gif") center / contain no-repeat;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.tile {
  width: 45px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #1a1b18;
  font-weight: 900;
  line-height: 1;
  box-shadow: none;
  user-select: none;
  padding: 0;
  overflow: visible;
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.26));
}

.tile.small {
  width: 32px;
  height: 46px;
  border-radius: 5px;
  font-size: 13px;
}

.meld {
  display: inline-flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 0;
  padding: 2px 6px 4px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  margin-right: 4px;
  position: relative;
}

.meld > .tile.small {
  margin-left: -8px;
}

.meld > .tile.small:first-child {
  margin-left: 0;
}

.meld > .tile.small {
  width: 26px;
  height: 38px;
}

.meld.gang {
  border: 1px solid rgba(240, 189, 93, 0.45);
  background: rgba(240, 189, 93, 0.08);
  padding-right: 14px;
}

.meld.gang::after {
  content: '杠';
  position: absolute;
  right: -2px;
  top: -8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(0, 0, 0, 0.4);
  padding: 1px 4px;
  border-radius: 4px;
}

.tile.selected {
  transform: translateY(-12px);
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 8px;
}

.tile.disabled {
  opacity: 0.44;
}

.tile-fallback {
  display: none;
}

.self-area {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(6, 22, 17, 0.6);
  backdrop-filter: blur(4px);
}

.bottom-stack {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 22px;
  display: grid;
  gap: 10px;
}

.bottom-stack .action-bar {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(6, 22, 17, 0.7);
  backdrop-filter: blur(4px);
}

.self-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.self-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.self-tools button {
  padding: 0 14px;
}

.trustee-toggle {
  border: 1px solid rgba(240, 189, 93, 0.6);
  background: rgba(240, 189, 93, 0.12);
  color: #f0bd5d;
  font-weight: 600;
}

.trustee-toggle.active {
  border-color: rgba(120, 220, 150, 0.7);
  background: rgba(120, 220, 150, 0.16);
  color: #7fe0a0;
}

.hand-row.trustee .tile {
  filter: grayscale(0.5);
  opacity: 0.55;
  cursor: default;
}

.hand-row {
  min-height: 74px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 24px;
  top: 20px;
  z-index: 10;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #d94645;
  color: white;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

.round-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 10, 8, 0.6);
  backdrop-filter: blur(4px);
}

.round-modal-card {
  width: min(520px, calc(100vw - 40px));
  background: linear-gradient(160deg, #0d2620 0%, #13362c 100%);
  border: 1px solid rgba(240, 189, 93, 0.4);
  border-radius: 14px;
  padding: 22px 26px 24px;
  color: #f0eedb;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.round-modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  color: #f0bd5d;
  margin-bottom: 14px;
}

.round-modal-card .icon-close {
  width: 28px;
  height: 28px;
  line-height: 1;
  font-size: 22px;
  padding: 0;
}

.round-modal-body {
  display: grid;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}

.round-modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.round-modal-row .name {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.round-modal-row .name small {
  color: #9ab4a6;
  font-size: 11px;
  letter-spacing: 0.05em;
}

.round-modal-row .delta {
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.round-modal-row .delta.pos {
  color: #e8b85d;
}

.round-modal-row .delta.neg {
  color: #8da9bb;
}

.round-modal-row .delta.zero {
  color: #6f8479;
}

.round-modal-row.winner {
  border-color: rgba(240, 189, 93, 0.55);
  background: rgba(240, 189, 93, 0.08);
}

.round-modal-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.round-modal-card footer button {
  padding: 0 18px;
}

.round-modal-empty {
  text-align: center;
  color: #9ab4a6;
  padding: 16px 0;
}

.round-modal-cleanup {
  margin: 4px 0 0;
  font-size: 12px;
  color: #ffd57a;
  text-align: center;
  min-height: 16px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .table-wrap {
    padding: 10px;
  }

  .mahjong-table {
    min-height: 760px;
  }

  .center-board {
    top: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 24px);
  }

  .opponent.top {
    top: 12px;
  }

  .opponent.left,
  .opponent.right {
    top: 104px;
    max-width: calc(50% - 24px);
  }

  .tile {
    width: 36px;
    height: 52px;
    font-size: 14px;
  }
}

/* ===== 移动端横屏优化 ===== */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at center, #1a2b21 0, var(--bg) 60%);
  color: var(--ink);
}

.rotate-hint .rotate-icon {
  width: 56px;
  height: 94px;
  border: 4px solid var(--gold);
  border-radius: 12px;
  position: relative;
  animation: rotate-phone 1.8s ease-in-out infinite;
}

.rotate-hint .rotate-icon::after {
  content: "\21BB";
  position: absolute;
  right: -24px;
  bottom: -12px;
  font-size: 26px;
  color: var(--gold);
}

@keyframes rotate-phone {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

.rotate-hint .rotate-text {
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
}

.rotate-hint .dismiss {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  min-height: auto;
  padding: 0;
}

/* 竖屏小屏（手机）且处于牌局中时，提示横屏 */
@media (orientation: portrait) and (max-width: 820px) {
  body.in-game .rotate-hint {
    display: flex;
  }
}

/* 用户主动选择竖屏查看，或结算弹窗打开时，不再遮挡 */
body.rotate-dismissed .rotate-hint {
  display: none !important;
}

body.round-open .rotate-hint {
  display: none !important;
}

/* 横屏小屏：全屏牌桌，隐藏侧边栏，紧凑布局 */
@media (orientation: landscape) and (max-height: 560px) {
  body.in-game .app-shell {
    grid-template-columns: 1fr;
  }

  body.in-game .side-panel {
    display: none;
  }

  body.in-game .table-wrap {
    padding: 0;
    height: 100vh;
    overflow: hidden;
  }

  body.in-game .mahjong-table {
    min-height: 100vh;
    height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body.in-game .center-board {
    top: 36%;
    width: min(320px, 45%);
    padding: 6px 12px;
    gap: 4px;
  }

  body.in-game .round-info,
  body.in-game .last-discard {
    font-size: 12px;
    gap: 6px;
  }

  body.in-game .opponent {
    max-width: 30vw;
    gap: 4px;
  }

  body.in-game .opponent.top {
    top: 8px;
  }

  body.in-game .opponent.left,
  body.in-game .opponent.right {
    top: 38%;
  }

  body.in-game .player-name {
    font-size: 12px;
  }

  body.in-game .badge {
    font-size: 10px;
    min-height: 20px;
    padding: 1px 6px;
  }

  body.in-game .mini-hand {
    flex-wrap: nowrap;
    gap: 2px;
  }

  body.in-game .back-tile {
    width: 14px;
    height: 20px;
    border-radius: 2px;
  }

  body.in-game .tile.small {
    width: 20px;
    height: 28px;
    border-radius: 3px;
  }

  body.in-game .meld > .tile.small {
    width: 16px;
    height: 22px;
  }

  body.in-game .meld {
    padding: 1px 4px 2px;
    margin-right: 3px;
  }

  body.in-game .bottom-stack {
    left: 10px;
    right: 10px;
    bottom: 8px;
    gap: 6px;
  }

  /* 操作栏：紧凑居中，避免横跨遮挡左右两家的弃牌河 */
  body.in-game .bottom-stack .action-bar {
    justify-self: center;
    width: fit-content;
    max-width: min(320px, 45vw);
  }

  body.in-game .self-area {
    padding: 8px 10px;
    gap: 6px;
  }

  body.in-game .self-meta {
    gap: 8px;
  }

  body.in-game .self-tools {
    gap: 6px;
  }

  body.in-game .hand-row {
    min-height: 58px;
  }

  body.in-game .tile {
    width: 40px;
    height: 56px;
  }

  body.in-game .tile.small {
    font-size: 11px;
  }
}
