/* 手机横屏专用布局：让牌桌、手牌和操作区在有限高度内保持完整可用。 */

/* 手机竖屏时覆盖牌桌，提示用户旋转设备。横屏和桌面端保持隐藏。 */
.orientation-tip {
  display: none;
}

@media (orientation: portrait) and (max-width: 768px) {
  .orientation-tip {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at center, rgba(19, 93, 54, 0.98), rgba(3, 30, 16, 0.99));
    color: #fff;
    text-align: center;
  }

  .orientation-tip-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(86vw, 340px);
    padding: 28px 22px 30px;
    border: 1px solid rgba(255, 208, 80, 0.5);
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.28);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  }

  .orientation-tip-icon {
    font-size: 56px;
    line-height: 1;
    animation: orientationTipRotate 2.2s ease-in-out infinite;
  }

  .orientation-tip-arrow {
    margin-top: -3px;
    color: var(--gold);
    font-size: 34px;
    font-weight: 800;
    line-height: 1;
  }

  .orientation-tip h1 {
    margin: 4px 0 0;
    color: var(--gold);
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 1px;
  }

  .orientation-tip p {
    margin: 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 14px;
    line-height: 1.7;
  }
}

@keyframes orientationTipRotate {
  0%, 100% { transform: rotate(0deg); }
  45%, 70% { transform: rotate(90deg); }
}

@media (orientation: landscape) and (max-height: 600px) {
  :root {
    --mobile-landscape-topbar: 36px;
  }

  html,
  body,
  #app {
    min-width: 0;
    max-width: 100vw;
    overflow: hidden;
  }

  /* 顶部工具栏：压缩间距和文字，避免控制项横向跑出屏幕。 */
  .top-bar {
    height: var(--mobile-landscape-topbar);
    min-width: 0;
    gap: 5px;
    padding: 2px 8px;
    overflow: hidden;
  }

  .brand {
    flex: 0 0 auto;
    gap: 4px;
    font-size: 13px;
  }

  .brand-text {
    display: none;
  }

  .brand-text-mobile {
    display: inline-block;
    font-size: 13px;
  }

  .brand-icon {
    font-size: 16px;
  }

  .meta {
    flex: 0 1 auto;
    min-width: 0;
    gap: 5px;
  }

  .meta-item {
    min-width: 0;
    gap: 2px;
    font-size: 10px;
  }

  .meta-label {
    display: none;
  }

  .meta-val {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .meta-val.highlight {
    font-size: 11px;
  }

  .top-controls {
    flex: 0 1 auto;
    min-width: 0;
    gap: 3px;
    overflow: hidden;
  }

  .top-controls > * {
    min-width: 0;
  }

  .top-controls .btn {
    flex: 0 1 auto;
    padding: 3px 5px;
    border-radius: 4px;
    font-size: 10px;
  }

  /* 横屏顶部按钮改为图标形态，保留 title 作为悬浮说明。 */
  .top-controls > .btn {
    width: 28px;
    min-width: 28px;
    height: 26px;
    padding: 3px;
    font-size: 0;
    line-height: 1;
  }

  .top-controls > .btn::before {
    font-size: 13px;
  }

  #coachBtn::before { content: "🤖"; }
  #swapToggleBtn::before { content: "🔀"; }
  #soundBtn::before { content: "🔊"; }
  #navReplayBtn::before { content: "📜"; }
  #rulesBtn::before { content: "📖"; }
  #newGameBtn::before { content: "🔄"; }

  .top-controls .btn-icon {
    padding: 3px 5px;
    font-size: 12px;
  }

  .top-controls .select-group {
    flex: 0 0 auto;
    gap: 2px;
    font-size: 9px;
  }

  .top-controls .select-group label {
    display: none;
  }

  .top-controls .select-group select {
    width: 44px;
    padding: 2px 2px;
    font-size: 9px;
  }

  /* 牌桌：上家/下家占左右列，对家居中，自己在底部独占一行。 */
  .table {
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: calc(100vh - var(--mobile-landscape-topbar));
    height: calc(100dvh - var(--mobile-landscape-topbar) - env(safe-area-inset-bottom, 0px));
    grid-template-areas:
      ". top ."
      "left center right"
      "bottom bottom bottom";
    grid-template-columns: minmax(0, 1fr) minmax(120px, 1.4fr) minmax(0, 1fr);
    grid-template-rows: minmax(52px, .8fr) minmax(96px, 1.1fr) minmax(112px, 1.5fr);
    padding: 3px 6px 3px;
    gap: 3px;
    overflow: hidden;
  }

  .table > .seat,
  .seat-top,
  .seat-left,
  .seat-right,
  .seat-bottom,
  .center-area {
    min-width: 0;
  }

  .seat {
    width: 100%;
    overflow: hidden;
  }

  .seat-header {
    max-width: 100%;
    gap: 3px;
    padding: 2px 5px;
    margin-bottom: 2px;
    border-radius: 8px;
    font-size: 10px;
  }

  .seat-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .seat-wind {
    padding: 1px 4px;
    font-size: 9px;
  }

  .seat-tag,
  .seat-score {
    font-size: 9px;
  }

  .seat-top {
    align-items: center;
  }

  .seat-top .hand-closed {
    width: 100%;
    min-height: 0;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 1px;
    overflow: hidden;
  }

  .seat-left,
  .seat-right {
    align-items: stretch;
  }

  .seat-left .seat-header,
  .seat-right .seat-header {
    align-self: flex-start;
  }

  .seat-right .seat-header {
    align-self: flex-end;
  }

  .seat-left .hand-closed,
  .seat-right .hand-closed {
    width: 100%;
    min-height: 0;
    max-height: 68px;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 1px;
    overflow: hidden;
  }

  .seat-right .hand-closed {
    justify-content: flex-end;
  }

  .seat-left .melds,
  .seat-right .melds,
  .seat-top .melds {
    min-height: 0;
    max-height: 28px;
    margin-bottom: 1px;
    gap: 2px;
    overflow: hidden;
  }

  .seat-left .discards-container,
  .seat-right .discards-container,
  .seat-top .discards-container {
    width: 100%;
    max-width: 100%;
    min-height: 0;
  }

  .seat-left .discards,
  .seat-right .discards,
  .seat-top .discards {
    max-height: 54px;
    padding: 2px 3px;
    gap: 1px;
    overflow: hidden;
  }

  /* 对手牌面在左右窄列中自动换行，在顶部中列保持一行。 */
  .seat .tile.small {
    width: clamp(15px, 2.3vw, 22px);
    height: clamp(24px, 5.7vw, 34px);
    border-radius: 3px;
  }

  .seat .tile.small .t-char {
    font-size: clamp(12px, 2.8vw, 18px);
  }

  .seat .tile.small .t-sub {
    top: 1px;
    left: 1px;
    font-size: clamp(6px, 1.2vw, 8px);
  }

  .seat .tile.tiny {
    width: clamp(15px, 2.3vw, 22px);
    height: clamp(22px, 5.1vw, 30px);
    border-radius: 3px;
  }

  .seat .tile.tiny .t-char {
    font-size: clamp(11px, 2.5vw, 16px);
  }

  .seat .tile.tiny .t-sub {
    top: 1px;
    left: 1px;
    font-size: clamp(5px, 1vw, 7px);
  }

  /* 中央信息区保持紧凑，教练面板展开时限制在中心区域内。 */
  .center-area {
    gap: 3px;
    padding: 0 2px;
    overflow: visible;
  }

  .compass {
    width: 48px;
    height: 48px;
    border-width: 2px;
    border-radius: 10px;
  }

  .compass-dice {
    font-size: 14px;
  }

  .compass-label {
    font-size: 7px;
  }

  .compass-wind {
    font-size: 8px;
  }

  .compass-wind.active {
    font-size: 9px;
  }

  .live-log {
    width: 100%;
    max-width: 310px;
    min-height: 20px;
    padding: 2px 4px;
    border-radius: 5px;
    font-size: 9px;
  }

  .coach-panel {
    width: min(92vw, 310px);
    max-width: 100%;
    max-height: calc(100% - 4px);
  }

  .coach-panel:not(.collapsed) {
    width: min(92vw, 310px);
    max-width: calc(100% - 4px);
  }

  .coach-head {
    padding: 3px 6px;
  }

  .coach-head-title {
    font-size: 10px;
  }

  .coach-body {
    max-height: 70px;
    padding: 4px 6px 5px;
    gap: 3px;
    font-size: 9px;
  }

  .coach-reason,
  .coach-macro {
    padding: 3px 5px;
    font-size: 9px;
  }

  /* 自己的弃牌、定缺提示、操作栏和手牌。 */
  .seat-bottom {
    min-width: 0;
    width: 100%;
    padding-bottom: 0;
    overflow: visible;
  }

  .human-river-wrap {
    width: min(82%, 560px);
    max-width: 100%;
    min-height: 0;
    margin-bottom: 0;
  }

  .human-river-wrap .discards {
    max-height: 30px;
    padding: 1px 3px;
    gap: 1px;
    overflow: hidden;
    justify-content: center;
  }

  .ting-bar {
    max-width: 90%;
    max-height: 25px;
    margin-bottom: 1px;
    padding: 2px 6px;
    gap: 5px;
    overflow: hidden;
  }

  .ting-header {
    flex: 0 0 auto;
    font-size: 9px;
  }

  .ting-tiles {
    min-width: 0;
    overflow: hidden;
  }

  .human-controls-row {
    width: min(95%, 640px);
    max-width: 100%;
    min-width: 0;
    height: 26px;
    padding: 0 2px;
    margin-bottom: 0;
    overflow: hidden;
  }

  .human-controls-row .seat-header {
    flex: 0 0 auto;
    padding: 2px 6px;
    margin-bottom: 0;
    font-size: 10px;
  }

  .human-controls-row .melds {
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 2px;
    overflow: hidden;
  }

  .human-hand {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    height: clamp(44px, calc((100vw - 36px) / 15.2 * 1.45 + 7px), 70px);
    gap: clamp(1px, .35vw, 3px);
    padding: 3px 0 0;
  }

  .human-hand .tile {
    width: clamp(20px, calc((100vw - 36px) / 15.2), 44px);
    height: clamp(30px, calc((100vw - 36px) / 15.2 * 1.45), 64px);
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -2px 0 var(--tile-ivory-shadow);
  }

  .human-hand .tile .t-char {
    font-size: clamp(14px, calc((100vw - 36px) / 15.2 * .72), 31px);
  }

  .human-hand .tile .t-sub {
    top: 1px;
    left: 2px;
    font-size: clamp(6px, calc((100vw - 36px) / 15.2 * .22), 10px);
  }

  .human-hand .tile:hover {
    transform: translateY(-3px);
  }

  .human-hand .tile.selected {
    transform: translateY(-7px);
    outline-width: 2px;
  }

  .human-hand .tile.drawn {
    margin-left: clamp(2px, .6vw, 6px);
  }

  .human-hand .tile .coach-badge {
    top: -7px;
    padding: 0 3px;
    font-size: 7px;
  }

  .actions-panel {
    left: 50%;
    right: auto;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 12px);
    padding: 4px 7px;
    gap: 4px;
    overflow-x: auto;
    transform: translateX(-50%);
  }

  .act-btn {
    flex: 0 0 auto;
    padding: 4px 8px;
    border-radius: 16px;
    font-size: 11px;
  }

  .btn-hotkey {
    display: none;
  }

  /* 横屏弹窗：换三张、规则、结算等内容不再被上下裁掉。 */
  .modal {
    padding: 6px;
    overflow: hidden;
  }

  .modal-card {
    width: auto;
    min-width: 0;
    max-width: 96vw;
    max-height: calc(100vh - 12px);
    max-height: calc(100dvh - 12px);
    padding: 10px;
    overflow-y: auto;
    border-radius: 12px;
  }

  .modal-header h2 {
    font-size: 15px;
    margin-bottom: 3px;
  }

  .modal-desc {
    margin-bottom: 7px;
    font-size: 10px;
  }

  .modal-swap {
    width: min(96vw, 700px);
    padding: 9px 10px;
  }

  .swap-coach-box {
    padding: 5px 7px;
    margin-bottom: 6px;
  }

  .swap-coach-title {
    font-size: 10px;
  }

  .swap-coach-tag {
    font-size: 9px;
    padding: 1px 4px;
  }

  .swap-coach-tiles-row {
    flex-wrap: nowrap;
    gap: 5px;
  }

  .swap-coach-reason {
    font-size: 9px;
  }

  .swap-selection-section {
    padding: 5px;
    margin-bottom: 6px;
  }

  .swap-sec-title {
    margin-bottom: 4px;
    font-size: 10px;
  }

  .swap-hand-grid {
    gap: 3px;
    padding: 3px;
  }

  .swap-hand-grid .tile {
    width: clamp(24px, calc((100vw - 70px) / 14.5), 42px);
    height: clamp(36px, calc((100vw - 70px) / 14.5 * 1.45), 61px);
  }

  .swap-hand-grid .tile .t-char {
    font-size: clamp(18px, calc((100vw - 70px) / 14.5 * .72), 30px);
  }

  .swap-hand-grid .tile .t-sub {
    font-size: clamp(6px, calc((100vw - 70px) / 14.5 * .22), 9px);
  }

  .swap-footer {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .swap-status-hint {
    min-width: 0;
    flex: 1 1 auto;
    font-size: 9px;
  }

  .swap-footer .btn-large,
  .modal-card .btn-large {
    flex: 0 0 auto;
    width: auto;
    padding: 6px 10px;
    font-size: 11px;
  }

  .modal-swap-reveal {
    width: min(96vw, 540px);
  }

  .swap-reveal-content {
    gap: 6px;
    margin: 8px 0 10px;
  }

  .swap-reveal-box {
    padding: 6px 8px;
  }

  .modal-lack,
  .modal-result,
  .modal-rules {
    width: min(96vw, 620px);
  }

  .rules-content {
    max-height: calc(100dvh - 80px);
    font-size: 10px;
    line-height: 1.5;
  }

  /* 复盘页复用同一套三列牌桌，并压缩顶部和时间轴。 */
  .replay-top-bar {
    min-width: 0;
    height: var(--mobile-landscape-topbar);
    gap: 5px;
    padding: 2px 8px;
    overflow: hidden;
  }

  .replay-brand {
    min-width: 0;
    font-size: 11px;
  }

  .replay-score-card {
    flex: 0 1 auto;
    min-width: 0;
    padding: 2px 5px;
    gap: 3px;
  }

  .replay-acc-score {
    font-size: 17px;
  }

  .replay-acc-info,
  .replay-stats-pills {
    display: none;
  }

  .replay-top-actions {
    gap: 3px;
  }

  .replay-top-actions .btn {
    padding: 3px 5px;
    font-size: 9px;
  }

  .replay-table {
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) minmax(120px, 1.4fr) minmax(0, 1fr);
    grid-template-rows: minmax(42px, .75fr) minmax(82px, 1fr) minmax(96px, 1.25fr);
    padding: 3px 6px;
    gap: 3px;
  }

  .replay-table .seat {
    min-width: 0;
    overflow: hidden;
  }

  .replay-hud-card {
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    padding: 4px 6px;
    gap: 3px;
    overflow: hidden;
  }

  .replay-hud-step,
  .replay-hud-act-row {
    font-size: 9px;
  }

  .replay-hud-badge {
    padding: 1px 4px;
    font-size: 8px;
  }

  .replay-hud-reason {
    max-height: 28px;
    padding: 3px 4px;
    font-size: 8px;
    overflow: hidden;
  }

  .replay-hud-candidates {
    font-size: 8px;
  }

  .r-cand-list {
    max-height: 22px;
  }

  .replay-timeline-bar {
    gap: 3px;
    padding: 3px 8px 5px;
  }

  .replay-ctrl-row {
    min-width: 0;
    flex-wrap: nowrap;
    gap: 3px;
  }

  .replay-step-info {
    flex: 0 1 auto;
    min-width: 60px;
    font-size: 9px;
  }

  .replay-btn-group,
  .replay-extra-group {
    min-width: 0;
    gap: 3px;
  }

  .replay-btn-group .btn,
  .replay-extra-group .btn,
  .replay-extra-group .select-group select {
    padding: 3px 5px;
    font-size: 9px;
  }

  .replay-extra-group .select-group label {
    display: none;
  }
}
