/* Shared phone layout. Keep the hand below the table in both orientations. */
.table-notices { display:none; }
@media (max-width:900px), (max-height:520px) and (orientation:landscape) {
  .viewport-game .topbar { padding:2px 6px; gap:4px; }
  .viewport-game .brand h1 { font-size:13px; letter-spacing:0; }
  .viewport-game .top-actions { gap:4px; }
  .viewport-game .top-actions .button, .viewport-game .pause-button {
    min-height:32px; padding:4px 7px; font-size:11px;
  }
  .viewport-game .online-solo { display:none; }
  .viewport-hud { gap:6px; padding-inline:6px; }
  .viewport-hud .level-chip, .viewport-hud #match-round { flex:none; white-space:nowrap; }
  .viewport-hud #match-levels { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .viewport-stage .controls button:disabled::after { content:''; }
  .viewport-stage .hand { touch-action:pan-x; scrollbar-width:auto; }
  .viewport-stage .hand .card { touch-action:none; }
  html body .viewport-stage .hand .card.selected { translate:none; }
  .viewport-stage .interpretations { min-width:0; }
  .viewport-stage .interpretations label { flex:none; }
  .viewport-stage .interpretations select { min-width:0; max-width:100%; flex:1; }
  /* A long public play scrolls within its owner's area, never into another seat. */
  .viewport-stage .seat-play-caption { flex-wrap:nowrap; max-width:100%; padding:1px 5px; gap:4px; margin:0 auto 2px; }
  html body .viewport-stage .seat-play-caption :is(.seat-play-name,.seat-play-badge) { font-size:11px; line-height:14px; }
  .viewport-stage .seat-play-name { min-width:0; max-width:6em; }
  .viewport-stage .seat-play-badge { flex:none; white-space:nowrap; }
  .viewport-stage .seat-play-cards, .viewport-stage .seat-play-cards.many {
    display:flex; flex-wrap:nowrap; gap:3px; width:max-content; max-width:100%;
    overflow-x:auto; overflow-y:hidden; margin-top:0; padding:1px 0;
    touch-action:pan-x; overscroll-behavior-x:contain; scrollbar-width:thin;
  }
  .table-menu:has(.menu-pages)[open] {
    max-height:calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px);
    width:min(720px,calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 16px)); padding:12px;
  }
  .table-menu .menu-page-content { max-height:none; flex:0 1 auto; padding:4px 8px 14px 2px; }
  .table-menu .menu-heading { margin:0; gap:8px; }
  .table-menu .menu-heading h2 { font-size:21px; margin:3px 0; }
  .table-menu .menu-heading p { margin:3px 0; font-size:11px; line-height:16px; }
  .table-menu #menu-resume { min-height:36px; margin-top:8px; padding:6px 12px; }
  .table-menu .menu-version { font-size:11px; margin-top:6px; }
  .audio-setting-actions { flex-wrap:wrap; }
  .audio-setting-row, .audio-setting-row label { max-width:100%; }
  .audio-setting-row input[type=range] { width:clamp(90px,28vw,140px); }
  .room-chat { right:max(8px,env(safe-area-inset-right)); max-height:calc(100dvh - env(safe-area-inset-bottom) - 56px); }
}

/* Transient information and exchange choices get real space in both orientations. */
@media (max-width:900px), (max-height:520px) and (orientation:landscape) {
  .viewport-stage { height:auto; min-height:100%; }
  .viewport-stage .table-notices {
    grid-column:1/-1; display:flex; flex-direction:column; gap:4px;
    min-width:0; padding:4px 8px 6px; pointer-events:none;
  }
  .viewport-stage .table-notices:not(:has(>:not([hidden]))) { display:none; }
  .viewport-stage .table-notices :is(#count-alert,.turn-reminder) {
    position:static; inset:auto; transform:none; flex:none;
    width:100%; min-width:0; max-width:100%; margin:0; padding:0;
    border:0; border-radius:0; background:transparent; box-shadow:none;
    color:var(--ink); font-size:11px; line-height:16px; font-weight:400;
    text-align:left; white-space:normal; overflow-wrap:anywhere;
    text-shadow:var(--notice-shadow,0 1px 3px #fffdf8);
  }
  html:is([data-environment="kanazawa"],[data-environment="amaharashi"],[data-environment="shiude"]) .table-notices {
    --notice-shadow:0 1px 3px #102033;
  }
  .viewport-stage .table-notices>#critical-status {
    position:static; inset:auto; width:100%; max-width:100%; min-width:0;
    margin:0; pointer-events:auto; overflow-wrap:anywhere;
  }
  .viewport-stage .table-notices #tail-recovery { display:flex; flex-wrap:wrap; gap:6px; }
  .viewport-stage:has(>#allocation-panel:not([hidden]))>#allocation-panel {
    position:static; inset:auto; width:auto; max-width:none; height:auto; max-height:none;
    display:grid; grid-template-columns:minmax(0,1fr) minmax(90px,.8fr); grid-template-rows:auto auto auto;
    gap:6px 8px; margin:0; padding:8px; overflow:visible;
    background:var(--surface); color:var(--ink); border-color:var(--ui-outline);
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) #allocation-title {
    grid-column:1/-1; grid-row:1; margin:0; font-size:12px; line-height:16px; overflow-wrap:anywhere;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) #allocation-choices {
    grid-column:1; grid-row:2; align-items:flex-start; flex-wrap:wrap; gap:6px; min-width:0;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) .allocation-choice {
    flex:1 1 46px; min-width:0; max-width:80px; height:auto; min-height:0; padding:2px; gap:4px;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) .allocation-choice>span {
    max-width:100%; font-size:10px; line-height:14px; white-space:normal; overflow-wrap:anywhere;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) .allocation-choice .card {
    width:38px!important; min-width:38px!important; height:58px!important; min-height:58px!important;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) #allocation-advice {
    grid-column:2; grid-row:2; align-self:start; margin:0; font-size:11px; line-height:16px;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden])) #allocation-confirm {
    grid-column:1/-1; grid-row:3; align-self:start; justify-self:stretch;
    width:100%; min-width:0; height:auto; min-height:34px; margin:0; padding:6px; font-size:11px;
  }
  .viewport-stage .table.exchange-active .trick-area,
  .viewport-stage:has(>#allocation-panel:not([hidden])) .table.exchange-active .trick-area {
    top:28px!important; bottom:8px!important; left:12px!important; right:12px!important;
    overflow:auto; overscroll-behavior:contain;
  }
  .viewport-stage .online-exchange-tile>span:first-child { min-width:0; overflow-wrap:anywhere; }
  .viewport-stage>#round-result {
    max-height:min(calc(100% - 32px),calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 72px));
  }
}

@media (max-width:900px) and (min-height:521px), (max-width:900px) and (orientation:portrait) {
  /* On very short screens the page may scroll; controls must never be clipped. */
  body.viewport-game { grid-template-rows:44px minmax(598px,1fr); overflow-y:auto; overflow-x:hidden; }
  .viewport-game>.layout { padding:0 4px 4px; }
  .viewport-stage { grid-template-rows:max-content auto minmax(330px,1.1fr) auto minmax(240px,1fr); }
  .viewport-hud { grid-row:1; }
  .viewport-stage>#allocation-panel { grid-column:1; grid-row:2; }
  .viewport-stage .table { grid-column:1; grid-row:3; }
  .viewport-stage .table-notices { grid-row:4; }
  .viewport-stage .hand-panel {
    grid-row:5;
    grid-template-rows:34px 36px minmax(50px,1fr) minmax(32px,auto) auto 42px 16px;
    gap:2px; padding:2px 5px 4px;
  }
  .viewport-stage .hand-header { height:34px; }
  .viewport-stage .my-seat .avatar { --seat-avatar-size:28px; }
  .viewport-stage .inline-hand-tools { gap:4px; }
  .viewport-stage .inline-hand-tools :is(.sort-button,.organize-button,.text-button) { min-height:32px; height:32px; min-width:28px; padding-inline:3px; font-size:11px; }
  .viewport-stage .inline-hand-tools>#reset-hand { padding-inline:3px; font-size:10px; }
  .viewport-stage .inline-hand-tools :is(#move-left,#move-right) { min-width:28px; padding-inline:4px; font-size:14px; }
  .viewport-stage .selection-row p { font-size:11px; }
  .viewport-stage .controls .button { min-height:40px; height:40px; padding-inline:10px; }
  .viewport-stage .table .seat { height:40px; --seat-card-height:40px; width:min(130px,calc(50% - 12px)); }
  .viewport-stage .seat-left, .viewport-stage .seat-right { top:116px; }
  .viewport-stage .seat-play-2 { top:44px; }
  .viewport-stage .seat-play-1, .viewport-stage .seat-play-3 { top:162px; }
  .viewport-stage .seat-play-0 { bottom:22px; }
  .start-shell { padding:20px max(14px,env(safe-area-inset-right)) max(20px,env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left)); }
  html body .online-lobby { padding:20px!important; margin-top:20px; }
  .online-lobby h2 { font-size:24px; }
  body:has(#welcome):not(.viewport-game) .topbar { flex-wrap:wrap; padding:16px; gap:12px; }
  body:has(#welcome):not(.viewport-game) .top-actions { flex-wrap:wrap; gap:6px; }
  .online-lobby input, .dialog input:not([type=range]):not([type=checkbox]) { font-size:16px; }
}

@media (max-height:520px) and (orientation:landscape) {
  /* A real header row reserves space for the controls and the score. */
  body.viewport-game { grid-template-rows:32px minmax(276px,1fr); overflow-y:auto; overflow-x:hidden; }
  body.viewport-game:has(.interpretations:not([hidden])) { grid-template-rows:32px minmax(304px,1fr); }
  body.viewport-game .topbar { position:static; height:32px; justify-content:flex-end; pointer-events:auto; }
  .viewport-game .top-actions .button, .viewport-game .pause-button { min-height:28px; height:28px; padding-block:2px; }
  .viewport-stage { grid-template-rows:136px auto minmax(140px,1fr); }
  .viewport-stage .table { grid-column:1; grid-row:1; }
  .viewport-stage .table-notices { grid-row:2; }
  .viewport-hud { top:-32px; left:6px; right:auto; max-width:calc(100% - 290px); justify-content:flex-start; }
  .viewport-stage .hand-panel {
    grid-column:1/-1; grid-row:3;
    grid-template-columns:minmax(0,1fr) auto;
    grid-template-rows:30px minmax(50px,1fr) auto 36px 14px;
    gap:2px 8px; padding:0 5px 2px;
  }
  .viewport-stage .hand-header { top:2px; }
  .viewport-stage .inline-hand-tools { grid-column:1/-1; grid-row:1; margin-left:70px; }
  .viewport-stage .inline-hand-tools :is(.sort-button,.organize-button,.text-button) { min-height:28px; height:28px; }
  .viewport-stage .hand { grid-column:1/-1; grid-row:2; }
  .viewport-stage .interpretations { grid-column:1/-1; grid-row:3; }
  .viewport-stage .selection-row {
    position:static; inset:auto; grid-column:1; grid-row:4;
    width:100%; height:36px; min-height:0; gap:5px; margin:0;
  }
  .viewport-stage .selection-row p { font-size:10px; line-height:15px; }
  .viewport-stage .selection-row .text-button { min-height:30px; padding:3px 6px; font-size:10px; }
  .viewport-stage .controls { grid-column:2; grid-row:4; gap:6px; }
  .viewport-stage .controls .button { min-height:34px; height:34px; padding:3px 9px; min-width:48px; font-size:11px; }
  .viewport-stage .controls .primary { min-width:72px; }
  .viewport-stage .online-exchange { grid-column:2; grid-row:4; }
  .viewport-stage .feedback { position:static; inset:auto; grid-column:1/-1; grid-row:5; line-height:14px; }
  .viewport-stage .table .seat .seat-count, .viewport-stage .table .seat .seat-count b { font-size:10px!important; line-height:13px; }
  .viewport-stage .seat-play-cards .card { height:36px; min-height:36px; }
  .viewport-stage .seat-play-cards .card .wild-tag { top:25px; }
  .viewport-stage .seat-play-caption { margin-bottom:0; }
  .table-menu:has(.menu-pages)[open] { padding:8px 12px; }
  .table-menu .menu-heading .eyebrow { display:none; }
  .table-menu .menu-heading h2 { font-size:18px; margin:0; }
  .table-menu .menu-pages { margin:6px 0; }
  .table-menu .menu-pages button { padding:6px 2px; }
  .table-menu .menu-version { display:none; }
  .start-shell { padding:20px max(20px,env(safe-area-inset-right)) 20px max(20px,env(safe-area-inset-left)); }
  html .start-shell .start-hero { min-height:280px; padding:30px 24px 24px; }
}

@media (max-height:360px) and (orientation:landscape) {
  body.viewport-game { grid-template-rows:32px minmax(266px,1fr); }
  body.viewport-game:has(.interpretations:not([hidden])) { grid-template-rows:32px minmax(294px,1fr); }
  .viewport-stage { grid-template-rows:126px auto minmax(140px,1fr); }
  .viewport-stage .seat-play-cards .card { height:30px; min-height:30px; }
  .viewport-stage .seat-play-cards .card .wild-tag { top:20px; }
}

@media (max-height:520px) and (orientation:landscape) {
  .viewport-stage:has(>#allocation-panel:not([hidden])) {
    grid-template-columns:minmax(0,1fr) minmax(0,1fr);
    grid-template-rows:minmax(164px,auto) auto minmax(140px,1fr); column-gap:8px;
  }
  .viewport-stage:has(>#allocation-panel:not([hidden]))>#allocation-panel { grid-column:1; grid-row:1; }
  .viewport-stage:has(>#allocation-panel:not([hidden])) .table { grid-column:2; grid-row:1; }
}

/* The level indicator uses the same outline skin as the table menu in every scene. */
.viewport-game :is(#menu-toggle, .level-chip) {
  border-radius:999px;
  font-size:12px;
  font-weight:600;
}
.viewport-stage .viewport-hud {
  height:auto;
  padding-top:6px;
}
.viewport-hud .level-chip {
  display:inline-flex;
  flex:none;
  align-items:center;
  gap:4px;
  min-height:0;
  padding:4px 10px;
  line-height:1.25;
  white-space:nowrap;
  text-shadow:none;
  cursor:default;
  pointer-events:none;
}
.level-chip #level-value { font-size:15px; font-weight:700; color:inherit; }
.level-chip #wild-label {
  padding-inline-start:7px;
  margin-inline-start:3px;
  border-inline-start:1px solid;
  border-color:inherit;
}
.viewport-stage .controls #play:disabled::after { content:' · 暂不可用'; }
.viewport-stage .controls #play[data-selection]:disabled::after { content:none; }
.viewport-stage .controls .helper-controls { flex:none; }
.viewport-stage .controls #play { width:auto; white-space:normal; line-height:1.25; }
.viewport-stage .selection-row .text-button { margin-inline-start:auto; }
@media (max-width:900px) and (orientation:portrait) {
  .viewport-stage .hand-panel {
    grid-template-rows:34px 36px minmax(50px,1fr) minmax(32px,auto) auto minmax(42px,auto) 16px;
  }
  .viewport-stage .controls #play { height:auto; }
}
