/* Language controls and space for longer translations; board geometry is unchanged. */
h1, #loading-title, #rules-header h2, #victory-title, #feedback-modal h2 { letter-spacing: 0; }
/* Two equal side columns keep the title centred: the 四国军棋 link on the left, the language control on the right. */
.game-header {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 6px;
  align-items: center; width: 100%; max-width: 480px; min-height: 52px; margin: 2px 0;
}
.game-header h1 { grid-column: 2; margin: 0; text-align: center; white-space: nowrap; font-size: 24px; }
#link-siguo {
  grid-column: 1; justify-self: start;
  display: inline-flex; align-items: center; height: 34px; padding: 0 10px; box-sizing: border-box;
  border: 1px solid rgba(240, 216, 112, .5); border-radius: 17px;
  background: rgba(240, 216, 112, .1); color: #f0d870;
  font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: background .15s ease, border-color .15s ease;
}
#link-siguo:hover { background: rgba(240, 216, 112, .18); border-color: rgba(240, 216, 112, .8); }
#link-siguo:focus-visible { outline: 2px solid #a9cbe6; outline-offset: 2px; }
@media (max-width: 700px) { #link-siguo { height: 32px; padding: 0 8px; font-size: 12px; } }
.language-control { position: relative; grid-column: 3; justify-self: end; font-size: 13px; }
.language-control.is-open { z-index: 450; }
#language-trigger {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 74px; height: 40px; padding: 0 7px; border: 1px solid transparent; border-radius: 6px;
  color: #aab7c8; background: transparent; cursor: pointer; font: inherit;
  transition: color .15s ease, background .15s ease;
}
#language-trigger:hover, #language-trigger[aria-expanded="true"] {
  color: #f0d870; background: rgba(240, 216, 112, .07); border-color: rgba(240, 216, 112, .14);
}
#language-current { width: 18px; flex-shrink: 0; font-size: 11px; font-weight: 600; text-align: center; }
.language-icon {
  width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.language-chevron { width: 10px; height: 10px; transition: transform .15s ease; }
#language-trigger[aria-expanded="true"] .language-chevron { transform: rotate(180deg); }
.language-dismiss { position: fixed; inset: 0; z-index: 1; cursor: default; touch-action: none; }
#language-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 2;
  width: 208px; max-width: calc(100vw - 24px); max-height: calc(100dvh - 112px); overflow-y: auto; padding: 6px;
  overscroll-behavior: contain;
  color: #dbe2eb; background: #222837; border: 1px solid #414956; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); animation: languageMenuIn .14s ease-out;
}
#language-menu[hidden], .language-dismiss[hidden] { display: none; }
#language-menu-title { padding: 7px 10px 8px; font-size: 11px; color: #98a5b7; }
#language-menu ul { list-style: none; margin: 0; padding: 0; }
#language-menu [role="menuitemradio"] {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 4px;
  background: transparent; color: inherit; font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
#language-menu [aria-checked="true"] { color: #f0d870; background: rgba(240,216,112,.07); }
#language-menu [role="menuitemradio"]:hover { background: rgba(255,255,255,.07); }
#language-trigger:focus-visible, #language-menu [role="menuitemradio"]:focus-visible {
  outline: 2px solid #a9cbe6; outline-offset: -2px;
}
.language-check { visibility: hidden; width: 16px; height: 16px; }
[aria-checked="true"] .language-check { visibility: visible; }
@keyframes languageMenuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  #language-menu { animation: none; }
  #language-trigger, .language-chevron { transition: none; }
}
/* Language offer for first-time visitors with a non-Chinese browser. Fixed, so it never moves the board. */
#language-prompt {
  position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 90; display: flex; align-items: center; gap: 12px;
  max-width: calc(100vw - 24px); padding: 8px 8px 8px 16px;
  background: rgba(10,14,24,.95); color: #d0d8e0; font-size: 13px; line-height: 1.4;
  border: 1px solid rgba(255,255,255,.12); border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
#language-prompt-switch {
  flex-shrink: 0; padding: 6px 12px; border-radius: 7px; background: #2a5fc8; color: #fff;
  text-decoration: none; font-weight: bold; white-space: nowrap;
}
#language-prompt-close {
  flex-shrink: 0; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: #98a4b0; font-size: 18px; line-height: 1; cursor: pointer;
}
#language-prompt-close:hover { background: rgba(255,255,255,.08); }
#language-prompt-switch:focus-visible, #language-prompt-close:focus-visible { outline: 2px solid #a9cbe6; outline-offset: 2px; }
#game-center { min-width: 0; max-width: 100%; }
#status-wrap, #connection-status { max-width: min(480px, calc(100vw - 24px)); }
#connection-text { min-width: 0; overflow-wrap: anywhere; }
#btn-reconnect { flex-shrink: 0; }
#status-wrap { min-width: 0; width: 100%; }
/* Status text must not move the layout when its length changes (see reserveStatusHeight in index.html):
   on wide screens the center column has a fixed width instead of growing with the status text,
   and the status box keeps a reserved height with its two lines centered inside it. */
@media (min-width: 701px) {
  #game-center { width: min(440px, calc(100% - 256px)); }
}
#status-wrap { display: flex; flex-direction: column; justify-content: center; }
#status { min-height: 1.65em; }
#info { min-height: 1.5em; }
/* The action log keeps a fixed height (its former max-height): new lines would otherwise push the
   graveyards below it on phones, and shift the vertically centered column on tall desktop screens. */
#action-log { height: 150px; }
@media (max-width: 700px) {
  #action-log { height: 90px; }
}
#status, #info, #stats-bar { overflow-wrap: anywhere; }
#status { line-height: 1.65; }
#status .red, #info .red { color: #e74c3c; }
#status .blue, #info .blue { color: #5dade2; }
#info { line-height: 1.5; }
#mode-toggle { max-width: calc(100vw - 16px); }
#mode-toggle button { min-width: 0; }
button, #mode-toggle button, #lobby-modal h2 { letter-spacing: 0; }
#pve-options { flex-wrap: wrap; justify-content: center; max-width: 100%; }
#toast, #turn-banner, #turn-banner.show-camp {
  max-width: calc(100vw - 32px); width: max-content; white-space: normal;
  overflow-wrap: anywhere; text-align: center; line-height: 1.5;
}
#toast { padding: 12px 20px; }
#victory-title { font-size: 26px; line-height: 1.35; overflow-wrap: anywhere; }
#victory-reason, #victory-player, #confirm-text, #endgame-text, #lobby-error {
  overflow-wrap: anywhere;
}
#victory-actions, #confirm-buttons, #endgame-buttons { flex-wrap: wrap; }
#lobby-modal { width: min(440px, calc(100vw - 24px)); min-width: 0; max-height: calc(100vh - 24px); overflow-y: auto; }
#input-room-code { width: 100%; min-width: 0; }
#btn-join-room { flex-shrink: 0; }
#rules-body table { table-layout: fixed; width: 100%; }
#rules-body table:first-of-type th:nth-child(2) { width: 56px; }
#rules-body td, #rules-body th { overflow-wrap: anywhere; }
#rules-body .rank-chain { white-space: normal; line-height: 1.8; letter-spacing: 0; }
#rules-body h3 { letter-spacing: 0; }
.gy-title { white-space: normal; line-height: 1.4; letter-spacing: 0; }
.gy-piece { min-width: 0; }
html[lang="en"] .gy-piece { font-size: 10px; }
html[lang="ko"] .gy-piece { font-size: 10px; }
@media (max-width: 600px) {
  .game-header { min-height: 44px; }
  .game-header h1 { font-size: 18px; }
  #language-trigger { width: 68px; height: 44px; padding: 0 6px; gap: 4px; }
  #status-wrap { max-width: calc(100vw - 24px); padding: 6px 10px; }
  #mode-toggle button { padding: 5px 12px; }
  #lobby-modal { padding: 24px 18px; }
  #rules-body { padding: 12px; }
  #rules-body td, #rules-body th { padding: 6px; }
  #victory-title { font-size: 22px; }
  .gy-piece { width: 38px; }
}
