:root {
  color-scheme: light;
  --bg: #f8f8fb;
  --surface: rgba(255, 255, 255, .94);
  --surface-solid: #ffffff;
  --panel: rgba(255, 255, 255, .92);
  --panel-soft: #f4f7fa;
  --line: #e4dfff;
  --line-strong: rgba(123, 97, 255, .8);
  --text: #34364c;
  --text-strong: #090c23;
  --muted: rgba(52, 54, 76, .58);
  --quiet: rgba(52, 54, 76, .32);
  --accent: #7b61ff;
  --accent-strong: #684cf4;
  --accent-soft: #e8edf9;
  --board-light: #e8edf9;
  --board-dark: #b7c0d8;
  --piece-dark: #34364c;
  --piece-light: #f4f7fa;
  --danger: #ef476f;
  --shadow: 0 28px 62.5px rgba(131, 123, 194, .17);
  --shadow-strong: 0 30px 90px rgba(123, 97, 255, .20);
  --radius-card: 26px;
  --radius-control: 12px;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, Roboto, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  z-index: -2;
  width: min(82vw, 980px);
  aspect-ratio: 1;
  right: max(-210px, -10vw);
  top: 50%;
  translate: 0 -50%;
  background: url("assets/figma/chess-symbols.svg") center / contain no-repeat;
  opacity: .46;
  pointer-events: none;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    radial-gradient(circle at 64% 44%, rgba(123, 97, 255, .16), transparent 34%),
    linear-gradient(135deg, #ffffff 0%, #fafaff 52%, #f4f2ff 100%);
  pointer-events: none;
}

h1, h2, p { margin: 0; }

h1 {
  color: var(--text);
  font-size: clamp(34px, 5vw, 45px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: 0;
  text-align: center;
}

h1::first-letter {
  color: var(--accent);
  font-weight: 800;
}

h2 {
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 12px;
}

#status {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
  margin-top: 10px;
  text-align: center;
}

.app {
  min-height: 100vh;
  padding: clamp(12px, 2.2vw, 32px);
}

.topbar {
  width: min(800px, calc(100vw - 32px));
  min-height: 340px;
  margin: min(12vh, 120px) auto 0;
  padding: 43px 32px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(25px);
}

.room-panel {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  align-items: stretch;
}

.profile-badge {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  justify-self: end;
  max-width: 100%;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent-soft);
  color: var(--text-strong);
  padding: 4px 16px 4px 10px;
  font-size: 18px;
  font-weight: 500;
}

.profile-badge span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.profile-avatar img,
.mini-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mini-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: -7px;
}

.gp-actions {
  display: flex;
  gap: 10px;
  grid-column: 1 / -1;
  flex-wrap: wrap;
}

.gp-actions button { flex: 1 1 150px; }

.language-switch {
  min-height: 48px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: #fff;
  padding: 5px;
}

.language-switch button {
  min-height: 36px;
  border: 0;
  border-radius: 9px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.language-switch button.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(123, 97, 255, .22);
}

input,
button,
select {
  width: 100%;
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-solid);
  color: var(--text-strong);
  padding: 0 20px;
  font: inherit;
  font-size: 18px;
  line-height: 1.2;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease, color .16s ease, transform .16s ease;
}

input::placeholder { color: rgba(0, 0, 0, .30); }

select {
  appearance: none;
  text-align: center;
  cursor: pointer;
  background:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%) calc(100% - 22px) 50% / 7px 7px no-repeat,
    linear-gradient(135deg, var(--accent) 50%, transparent 50%) calc(100% - 16px) 50% / 7px 7px no-repeat,
    #fff;
}

button {
  cursor: pointer;
  justify-content: center;
  color: var(--accent);
  background: #fff;
  border-color: var(--line-strong);
}

button:hover,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(123, 97, 255, .12);
}

button:active { transform: translateY(1px); }

button:disabled,
button.is-disabled {
  opacity: .42;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#create {
  grid-column: 1 / -1;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

#create:hover {
  background: var(--accent-strong);
}

#randomMatch {
  grid-column: 1 / -1;
  color: var(--accent);
  background: rgba(255, 255, 255, .74);
}

#join {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

#gpLogin {
  justify-self: start;
  width: auto;
  min-height: 48px;
  padding: 0 15px;
  font-size: 14px;
}

#name {
  grid-column: 1 / -1;
}

button.danger {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(360px, 1fr) minmax(250px, 320px);
  gap: clamp(14px, 1.8vw, 24px);
  align-items: start;
  width: min(1440px, 100%);
  margin: 0 auto;
}

body:not(.has-state) .layout { display: none; }
body.has-state .topbar { display: none; }
body:not(.has-state) .game-sound { display: none; }
body.has-state .app {
  padding: clamp(8px, 1.4vw, 18px);
}

.side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.block {
  border: 1px solid rgba(228, 223, 255, .72);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(131, 123, 194, .10);
  backdrop-filter: blur(20px);
  padding: 18px;
}

[hidden] { display: none !important; }

.game-sound {
  align-self: flex-end;
  flex: 0 0 auto;
  width: auto;
  max-width: min(150px, calc(100vw - 24px));
  min-height: 38px;
  padding: 8px 12px;
  border-radius: var(--radius-control);
  border-color: rgba(123, 97, 255, .36);
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 10px 26px rgba(92, 79, 159, .14);
  backdrop-filter: blur(16px);
  color: var(--accent);
  font-size: 13px;
}

.my-turn #handBlock,
.turn-card.turn-active {
  border-color: var(--accent);
  box-shadow: var(--shadow-strong), 0 0 0 3px rgba(123, 97, 255, .10);
}

.hand-turn-meter {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin: -2px 0 10px;
  border: 1px solid rgba(123, 97, 255, .24);
  border-radius: var(--radius-control);
  background: rgba(232, 237, 249, .78);
  color: var(--text-strong);
  padding: 7px 10px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.hand-turn-meter.is-mine {
  border-color: var(--accent);
  background: rgba(123, 97, 255, .12);
  color: var(--accent-strong);
}

.turn-card {
  min-height: 216px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.turn-card h2 {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 18px;
  font-weight: 500;
}

.turn-count {
  margin: 12px 0 8px;
  color: var(--accent);
  font-size: clamp(54px, 7vw, 82px);
  font-weight: 800;
  line-height: 1;
}

.turn-caption {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

.room-details {
  color: var(--muted);
  line-height: 1.45;
}

#players {
  display: grid;
  gap: 9px;
  margin-top: 12px;
  color: var(--text);
  font-size: 15px;
}

.progress-block h2,
.room-details h2,
#handBlock h2,
.played-cards-panel h2 {
  font-size: 18px;
}

.gp-status {
  margin: -4px 0 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.progress-grid div {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: #fff;
  padding: 10px 12px;
}

.progress-grid strong {
  display: block;
  color: var(--accent);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.progress-grid span,
.progress-grid p {
  display: block;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.rules summary,
.log-block summary {
  cursor: pointer;
  color: var(--text-strong);
  font-weight: 600;
}

.rules ul {
  max-height: 280px;
  overflow: auto;
  padding-left: 18px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.rules li + li { margin-top: 8px; }

.board-wrap {
  display: grid;
  width: 100%;
  place-items: start center;
}

body:not(.has-state) .board-wrap { display: none; }

.board-stage {
  position: relative;
  display: grid;
  width: min(74vh, 100%);
  max-width: 690px;
  padding: 8px;
  overflow: visible;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 26px 68px rgba(52, 54, 76, .14);
}

.board-stage.has-card-overlay .board {
  opacity: .34;
  pointer-events: none;
}

.board-card-overlay {
  position: absolute;
  inset: 8px;
  z-index: 5;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.board-card-panel {
  width: min(260px, 52%);
  display: grid;
  gap: 12px;
  justify-items: stretch;
  padding: 16px;
  border: 1px solid rgba(228, 223, 255, .92);
  border-radius: 22px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow-strong);
  backdrop-filter: blur(18px);
}

.board-card-panel h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: 16px;
  text-align: center;
}

.board-card-panel .opponent-card.card {
  width: 100%;
  min-height: 168px;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  overflow: visible;
  border: 0;
  border-radius: 8px;
  background: var(--board-light);
  transition: opacity .16s ease;
}

.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  place-items: center;
  user-select: none;
  cursor: pointer;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  padding: 6.25%;
}

.square.light {
  background: var(--board-light);
  color: var(--board-dark);
}

.square.dark {
  background: var(--board-dark);
  color: var(--board-light);
}

.square.selected {
  outline: clamp(3px, .65vmin, 5px) solid var(--accent);
  outline-offset: clamp(-5px, -.65vmin, -3px);
  box-shadow:
    inset 0 0 0 999px rgba(123, 97, 255, .16),
    inset 0 0 0 2px rgba(255, 255, 255, .48);
}

.square.legal-target {
  box-shadow: inset 0 0 0 999px rgba(123, 97, 255, .12);
}

.square:hover {
  box-shadow: inset 0 0 0 999px rgba(123, 97, 255, .08);
}

.square:disabled { opacity: 1; }

.coord {
  position: absolute;
  z-index: 2;
  left: 10px;
  top: 9px;
  color: currentColor;
  font-family: Roboto, Inter, system-ui, sans-serif;
  font-size: clamp(8px, 1.35vmin, 14px);
  font-weight: 500;
  line-height: 1;
  text-transform: uppercase;
  pointer-events: none;
}

.move-dot {
  position: absolute;
  z-index: 4;
  width: clamp(18px, 28%, 38px);
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(123, 97, 255, .84);
  border: clamp(2px, .45vmin, 4px) solid rgba(255, 255, 255, .92);
  box-shadow:
    0 6px 16px rgba(52, 54, 76, .28),
    0 0 0 clamp(2px, .45vmin, 5px) rgba(123, 97, 255, .2);
  pointer-events: none;
}

.piece {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
  display: block;
  width: var(--piece-size, 82%);
  height: var(--piece-size, 82%);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  transform: translate(-50%, -50%);
}

.piece-p { --piece-size: 74%; }
.piece-b { --piece-size: 75%; }
.piece-n { --piece-size: 73%; }
.piece-r { --piece-size: 82%; }
.piece-k { --piece-size: 87%; }
.piece-q { --piece-size: 89%; }

.hand {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}

.card {
  min-height: 108px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px;
  font-weight: 800;
  text-shadow: none;
  box-shadow: 0 12px 26px rgba(52, 54, 76, .16);
}

.card.is-disabled {
  filter: grayscale(.28) saturate(.7);
  opacity: .48;
}

.card small {
  font-size: 12px;
  font-weight: 600;
  opacity: .92;
}

.card span {
  font-size: 28px;
  line-height: 1;
}

.card i {
  display: block;
  font-size: 30px;
  margin-bottom: 6px;
}

.card b {
  display: block;
  font-size: 17px;
}

.opponent-card {
  min-height: 176px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.opponent-card.card {
  min-height: 220px;
  padding: 18px;
  font-size: 48px;
}

.opponent-card.card small { font-size: 16px; }

.opponent-card.empty {
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  background: rgba(232, 237, 249, .42);
}

.played-cards-panel {
  display: grid;
  gap: 10px;
}

.played-cards-panel h2 {
  margin-bottom: 0;
}

.played-cards-surface {
  display: grid;
  gap: 9px;
  border: 1px solid rgba(123, 97, 255, .42);
  border-radius: 14px;
  background: rgba(232, 237, 249, .72);
  padding: 10px;
}

.played-card-slot {
  display: grid;
  gap: 6px;
}

.played-card-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.played-card-versus {
  display: grid;
  place-items: center;
  width: 34px;
  height: 26px;
  justify-self: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-solid);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.played-card {
  min-height: 104px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.played-card.card {
  min-height: 104px;
  padding: 10px;
  font-size: 34px;
}

.played-card.card small { font-size: 13px; }

.played-card.empty {
  border: 1px dashed var(--line-strong);
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  padding: 10px;
  font-size: 13px;
  line-height: 1.3;
}

.red { background: linear-gradient(135deg, #ff5a7d, #ef476f); }
.yellow { background: linear-gradient(135deg, #ffd166, #f2b84b); color: #513c00; }
.green { background: linear-gradient(135deg, #36d399, #20a874); }
.blue { background: linear-gradient(135deg, #4ea8ff, #3d7cff); }
.wild { background: linear-gradient(135deg, #ef476f, #ffd166 35%, #20a874 65%, #3d7cff); }
.special { background: linear-gradient(135deg, #34364c, #7b61ff 55%, #ffd166); }

.wide {
  width: 100%;
  margin-top: 10px;
}

.hand-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.hand-actions button {
  min-width: 0;
}

.compact-leave {
  display: none;
}

.log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.log-block .log { margin-top: 10px; }

.toast {
  position: fixed;
  z-index: 20;
  max-width: min(440px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: rgba(255, 255, 255, .96);
  color: var(--text-strong);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  translate: 0 8px;
  transition: opacity .16s ease, translate .16s ease;
}

.toast.show {
  opacity: 1;
  translate: 0 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(52, 54, 76, .30);
  backdrop-filter: blur(10px);
}

.modal-card {
  width: min(460px, 100%);
  border: 1px solid rgba(228, 223, 255, .9);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-strong);
  padding: 24px;
}

.modal-card p {
  color: var(--muted);
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.matchmaking-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 36%, rgba(123, 97, 255, .18), transparent 32%),
    rgba(248, 248, 251, .96);
  backdrop-filter: blur(18px);
}

.matchmaking-panel {
  width: min(560px, 100%);
  display: grid;
  gap: 22px;
  justify-items: center;
  text-align: center;
}

.matchmaking-panel p {
  color: var(--text-strong);
  font-size: clamp(38px, 8vw, 76px);
  font-weight: 800;
  line-height: .98;
}

.matchmaking-panel strong {
  color: var(--accent);
  font-size: clamp(48px, 12vw, 104px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.matchmaking-panel button {
  width: min(320px, 100%);
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(248, 248, 251, .76);
  backdrop-filter: blur(16px);
}

.result-panel {
  width: min(520px, 100%);
  display: grid;
  justify-items: center;
  gap: 14px;
  border: 1px solid rgba(228, 223, 255, .9);
  border-radius: var(--radius-card);
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow-strong);
  padding: clamp(26px, 6vw, 44px);
  text-align: center;
}

.result-panel p {
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
}

.result-panel strong {
  color: var(--accent);
  font-size: clamp(64px, 14vw, 126px);
  font-weight: 900;
  line-height: .9;
}

.result-overlay.is-lose .result-panel strong {
  color: var(--danger);
}

.result-panel span {
  color: var(--text);
  font-size: 18px;
  line-height: 1.35;
}

.result-actions {
  width: min(300px, 100%);
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.result-panel button {
  width: min(300px, 100%);
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.result-panel button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: minmax(230px, 300px) minmax(330px, 1fr);
  }

  .layout > .side:last-child {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 700px) and (max-height: 820px) {
  body.has-state {
    overflow: hidden;
  }

  body.has-state .app {
    height: 100svh;
    padding: 8px;
    overflow: hidden;
  }

  body.has-state .layout {
    width: min(1280px, 100%);
    height: calc(100svh - 16px);
    display: grid;
    grid-template-columns: minmax(0, min(calc(100svh - 16px), calc(100vw - 300px))) minmax(284px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: 10px;
    overflow: hidden;
  }

  body.has-state .layout > .side:first-child {
    display: none;
  }

  body.has-state .layout > .board-wrap {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    place-items: center;
  }

  body.has-state .layout > .side:last-child {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    -webkit-overflow-scrolling: touch;
  }

  body.has-state .board-stage {
    width: min(100%, calc(100svh - 16px), calc(100vw - 300px));
    max-width: none;
    padding: 6px;
  }

  body.has-state .board-card-overlay {
    inset: 6px;
  }

  body.has-state .board-card-panel {
    width: min(210px, 56%);
    gap: 8px;
    padding: 12px;
    border-radius: 18px;
  }

  body.has-state .board-card-panel .opponent-card.card {
    min-height: 132px;
  }

  body.has-state .block {
    padding: 12px;
    border-radius: 16px;
  }

  body.has-state #handBlock h2,
  body.has-state .played-cards-panel h2 {
    font-size: 16px;
    margin-bottom: 8px;
  }

  body.has-state .hand-turn-meter {
    min-height: 34px;
    margin-bottom: 8px;
    padding: 5px 8px;
    font-size: 12px;
  }

  body.has-state .hand {
    display: flex;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding-bottom: 4px;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.has-state .card {
    flex: 0 0 78px;
    min-width: 78px;
    min-height: 86px;
    border-radius: 14px;
  }

  body.has-state .wide {
    min-height: 46px;
    margin-top: 6px;
  }

  body.has-state .hand-actions {
    gap: 8px;
    margin-top: 6px;
  }

  body.has-state .hand-actions button {
    min-height: 46px;
  }

  body.has-state .compact-leave {
    display: block;
  }

  body.has-state .opponent-card,
  body.has-state .opponent-card.card {
    min-height: 104px;
    font-size: 34px;
  }

  body.has-state .log-block { display: none; }
}

@media (max-width: 860px) {
  body::before {
    width: 110vw;
    right: -55vw;
    top: 28%;
    opacity: .30;
  }

  .app {
    min-width: 0;
    padding: 10px;
    overflow-x: hidden;
  }

  .topbar {
    width: 100%;
    min-height: calc(100vh - 20px);
    margin: 0;
    padding: 30px 18px;
  }

  .room-panel {
    grid-template-columns: 1fr;
  }

  .profile-badge,
  #gpLogin {
    justify-self: stretch;
    width: 100%;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 0;
    width: 100%;
    min-width: 0;
  }

  body.has-state .layout > .side:first-child { display: none; }
  .layout > .side:first-child { order: 3; }
  .layout > .board-wrap {
    order: 1;
    flex: 0 0 auto;
  }
  .layout > .side:last-child {
    order: 2;
    display: flex;
    width: 100%;
    min-width: 0;
  }

  .side {
    width: 100%;
    min-width: 0;
    gap: 10px;
  }

  .block {
    width: 100%;
    min-width: 0;
    padding: 14px;
    border-radius: 16px;
  }

  .board-stage {
    width: min(100%, calc(100vw - 20px), calc(100svh - 222px), 690px);
    min-width: 0;
    padding: 6px;
  }

  .board-card-overlay {
    inset: 6px;
  }

  .board-card-panel {
    width: min(188px, 58%);
    gap: 8px;
    padding: 10px;
    border-radius: 18px;
  }

  .board-card-panel h2 {
    font-size: 14px;
  }

  .board-card-panel .opponent-card.card {
    min-height: 118px;
    font-size: 32px;
  }

  .turn-card { min-height: 126px; }

  .turn-count {
    margin: 8px 0 4px;
    font-size: 46px;
  }

  #handBlock {
    position: relative;
    z-index: 6;
  }

  #handBlock h2,
  .played-cards-panel h2 {
    margin-bottom: 8px;
  }

  .hand-turn-meter {
    min-height: 36px;
    margin-bottom: 8px;
    padding: 6px 8px;
    font-size: 13px;
  }

  .hand {
    display: flex;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .card {
    min-width: 78px;
    min-height: 86px;
    scroll-snap-align: start;
    border-radius: 14px;
    padding: 8px;
  }

  .card span { font-size: 24px; }

  input,
  button,
  select {
    min-height: 54px;
    font-size: 16px;
  }

  .wide {
    min-height: 44px;
    margin-top: 6px;
  }

  .hand-actions {
    gap: 8px;
    margin-top: 6px;
  }

  .hand-actions button {
    min-height: 44px;
  }

  .opponent-card,
  .opponent-card.card {
    width: 100%;
    min-height: 112px;
    font-size: 34px;
  }

  .progress-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .log { max-height: 180px; }
  .coord { left: 6px; top: 6px; font-size: 8px; }
}

@media (max-width: 640px) and (orientation: portrait) {
  body.has-state .app {
    padding: 8px;
    min-height: 100svh;
  }

  body.has-state .layout {
    gap: 8px;
    min-height: 0;
  }

  body.has-state .layout > .board-wrap {
    display: block;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  body.has-state .board-stage {
    --portrait-board-size: min(calc(100vw - 16px), 690px);
    width: min(100%, var(--portrait-board-size));
    height: auto;
    padding: 5px;
    border-radius: 12px;
  }

  body.has-state .block {
    padding: 10px;
    border-radius: 14px;
  }

  body.has-state #handBlock h2,
  body.has-state .played-cards-panel h2 {
    margin-bottom: 6px;
    font-size: 18px;
  }

  body.has-state .hand {
    gap: 7px;
    padding-bottom: 3px;
  }

  body.has-state .card {
    min-width: 70px;
    min-height: 76px;
    padding: 7px;
  }

  body.has-state .card small {
    font-size: 12px;
  }

  body.has-state .card span {
    font-size: 22px;
  }

  body.has-state .wide,
  body.has-state .hand-actions button {
    min-height: 40px;
  }

  body.has-state .hand-actions {
    gap: 7px;
    margin-top: 5px;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  body::before {
    width: 70vw;
    right: -20vw;
    top: 50%;
    opacity: .24;
  }

  .app {
    height: 100svh;
    padding: 8px;
    overflow: hidden;
  }

  .layout {
    height: calc(100svh - 16px);
    display: grid;
    grid-template-columns: minmax(0, calc(100svh - 16px)) minmax(250px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: 8px;
    overflow: hidden;
  }

  .layout > .board-wrap {
    order: initial;
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
    place-items: center;
  }

  .layout > .side:first-child {
    order: initial;
    display: none;
  }

  .layout > .side:last-child {
    order: initial;
    grid-column: 2;
    grid-row: 1;
    min-height: 0;
    display: flex;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .board-stage {
    width: min(100%, calc(100svh - 16px));
    max-width: none;
    padding: 5px;
  }

  .board-card-overlay {
    inset: 5px;
  }

  .board-card-panel {
    width: min(170px, 55%);
    gap: 7px;
    padding: 9px;
    border-radius: 16px;
  }

  .board-card-panel h2 {
    font-size: 13px;
  }

  .board-card-panel .opponent-card.card {
    min-height: 104px;
    font-size: 30px;
  }

  .block {
    padding: 12px;
    border-radius: 14px;
  }

  #handBlock h2,
  .played-cards-panel h2 {
    font-size: 16px;
  }

  .hand-turn-meter {
    min-height: 32px;
    font-size: 12px;
  }

  .card {
    min-width: 72px;
    min-height: 78px;
  }

  .compact-leave {
    display: block;
  }

  .opponent-card,
  .opponent-card.card {
    min-height: 96px;
  }

  .played-card,
  .played-card.card {
    min-height: 82px;
    font-size: 28px;
  }
}

@media (max-width: 520px) {
  .topbar {
    border-radius: 22px;
  }

  h1 { font-size: 36px; }

  .progress-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gp-actions {
    flex-direction: column;
  }
}

.board-card-panel.played-cards-panel {
  width: min(430px, 78%);
  max-height: calc(100% - 20px);
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
}

.played-cards-panel .played-cards-surface {
  width: 100%;
}

.played-cards-prompt {
  min-height: 170px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(123, 97, 255, .42);
  border-radius: 14px;
  background: rgba(232, 237, 249, .82);
  color: var(--text-strong);
  padding: 24px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
}

.played-cards-panel .played-card,
.played-cards-panel .played-card.card {
  min-height: 96px;
}

@media (max-width: 860px) {
  body.has-state .board-card-panel.played-cards-panel {
    width: min(360px, 82%);
    gap: 8px;
    padding: 10px;
  }

  .played-cards-panel .played-cards-surface {
    gap: 6px;
    padding: 8px;
  }

  .played-cards-prompt {
    min-height: 140px;
    padding: 18px;
    font-size: 18px;
  }

  .played-cards-panel .played-card,
  .played-cards-panel .played-card.card {
    min-height: 78px;
  }
}

@media (max-width: 640px) and (orientation: portrait) {
  body.has-state .board-card-panel.played-cards-panel {
    width: min(330px, 86%);
  }

  .played-cards-panel .played-card,
  .played-cards-panel .played-card.card {
    min-height: 72px;
  }

  .played-cards-prompt {
    min-height: 124px;
    padding: 16px;
    font-size: 17px;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  body.has-state .board-card-panel.played-cards-panel {
    width: min(300px, 72%);
    gap: 5px;
    padding: 8px;
  }

  .played-cards-panel .played-cards-surface {
    gap: 4px;
    padding: 7px;
  }

  .played-cards-panel .played-card-slot {
    gap: 3px;
  }

  .played-cards-panel .played-card,
  .played-cards-panel .played-card.card {
    min-height: 58px;
  }

  .played-cards-panel .played-card-versus {
    height: 22px;
  }

  .played-cards-prompt {
    min-height: 96px;
    padding: 12px;
    font-size: 16px;
  }
}
