.my-river {
  position: absolute;
  left: 28%;
  right: 28%;
  bottom: 178px;
  z-index: 2;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(3, 42, 34, 0.48);
  color: #b9d8cd;
  font-size: 10px;
  text-align: center;
}

.my-river > span {
  display: block;
  margin-bottom: 5px;
}

.my-river .river-row {
  justify-content: center;
}

.seat-left .meld-list,
.seat-right .meld-list,
.seat-left .river-row,
.seat-right .river-row {
  clear: both;
  position: relative;
  z-index: 2;
}

.seat-left .meld-list,
.seat-right .meld-list {
  padding-top: 7px;
}

.round-settlement-dialog {
  width: min(860px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid #cfe0d8;
  border-radius: 20px;
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(4, 35, 28, 0.34);
}

.round-settlement-dialog::backdrop {
  background: rgba(4, 28, 23, 0.68);
  backdrop-filter: blur(5px);
}

.settlement-dialog-head,
.settlement-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  background: #f5faf7;
}

.settlement-dialog-head {
  border-bottom: 1px solid var(--line);
}

.settlement-dialog-head h2 {
  margin: 3px 0 0;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #e4efe9;
  color: var(--green);
  font-size: 24px;
}

.settlement-dialog-body {
  padding: 20px 22px;
  overflow: auto;
}

.settlement-score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.settlement-score-card,
.round-review-step,
.settlement-result-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7faf8;
}

.settlement-score-card strong,
.settlement-score-card span {
  display: block;
}

.settlement-score-card strong {
  margin: 4px 0;
  font-size: 21px;
}

.settlement-positive { color: #147556; }
.settlement-negative { color: #b33b2e; }
.round-review-list { display: grid; gap: 9px; margin-top: 12px; }
.round-review-step h4 { margin: 0 0 6px; }
.round-review-step p,
.settlement-result-card p,
.settlement-empty-audit { margin: 5px 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.strategy-comparison { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.strategy-comparison span { padding: 4px 7px; border-radius: 999px; background: #e9f2ed; font-size: 10px; }
.strategy-comparison .is-user-choice { background: #fff0bd; color: #775000; }
.strategy-picker { display: grid; gap: 6px; margin: 10px 0; color: var(--muted); font-size: 11px; }
.strategy-picker select { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); font: inherit; }
.selected-strategy-card { border-color: #d2a83b; box-shadow: 0 0 0 2px rgba(210, 168, 59, 0.13); }
.auto-strategy-tag { background: #fff0bd !important; color: #775000; font-weight: 700; }
.settlement-dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line); }

@media (max-width: 1180px) {
  .my-river { left: 25%; right: 25%; bottom: 176px; }
}

@media (max-width: 760px) {
  .my-river { left: 18%; right: 18%; bottom: 174px; padding: 6px; }
  .settlement-score-grid { grid-template-columns: repeat(2, 1fr); }
  .settlement-dialog-head,
  .settlement-dialog-actions,
  .settlement-dialog-body { padding: 15px; }
}

/* Adaptive game shell and faster turn controls */
html { scroll-padding-top: 92px; }
body { min-width: 320px; }
button,
select,
.tile-chip { touch-action: manipulation; }

button:focus-visible,
select:focus-visible,
input:focus-visible,
.tile-chip:focus-visible {
  outline: 3px solid #f1bd3e;
  outline-offset: 2px;
}

kbd {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  margin-left: 4px;
  padding: 0 5px;
  place-items: center;
  border: 1px solid rgba(19, 67, 56, 0.18);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.68);
  color: inherit;
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.action-console {
  position: sticky;
  top: 92px;
  z-index: 12;
}

.quick-action-dock {
  display: grid;
  gap: 9px;
}

.active-strategy-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid #dbe8e1;
  border-radius: 10px;
  background: #f5faf7;
}

.active-strategy-summary span {
  color: var(--muted);
  font-size: 10px;
}

.active-strategy-summary strong {
  color: var(--green);
  font-size: 12px;
  text-align: right;
}

.active-strategy-summary.is-ready {
  border-color: rgba(210, 168, 59, 0.48);
  background: #fff9e8;
}

.tile-chip.recommended:not(.selected) {
  outline: 3px solid #f2bd3e;
  outline-offset: 2px;
  box-shadow: 0 3px 0 #d5a42f, 0 8px 13px rgba(0, 0, 0, 0.23);
}

.tile-chip.recommended::after {
  content: "荐";
  position: absolute;
  top: -10px;
  right: -7px;
  display: grid;
  width: 19px;
  height: 19px;
  place-items: center;
  border: 2px solid #fff8dc;
  border-radius: 50%;
  background: #d89e12;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  z-index: 2;
}

@media (min-width: 1181px) {
  .table-layout {
    grid-template-columns: minmax(680px, 1fr) clamp(280px, 20vw, 320px);
  }

  .mahjong-table {
    min-height: clamp(650px, calc(100vh - 184px), 760px);
  }

  .recommendation-grid {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  }
}

@media (max-width: 1180px) {
  .game-sidebar {
    grid-template-columns: minmax(260px, 0.9fr) repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .action-console { top: 86px; }
  .event-log-list,
  .decision-history { max-height: 245px; overflow: auto; }
}

@media (max-width: 900px) {
  .match-strip {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 14px;
  }

  .match-meta {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  .mahjong-table { min-height: 680px; }
  .seat-left,
  .seat-right { width: 165px; }
  .seat-left .river-row,
  .seat-right .river-row { max-width: 140px; }

  .game-sidebar {
    grid-template-columns: minmax(250px, 0.85fr) minmax(0, 1.15fr);
  }

  .decision-score { grid-column: 1 / -1; }
  .assistant-section { padding: 16px; }
}

@media (max-width: 760px) {
  html { scroll-padding-top: 76px; }
  .workspace {
    padding-bottom: calc(128px + env(safe-area-inset-bottom));
  }

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

  .brand-lockup { min-width: 0; }
  .brand-lockup h1 {
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mode-switch {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .mode-button { flex: 1; min-height: 38px; }
  .topbar-status { position: absolute; top: 12px; right: 12px; }

  .match-strip {
    position: relative;
    padding: 11px 12px;
    overflow: hidden;
  }

  .scoreboard {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .scoreboard::-webkit-scrollbar { display: none; }
  .score-item { flex: 1 0 68px; }
  .match-meta {
    gap: 6px;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
  }

  .match-meta > * { flex: none; }
  .mahjong-table {
    min-height: 610px;
    border-width: 5px;
  }

  .mahjong-table::before { inset: 6px; }
  .seat-top { top: 12px; left: 18%; right: 18%; }
  .seat-left,
  .seat-right { top: 25%; width: 116px; }
  .seat-left { left: 10px; }
  .seat-right { right: 10px; }

  .seat-left .concealed-row,
  .seat-right .concealed-row { display: none; }
  .seat-left .river-row,
  .seat-right .river-row { max-width: 104px; gap: 3px; }

  .seat .player-card { padding: 6px 7px; gap: 5px; }
  .seat .player-card .avatar { width: 27px; height: 27px; font-size: 11px; }
  .seat .player-card strong { font-size: 11px; }
  .seat .player-card small,
  .seat .player-card b { font-size: 9px; }

  .setup-panel {
    top: 100px;
    width: min(270px, calc(100% - 36px));
    z-index: 8;
  }

  .seat-bottom { bottom: 14px; }
  .my-hand-row {
    width: 100%;
    padding: 13px 8px 7px;
    gap: 5px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .my-hand-row .tile-chip { scroll-snap-align: center; }
  .my-river { left: 15%; right: 15%; bottom: 155px; max-height: 112px; overflow: auto; }

  .game-sidebar { display: grid; grid-template-columns: 1fr; }
  .action-console { position: static; }
  .decision-score { grid-column: auto; }

  .quick-action-dock {
    position: fixed;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    z-index: 65;
    grid-template-columns: minmax(112px, 0.82fr) minmax(160px, 1.18fr);
    gap: 7px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    background: rgba(7, 45, 37, 0.96);
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(16px);
  }

  .quick-action-dock:not(.is-gameplay-active) { display: none; }

  .quick-action-dock .active-strategy-summary {
    grid-column: 1 / -1;
    min-height: 30px;
    padding: 5px 8px;
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.1);
  }

  .quick-action-dock .active-strategy-summary span { color: #cce3d8; }
  .quick-action-dock .active-strategy-summary strong { color: #fff4c5; }
  .quick-action-dock .strategy-picker { margin: 0; gap: 3px; color: #cce3d8; }
  .quick-action-dock .strategy-picker select { min-height: 42px; padding: 7px 8px; }
  .quick-action-dock .accent-button { min-height: 42px; margin: 13px 0 0; }
  .control-hint { display: none; }

  .recommendation-grid { gap: 8px; }
  .assistant-section,
  .analysis-drawer,
  .lab-view { border-radius: 13px; }
  button,
  select { min-height: 42px; }
  .dialog-close { min-height: 36px; }
  kbd { display: none; }
}

@media (max-width: 480px) {
  .workspace { padding-right: 5px; padding-left: 5px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-lockup .eyebrow { display: none; }
  .brand-lockup h1 { margin: 0; max-width: 55vw; font-size: 14px; }
  .match-strip > div:first-child strong { display: block; }
  .match-meta { font-size: 10px; }

  .mahjong-table { min-height: 575px; border-radius: 18px; }
  .seat-top { left: 13%; right: 13%; }
  .seat-left,
  .seat-right { top: 24%; width: 101px; }
  .seat-left { left: 7px; }
  .seat-right { right: 7px; }
  .seat-left .river-row,
  .seat-right .river-row { max-width: 94px; }

  .center-mark { transform: translate(-50%, -50%) scale(0.82); }
  .setup-panel { top: 92px; }
  .my-river { left: 9%; right: 9%; bottom: 146px; }
  .my-hand-row .tile-chip { width: 34px; height: 46px; }
  .recommendation-grid { grid-template-columns: minmax(0, 1fr); }
  .control-grid { grid-template-columns: 1fr; }
}

@media (max-height: 650px) and (orientation: landscape) {
  .topbar { position: relative; }
  .mahjong-table { min-height: 540px; }
  .action-console { top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.research-status-button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #dff4eb;
  font-size: 11px;
  font-weight: 750;
}

.research-status-button[data-consent="accepted"] {
  border-color: rgba(244, 197, 92, 0.55);
  color: #ffe6a3;
}

.research-consent-dialog {
  width: min(560px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
}

.research-consent-dialog::backdrop {
  background: rgba(2, 25, 20, 0.76);
  backdrop-filter: blur(7px);
}

.research-consent-card { padding: clamp(22px, 5vw, 34px); }
.research-consent-card h2 { margin: 7px 0 10px; font-size: 24px; }
.research-consent-card p,
.research-consent-card li { color: var(--muted); font-size: 13px; line-height: 1.7; }
.research-consent-card ul { padding-left: 20px; }
.research-consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }

@media (max-width: 760px) {
  .research-status-button { max-width: 104px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .research-consent-actions { grid-template-columns: 1fr; }
}

/* Mobile table: keep every control and every tile inside the visual viewport. */
html,
body,
.app-shell {
  max-width: 100%;
  overflow-x: clip;
}

@media (max-width: 760px) {
  .workspace {
    width: 100%;
    padding-right: 6px;
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
    padding-left: 6px;
  }

  .topbar-status { gap: 4px; }
  .research-status-button {
    max-width: 82px;
    padding-right: 7px;
    padding-left: 7px;
  }
  .topbar .ghost-button {
    width: 38px;
    padding-right: 6px;
    padding-left: 6px;
  }

  .match-strip,
  .table-layout,
  .game-sidebar,
  .assistant-section,
  .analysis-drawer,
  .lab-view {
    min-width: 0;
    max-width: 100%;
  }

  .score-item {
    padding-right: 7px;
    padding-left: 7px;
    gap: 5px;
  }

  .mahjong-table {
    width: 100%;
    min-height: clamp(575px, 158vw, 640px);
  }

  .table-center {
    inset: 31% 24% 34%;
  }

  .center-mark,
  .center-mark:hover {
    width: 104px;
    height: 104px;
    transform: rotate(45deg) scale(0.78);
    transform-origin: center;
  }

  .seat-left,
  .seat-right {
    width: clamp(92px, 28vw, 116px);
  }

  .seat .player-card,
  .seat .player-card > div {
    min-width: 0;
  }

  .seat .player-card strong,
  .seat .player-card small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .seat-left .river-row,
  .seat-right .river-row {
    max-width: 100%;
  }

  .seat-left .river-row .tile-chip,
  .seat-right .river-row .tile-chip {
    width: 25px;
    height: 33px;
  }

  .seat-left .river-row .mahjong-icon,
  .seat-right .river-row .mahjong-icon {
    font-size: 17px;
  }

  .seat-bottom {
    right: 5px;
    left: 5px;
  }

  .seat-bottom .player-card {
    width: min(210px, 60%);
    margin-right: auto;
    margin-left: auto;
  }

  .seat-bottom .meld-list {
    max-width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: thin;
  }

  .my-hand-row {
    width: 100%;
    min-width: 0;
    padding-right: 1px;
    padding-left: 1px;
    overflow: visible;
    gap: 2px;
    justify-content: center;
  }

  .my-hand-row .tile-chip {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: 34px;
    height: 46px;
    padding-right: 0;
    padding-left: 0;
  }

  .my-hand-row .mahjong-icon {
    font-size: clamp(17px, 5.8vw, 23px);
  }

  .my-hand-row .tile-caption { font-size: 6px; }
  .my-river {
    right: 7%;
    left: 7%;
    max-width: none;
  }

  .action-panel {
    width: 100%;
    max-width: 100%;
    padding: 7px;
  }

  .action-buttons {
    flex-wrap: wrap;
  }

  .action-buttons .action-button {
    flex: 1 1 72px;
    min-width: 0;
  }

  .quick-action-dock {
    grid-template-columns: minmax(0, 1fr) minmax(132px, 1fr);
    padding: 6px;
    border-radius: 13px;
  }

  .quick-action-dock .active-strategy-summary { display: none; }
  .quick-action-dock .strategy-picker { min-width: 0; }
  .quick-action-dock .strategy-picker > span { display: none; }
  .quick-action-dock .strategy-picker select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }
  .quick-action-dock .accent-button {
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding-right: 7px;
    padding-left: 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .manual-tile-group {
    align-items: flex-start;
  }
  .manual-tile-group .tile-row {
    min-width: 0;
  }
  .table-wrap {
    width: 100%;
    max-width: 100%;
    overscroll-behavior-x: contain;
  }

  .round-settlement-dialog[open] {
    display: flex;
    flex-direction: column;
    width: calc(100vw - 12px);
    max-height: calc(100vh - 12px);
    max-height: calc(100dvh - 12px);
    margin: auto;
  }
  .round-settlement-dialog .settlement-dialog-body {
    min-height: 0;
    overscroll-behavior: contain;
  }
  .research-consent-dialog {
    max-height: calc(100vh - 12px);
    max-height: calc(100dvh - 12px);
    overflow-y: auto;
  }
}

@media (max-width: 380px) {
  .workspace { padding-right: 3px; padding-left: 3px; }
  .match-strip { padding-right: 8px; padding-left: 8px; }
  .seat-left { left: 4px; }
  .seat-right { right: 4px; }
  .seat-left,
  .seat-right { width: 92px; }
  .seat-top { right: 10%; left: 10%; }
  .center-mark,
  .center-mark:hover { transform: rotate(45deg) scale(0.68); }
  .my-river { right: 4%; left: 4%; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .settlement-score-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-height: 650px) and (orientation: landscape) and (max-width: 900px) {
  .workspace { padding-bottom: 68px; }
  .quick-action-dock {
    right: 6px;
    left: auto;
    width: min(390px, calc(100vw - 12px));
  }
}
