/* The game owns the viewport; management is opened in panels, never below it. */
html:has(body.in-game),
body.in-game {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body.in-game #app {
  height: 100%;
  overflow: hidden;
}
#play-screen.play-screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  margin: 0;
  background: #142c38;
}
#play-screen .play-header {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  height: 52px;
  max-width: none;
  padding: 6px max(8px, env(safe-area-inset-right)) 4px
    max(8px, env(safe-area-inset-left));
  background: transparent;
  z-index: 30;
  pointer-events: none;
}
#play-screen .game-heading,
#play-screen .game-level,
#play-screen #fullscreen,
#play-screen #play-sound,
#play-screen #help {
  display: none !important;
}
#play-screen .game-back,
#play-screen #pause {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border: 1px solid #c4e5ed66;
  border-radius: 12px;
  background: #173a46e8;
  color: #eef7eb;
  box-shadow: 0 2px 8px #08253133;
}
#play-screen .play-tools {
  margin-left: auto;
}
#play-screen .play-body {
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
}
#play-screen .game-frame {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}
#play-screen .game-footer,
#play-screen .portrait-guide {
  display: none !important;
}
#play-screen .canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#play-screen .game-hud {
  position: absolute;
  top: 5px;
  left: 59px;
  right: 59px;
  z-index: 12;
  height: 42px;
  min-height: 0;
  padding: 4px 8px;
  gap: 8px;
  border-radius: 10px;
  background: #143041c9;
  pointer-events: none;
}
#play-screen .game-hud #detail {
  display: none;
}
#play-screen .game-hud > div:first-child {
  min-width: 0;
}
#play-screen .game-hud #goal {
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#play-screen .hud-stats {
  gap: 9px;
  flex-shrink: 0;
}
#play-screen .hud-stats b,
#play-screen .score-count {
  font-size: 12px;
}
#play-screen.table-mode .game-hud {
  display: none;
}
#play-screen .touch-controls {
  z-index: 15;
}
#play-screen .launch-ball {
  min-width: 96px;
  min-height: 44px;
  bottom: max(18px, env(safe-area-inset-bottom));
}
#play-screen .joystick {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 112px;
  height: 112px;
}
#play-screen .direction-controls {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
}
#play-screen .touch-buttons {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
}
.pause-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}
.pause-tools button {
  flex: 1;
}
.experience-screen {
  position: fixed;
  inset: 0;
  height: 100dvh;
  width: 100%;
  background: #edf2e5;
  z-index: 40;
}
.experience-screen iframe {
  border: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#play-screen.table-mode .table-surface {
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding-top: calc(48px + env(safe-area-inset-top, 0px));
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
}
#play-screen .table-layout {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0 8px;
  gap: 0;
  overflow: hidden;
}
#play-screen .chess-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 58px;
}
.chess-layout .board-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 28px;
  min-height: 0;
}
.chess-layout .board-turn {
  justify-content: center;
  margin: 0;
  padding: 4px 6px;
  font-size: 14px;
}
.chess-layout .board-turn > span:last-child {
  margin-left: 7px;
  font-size: 12px;
}
.chess-playfield {
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  container-type: size;
}
#play-screen .chess-board {
  width: min(100cqw, 100cqh);
  max-height: 100%;
  margin: 0;
  border-width: 7px;
}
#play-screen .xiangqi-board {
  width: min(100cqw, calc(100cqh * 0.9));
}
.chess-layout .table-message {
  margin: 0;
  text-align: center;
  line-height: 1.4;
  align-self: center;
  font-size: 12px;
}
#play-screen .chess-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 0;
  padding: 5px;
}
.chess-actions .table-toolbar {
  margin: 0;
  width: min(320px, 70%);
}
.chess-actions .board-note {
  font-size: 11px;
}
#play-screen .city-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 60px;
  position: relative;
}
.city-layout .board-main {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 36px minmax(0, 1fr) auto;
  gap: 4px;
}
.city-status {
  min-width: 0;
}
.city-status .board-turn {
  justify-content: center;
  height: 25px;
  margin: 0;
  gap: 6px;
  font-size: 13px;
}
.city-status .board-turn > span:last-child {
  font-size: 12px;
  margin-left: 8px;
}
.city-status .wallet-strip {
  margin: 0;
  height: 34px;
  padding: 4px 10px;
  border: 0;
  background: transparent;
  justify-content: center;
  gap: 24px;
}
.city-status .wallet-strip span {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 10px;
}
.city-status .wallet-strip b {
  display: inline;
  font-size: 14px;
  margin: 0;
}
#play-screen .city-map-scroll {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  container-type: size;
  border-radius: 8px;
}
#play-screen .city-board {
  width: 100cqw;
  height: 100cqh;
  aspect-ratio: auto;
  max-width: none;
  min-width: 0;
  flex-shrink: 0;
  margin: 0;
  border-width: 4px;
}
#play-screen .city-center {
  padding: 10px;
  min-width: 0;
  overflow: hidden;
  gap: 8px;
}
#play-screen .city-center h2,
#play-screen .city-center > .eyebrow {
  display: none;
}
#play-screen .city-center .dice-stage {
  width: auto;
  height: auto;
  margin: 0;
}
#play-screen .city-center p {
  max-width: 90%;
  max-height: 85px;
  margin: 2px 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  overflow: hidden;
}
#play-screen .city-center .die-face {
  width: 58px;
  height: 58px;
  padding: 9px;
  gap: 3px;
}
#play-screen .city-center .die-pip {
  width: 9px;
  height: 9px;
}
#play-screen .city-center .dice-caption {
  font-size: 12px;
}
.map-colors {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  max-width: 95%;
}
.map-colors button {
  padding: 2px;
  border: 0;
  background: #173c3ac9;
  border-radius: 6px;
  color: #fff3d5;
  min-height: 40px;
  min-width: 32px;
  font-size: 9px;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 3px;
}
.map-colors i {
  display: grid;
  place-items: center;
  width: 22px;
  height: 18px;
  border-radius: 4px;
  font-style: normal;
  background: var(--district);
  color: #153f3a;
  font-size: 10px;
  font-weight: 800;
}
.city-turn-action {
  min-height: 64px;
  max-height: min(32dvh, 230px);
  padding: 5px 2px;
  min-width: 0;
}
.turn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  min-height: 54px;
}
.table-surface .city-turn-action .roll-button {
  min-height: 48px;
  width: min(48%, 250px);
  background: #ffce77;
  color: #274847;
  font-size: 16px;
  box-shadow: 0 3px 0 #886437;
  border: 1px solid #ffe2a4;
}
.city-turn-action .waiting {
  font-size: 13px;
  color: #cee5d0;
  padding: 12px 6px;
}
.city-turn-action .vehicle-controls {
  margin: 0;
  gap: 4px;
  font-size: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.table-surface .city-turn-action .vehicle-controls button {
  min-height: 40px;
  min-width: 37px;
  padding: 5px;
}
.city-turn-action .decision-card {
  margin: 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-height: min(32dvh, 230px);
  overflow: auto;
  border: 1px solid #d4e6b3;
  background: #f5ecd5;
  color: #36533f;
  box-shadow: 0 4px 16px #05283135;
  animation: none;
}
.city-turn-action .decision-image {
  width: 45px;
  height: 55px;
  flex-shrink: 0;
}
.city-turn-action .decision-card h3 {
  font-size: 14px;
  margin: 0 0 4px;
}
.city-turn-action .decision-card p {
  font-size: 11px;
  line-height: 1.4;
  margin: 4px 0 7px;
}
.city-turn-action .district-offer {
  display: none;
}
.city-turn-action .district-badge {
  margin: 0;
  padding: 2px 5px;
  font-size: 10px;
}
.city-turn-action .district-badge i {
  width: 16px;
  height: 16px;
  font-size: 9px;
}
.city-turn-action .decision-card button {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 12px;
  margin: 2px 5px 2px 0;
}
.city-turn-action .shop-card {
  display: block;
}
.city-turn-action .market-cards {
  display: flex;
  gap: 6px;
  margin: 4px 0;
}
.city-turn-action .market-cards button {
  flex: 1;
  min-width: 0;
  padding: 3px;
}
.city-turn-action .market-cards img {
  width: 28px;
  height: 28px;
}
.city-turn-action .market-cards small {
  font-size: 10px;
}
.city-dock {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 4px;
  padding: 5px 0;
  background: #163941;
  border-top: 1px solid #d1e8d32b;
  z-index: 22;
}
.city-dock > button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #23494e;
  color: #e7efce;
  font-size: 11px;
  cursor: pointer;
  touch-action: manipulation;
}
.city-dock img {
  width: 24px;
  height: 25px;
  object-fit: contain;
}
.city-dock > button[aria-pressed="true"] {
  background: #425f51;
  border-color: #edce83;
  color: #ffe7a1;
}
.table-surface .city-dock .map-zoom {
  margin: 0;
  padding: 4px;
  min-height: 46px;
  font-size: 11px;
}
#play-screen .city-map-scroll.zoomed {
  display: block;
  overflow: auto;
  height: 100%;
}
#play-screen .city-map-scroll.zoomed .city-board {
  width: 180cqw;
  height: 180cqh;
  min-width: 180cqw;
  margin: 0;
}
#play-screen .city-map-scroll.zoomed .city-tile strong {
  font-size: 12px;
}
#play-screen .city-map-scroll.zoomed .city-tile small {
  display: block;
  font-size: 10px;
}
#play-screen .city-map-scroll.zoomed .district {
  height: 16px;
  line-height: 16px;
  font-size: 11px;
}
.city-sheet-backdrop {
  position: absolute;
  inset: 0 0 60px;
  z-index: 23;
  background: #0a263aa3;
  border: 0;
  cursor: pointer;
}
#play-screen .city-sidebar.city-sheet {
  position: absolute;
  bottom: 64px;
  right: 8px;
  width: min(520px, calc(100% - 16px));
  max-height: calc(100% - 78px);
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  background: #f5f1df;
  border: 1px solid #d3dfc5;
  border-radius: 17px;
  box-shadow: 0 12px 38px #05222a80;
  color: #36563e;
  z-index: 24;
  overflow: hidden;
}
.city-sheet-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #e7edda;
  flex-shrink: 0;
}
.city-sheet-heading h3 {
  font-size: 16px;
  margin: 0;
}
.city-sheet-close {
  width: 44px;
  height: 42px;
  border: 1px solid #c5d4b4;
  border-radius: 10px;
  background: #fbfbee;
  color: #365443;
  font-size: 20px;
  cursor: pointer;
}
.city-sheet-content {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 10px;
}
.city-sheet .city-management {
  border: 0;
  border-radius: 0;
}
.city-sheet .city-management > summary {
  display: none;
}
.city-sheet .roster-row {
  background: #e4ecda;
  color: #3e5d42;
}
.city-sheet .roster-row small,
.city-sheet .roster-row > b {
  color: #5b7152;
}
.city-sheet .roster-row.active {
  border-color: #78955a;
}
.city-sheet .district-panel {
  margin: 0;
}
.city-sheet .district-legend {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.city-sheet .hand-cards {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.city-sheet .hand-cards small {
  display: block;
  font-size: 10px;
}
.city-sheet .hand-cards img {
  width: 60px;
  height: 58px;
}
.city-sheet .hand-cards strong {
  font-size: 12px;
}
.city-sheet .stock-row {
  gap: 6px;
}
.city-sheet .table-toolbar {
  flex-wrap: wrap;
}
.city-sheet .table-toolbar button {
  min-width: 100px;
}
@media (orientation: landscape) {
  .city-layout .board-main {
    grid-template-columns: minmax(0, 1fr) minmax(235px, 28%);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
  }
  .city-status {
    grid-column: 2;
    grid-row: 1;
  }
  .city-status .board-turn {
    height: 32px;
  }
  .city-status .wallet-strip {
    height: auto;
    padding: 8px;
    flex-direction: column;
    gap: 6px;
    background: #24494b;
    border-radius: 10px;
  }
  .city-status .wallet-strip span {
    justify-content: space-between;
    font-size: 12px;
  }
  .city-status .wallet-strip b {
    font-size: 17px;
  }
  .city-layout .city-map-scroll {
    grid-column: 1;
    grid-row: 1/3;
  }
  .city-turn-action {
    grid-column: 2;
    grid-row: 2;
    align-self: end;
    max-height: 100%;
  }
  .turn-primary {
    flex-direction: column;
    gap: 14px;
  }
  .table-surface .city-turn-action .roll-button {
    width: 100%;
  }
  .city-turn-action .decision-card {
    display: block;
    max-height: 100%;
    padding: 13px;
  }
  .city-turn-action .decision-image {
    float: right;
    margin-left: 8px;
  }
  .city-turn-action .decision-card > div > div {
    display: flex;
    flex-wrap: wrap;
  }
  .city-turn-action .decision-card button {
    flex: 1;
  }
  .city-turn-action .decision-card p {
    font-size: 12px;
    margin: 9px 0;
  }
  .city-dock {
    max-width: 740px;
    width: 100%;
    justify-self: center;
  }
}
@media (max-width: 550px) {
  #play-screen .game-hud {
    left: 57px;
    right: 57px;
  }
  #play-screen .game-hud > div:first-child {
    display: none;
  }
  #play-screen .hud-stats {
    width: 100%;
    justify-content: space-between;
    gap: 7px;
  }
  #play-screen .score-count {
    font-size: 11px;
  }
  #play-screen .city-center {
    padding: 7px;
    gap: 5px;
  }
  #play-screen .city-center .die-face {
    width: 43px;
    height: 43px;
    padding: 7px;
    gap: 2px;
  }
  #play-screen .city-center .die-pip {
    width: 6px;
    height: 6px;
  }
  #play-screen .city-center p {
    font-size: 11px;
    margin: 0;
    padding: 7px;
    max-width: 98%;
  }
  #play-screen .city-center .dice-caption {
    font-size: 10px;
  }
  #play-screen .city-tile strong {
    font-size: 7px;
  }
  .map-colors {
    gap: 3px;
    width: 100%;
  }
  .map-colors button {
    min-width: 28px;
  }
  .city-sheet .district-key strong {
    font-size: 12px;
  }
  #play-screen .chess-piece {
    font-size: clamp(19px, 5.8vw, 28px);
  }
}
@media (orientation: landscape) and (max-height: 520px) {
  #play-screen .game-hud #goal {
    max-width: 350px;
  }
  #play-screen.table-mode .table-surface {
    padding-top: calc(47px + env(safe-area-inset-top, 0px));
  }
  #play-screen .city-layout {
    grid-template-rows: minmax(0, 1fr) 49px;
  }
  .city-dock {
    padding: 3px 0;
  }
  .city-dock > button,
  .table-surface .city-dock .map-zoom {
    min-height: 42px;
    flex-direction: row;
    gap: 5px;
  }
  .city-dock img {
    width: 22px;
    height: 22px;
  }
  #play-screen .city-center {
    padding: 4px;
    gap: 3px;
  }
  #play-screen .city-center p {
    font-size: 10px;
    padding: 5px;
    max-height: 45px;
    line-height: 1.3;
  }
  #play-screen .city-center .dice-caption {
    font-size: 10px;
    padding: 3px 5px;
    margin-top: 5px;
  }
  #play-screen .city-center .die-face {
    width: 39px;
    height: 39px;
    padding: 6px;
    gap: 2px;
  }
  #play-screen .city-center .die-pip {
    width: 6px;
    height: 6px;
  }
  .map-colors button {
    min-height: 32px;
    min-width: 23px;
    font-size: 8px;
    gap: 1px;
  }
  .map-colors i {
    width: 18px;
    height: 16px;
  }
  .city-status .wallet-strip {
    padding: 5px 8px;
    gap: 2px;
  }
  .city-status .wallet-strip b {
    font-size: 14px;
  }
  .city-turn-action .decision-card {
    padding: 8px;
  }
  .city-turn-action .decision-card p {
    font-size: 11px;
    margin: 5px 0;
  }
  .city-turn-action .decision-image {
    display: none;
  }
  .city-turn-action .decision-card h3 {
    font-size: 13px;
  }
  .city-turn-action .decision-card button {
    min-height: 40px;
    padding: 6px;
  }
  .city-sheet-backdrop {
    bottom: 49px;
  }
  #play-screen .city-sidebar.city-sheet {
    bottom: 52px;
  }
  #play-screen .chess-layout {
    grid-template-columns: minmax(0, 1fr) 180px;
    grid-template-rows: minmax(0, 1fr);
  }
  .chess-layout .board-main {
    grid-template-rows: minmax(0, 1fr) 22px;
  }
  #play-screen .chess-actions {
    flex-direction: column;
  }
  .chess-actions .table-toolbar {
    width: 100%;
    flex-direction: column;
  }
  #play-screen .chess-piece {
    font-size: clamp(13px, 4vh, 22px);
  }
}

/* Portrait remains upright; games render to these dimensions directly. */
#play-screen .canvas-wrap {
  inset: 0;
}
#play-screen .game-hud {
  height: 40px;
  top: calc(6px + env(safe-area-inset-top, 0px));
  align-items: center;
  justify-content: center;
}
#play-screen .game-hud > div:first-child {
  display: none;
}
#play-screen .hud-stats {
  max-width: none;
  width: 100%;
  flex-wrap: nowrap;
  justify-content: space-around;
}
#play-screen .hud-stats #health {
  width: auto;
}
#play-screen #practice-badge {
  padding: 2px 5px;
  font-size: 10px;
  line-height: 1.3;
}
#play-screen .game-tactical {
  position: absolute;
  left: 10px;
  right: 10px;
  top: calc(54px + env(safe-area-inset-top, 0px));
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  justify-content: center;
  z-index: 13;
  pointer-events: none;
  color: #e8f7e6;
}
#play-screen .game-tactical span {
  background: #163944cb;
  border: 1px solid #b8d8c230;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.3;
}
#play-screen .game-tactical .warning {
  background: #8c3b35e8;
  color: #fff0c7;
}
#play-screen .game-tactical .equipment {
  display: flex;
  padding: 3px 5px;
  align-items: center;
  gap: 2px;
}
#play-screen .game-tactical img {
  width: 25px;
  height: 25px;
  object-fit: contain;
}
#play-screen.table-mode .game-tactical {
  display: none;
}
#play-screen .table-layout {
  padding: 0;
}
#play-screen .board-turn {
  position: fixed;
  top: calc(6px + env(safe-area-inset-top, 0px));
  left: max(58px, calc(env(safe-area-inset-left) + 50px));
  right: max(58px, calc(env(safe-area-inset-right) + 50px));
  height: 40px;
  margin: 0;
  padding: 5px;
  justify-content: center;
  z-index: 20;
}
#play-screen .city-map-scroll {
  border-radius: 0;
}
#play-screen .city-board {
  border-radius: 0;
  border-width: 2px;
}
#play-screen .chess-board,
#play-screen .xiangqi-board {
  width: 100cqw;
  height: 100cqh;
  aspect-ratio: auto;
  border-radius: 0;
  border-width: 4px;
  --piece-size: min(
    calc(100cqw / var(--cols) * 0.85),
    calc(100cqh / var(--rows) * 0.85)
  );
}
#play-screen .chess-piece {
  width: var(--piece-size);
  height: var(--piece-size);
  aspect-ratio: 1;
  font-size: calc(var(--piece-size) * 0.63);
}
#play-screen .board-cell .stone {
  width: var(--piece-size);
  height: var(--piece-size);
  aspect-ratio: 1;
}
@media (orientation: portrait) {
  #play-screen .touch-buttons {
    bottom: max(20px, env(safe-area-inset-bottom));
    right: 12px;
  }
  #play-screen .direction-controls {
    bottom: max(20px, env(safe-area-inset-bottom));
    left: 12px;
  }
  #play-screen .joystick {
    left: 12px;
    bottom: max(20px, env(safe-area-inset-bottom));
    width: 132px;
    height: 132px;
  }
  #play-screen .game-hud #goal {
    display: none;
  }
  #play-screen .game-tactical span {
    font-size: 10px;
  }
}
