.three-piece-page {
  --three-piece-accent: #72e9ff;
  --three-piece-violet: #aa7cff;
  width: 100%;
  min-width: 0;
  min-height: 100%;
  color: var(--semi-color-text-0, #f7f5ff);
}

body.three-piece-active .main-scroll {
  scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
  body.three-piece-active .main-scroll {
    overflow-y: scroll;
  }
}

.three-piece-page .glass {
  border: 1px solid color-mix(in srgb, var(--three-piece-accent) 24%, rgba(140, 118, 220, .32));
  background: linear-gradient(145deg, rgba(14, 34, 70, .76), rgba(38, 21, 68, .72));
  box-shadow: 0 18px 48px rgba(4, 9, 32, .24), inset 0 1px rgba(255, 255, 255, .05);
  backdrop-filter: blur(18px);
}

.three-piece-login {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 620px;
  margin: 80px auto;
  padding: 28px;
  border-radius: 22px;
}

.three-piece-login > span { font-size: 32px; }
.three-piece-login h2 { margin-bottom: 6px; font-size: 20px; }
.three-piece-login p { color: var(--semi-color-text-2, #aaa4c8); }

.three-piece-lobby {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(300px, 420px);
  gap: clamp(28px, 6vw, 76px);
  max-width: 980px;
  margin: 34px auto;
  padding: clamp(28px, 5vw, 56px);
  border-radius: 28px;
}

.three-piece-lobby-copy { align-self: center; }
.three-piece-kicker { color: var(--three-piece-accent); font-size: 12px; font-weight: 700; letter-spacing: .16em; }
.three-piece-lobby-copy h2 { margin: 12px 0 14px; font-size: clamp(28px, 4vw, 44px); line-height: 1.1; }
.three-piece-lobby-copy p { max-width: 470px; margin-bottom: 22px; color: var(--semi-color-text-2, #aaa4c8); line-height: 1.8; }

.three-piece-lobby-form { display: grid; gap: 14px; padding: 22px; border: 1px solid rgba(151, 133, 220, .22); border-radius: 20px; background: rgba(6, 13, 43, .4); }
.three-piece-lobby-form label { display: grid; gap: 7px; color: var(--semi-color-text-2, #b6b0d5); font-size: 13px; }
.three-piece-lobby-form input,
.three-piece-lobby-form select {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid rgba(145, 127, 215, .32);
  border-radius: 12px;
  outline: none;
  color: #f7f5ff;
  background: rgba(8, 15, 48, .76);
}
.three-piece-lobby-form input:focus,
.three-piece-lobby-form select:focus { border-color: var(--three-piece-accent); box-shadow: 0 0 0 3px rgba(114, 233, 255, .12); }

.three-piece-primary { border-color: rgba(114, 233, 255, .35) !important; color: #081630 !important; background: linear-gradient(135deg, var(--three-piece-accent), #a790ff) !important; font-weight: 700; }
.three-piece-divider { display: flex; align-items: center; gap: 10px; color: #777291; font-size: 12px; }
.three-piece-divider::before, .three-piece-divider::after { content: ""; flex: 1; height: 1px; background: rgba(151, 133, 220, .2); }

.three-piece-room-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 980px;
  margin: 6px auto 18px;
  padding: 12px 14px;
  border-radius: 18px;
}
.three-piece-room-bar > div { display: grid; margin-right: auto; }
.three-piece-room-bar > div span { color: var(--semi-color-text-2, #aaa4c8); font-size: 11px; }
.three-piece-room-bar > div strong { letter-spacing: .2em; }

.three-piece-connection { display: inline-flex; align-items: center; gap: 7px; padding: 0 7px; color: var(--semi-color-text-2, #aaa4c8); font-size: 12px; white-space: nowrap; }
.three-piece-connection i { width: 8px; height: 8px; border-radius: 50%; background: #f7bd66; box-shadow: 0 0 10px currentColor; }
.three-piece-connection.is-connected i { background: #71f3b1; }
.three-piece-connection.is-error i { background: #ff7189; }

.three-piece-layout {
  display: grid;
  grid-template-columns: minmax(320px, 590px) minmax(240px, 320px);
  justify-content: center;
  align-items: start;
  gap: 18px;
  min-width: 0;
  max-width: 980px;
  margin: 0 auto;
}
.three-piece-layout > main,
.three-piece-side,
.three-piece-board-shell { min-width: 0; }
.three-piece-layout > main { display: grid; gap: 12px; }
.three-piece-board-shell { display: grid; place-items: center; padding: clamp(18px, 4vw, 42px); border-radius: 24px; }
.three-piece-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  width: min(100%, 460px);
  aspect-ratio: 1;
  contain: size layout paint;
  overflow: hidden;
  border: 2px solid rgba(114, 233, 255, .52);
  border-radius: 20px;
  background: rgba(6, 13, 43, .54);
  box-shadow: 0 0 34px rgba(114, 233, 255, .1);
}
.three-piece-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-right: 1px solid rgba(114, 233, 255, .32);
  border-bottom: 1px solid rgba(114, 233, 255, .32);
  color: inherit;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .16s ease, box-shadow .16s ease, transform .16s ease;
}
.three-piece-cell:nth-child(3n) { border-right: 0; }
.three-piece-cell:nth-child(n+7) { border-bottom: 0; }
.three-piece-cell:not(:disabled):hover { background: rgba(114, 233, 255, .08); }
.three-piece-cell:focus-visible { z-index: 2; outline: 3px solid #fff; outline-offset: -5px; }
.three-piece-cell.is-target::after { content: ""; width: 18%; aspect-ratio: 1; border: 1px solid var(--three-piece-accent); border-radius: 50%; opacity: .68; box-shadow: 0 0 16px var(--three-piece-accent); }
.three-piece-cell.is-selected { background: rgba(170, 124, 255, .16); box-shadow: inset 0 0 0 3px var(--three-piece-violet); }
.three-piece-cell.is-winning { background: rgba(113, 243, 177, .13); box-shadow: inset 0 0 24px rgba(113, 243, 177, .25); }
.three-piece-token { position: absolute; inset: 22%; display: grid; place-items: center; aspect-ratio: 1; font-family: ui-rounded, system-ui, sans-serif; font-size: clamp(48px, 8vw, 88px); font-weight: 300; line-height: 1; filter: drop-shadow(0 0 13px currentColor); }
.three-piece-token.piece-1 { color: #75ebff; }
.three-piece-token.piece-2 { color: #d59cff; }

.three-piece-meta {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 13px;
}
.three-piece-meta strong { text-align: center; font-size: 16px; }
.three-piece-meta > span:last-child { justify-self: end; font-variant-numeric: tabular-nums; }
.three-piece-meta .is-urgent { color: #ff9dac; }
.three-piece-actions { display: flex; justify-content: center; padding: 12px; border-radius: 16px; }
.three-piece-actions .danger { color: #ffafbc; }

.three-piece-side { display: grid; gap: 14px; }
.three-piece-panel { padding: 16px; border-radius: 20px; }
.three-piece-panel h3 { font-size: 15px; }
.three-piece-panel p { margin-top: 10px; color: var(--semi-color-text-2, #aaa4c8); font-size: 13px; line-height: 1.7; }
.three-piece-panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.three-piece-panel-title span { color: var(--semi-color-text-2, #aaa4c8); font-size: 12px; }
.three-piece-players { display: grid; gap: 10px; margin-bottom: 12px; }
.three-piece-player {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  min-height: 76px;
  padding: 12px;
  border: 1px solid rgba(151, 133, 220, .18);
  border-radius: 14px;
  background: rgba(7, 13, 43, .4);
}
.three-piece-player.is-active { border-color: rgba(114, 233, 255, .5); box-shadow: 0 0 20px rgba(114, 233, 255, .08); }
.three-piece-player.is-offline { opacity: .62; }
.three-piece-seat { grid-column: 2; color: var(--semi-color-text-2, #aaa4c8); font-size: 11px; }
.three-piece-avatar { grid-column: 1; grid-row: 1 / 4; align-self: center; display: grid; place-items: center; width: 38px; height: 38px; overflow: hidden; border: 1px solid rgba(114, 233, 255, .28); border-radius: 50%; color: var(--three-piece-accent); background: rgba(114, 233, 255, .08); }
.three-piece-avatar img { width: 100%; height: 100%; object-fit: cover; }
.three-piece-player strong { grid-column: 2; font-size: 14px; }
.three-piece-player small { grid-column: 2; color: var(--semi-color-text-2, #aaa4c8); }
.three-piece-piece { grid-column: 3; grid-row: 1 / 4; align-self: center; color: var(--three-piece-accent); font-size: 28px; }

.three-piece-dialog-backdrop {
  position: fixed;
  z-index: 1200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 7, 24, .68);
  backdrop-filter: blur(8px);
}
.three-piece-dialog { position: relative; width: min(100%, 520px); padding: 26px; border-radius: 22px; }
.three-piece-dialog h2 { margin-bottom: 16px; font-size: 20px; }
.three-piece-dialog ol { display: grid; gap: 10px; padding-left: 22px; color: var(--semi-color-text-1, #ded9f0); line-height: 1.65; }
.three-piece-dialog-close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border: 1px solid rgba(151, 133, 220, .3); border-radius: 10px; color: #fff; background: rgba(7, 13, 43, .5); cursor: pointer; }

@media (max-width: 820px) {
  .three-piece-lobby { grid-template-columns: 1fr; max-width: 620px; }
  .three-piece-layout { grid-template-columns: minmax(0, 600px); }
  .three-piece-side { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 580px) {
  .three-piece-page { padding-inline: 0; }
  .three-piece-lobby { margin: 8px 0; padding: 20px; border-radius: 20px; }
  .three-piece-lobby-copy h2 { font-size: 28px; }
  .three-piece-room-bar { flex-wrap: wrap; margin-top: 0; }
  .three-piece-room-bar > div { width: 100%; }
  .three-piece-connection { margin-right: auto; }
  .three-piece-layout { min-width: 0; }
  .three-piece-board-shell { padding: 12px; border-radius: 18px; }
  .three-piece-board { border-radius: 14px; }
  .three-piece-token { font-size: clamp(42px, 20vw, 74px); }
  .three-piece-meta { grid-template-columns: 1fr auto; }
  .three-piece-meta strong { grid-column: 1 / -1; grid-row: 1; }
  .three-piece-side { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .three-piece-cell, .three-piece-token { transition: none !important; animation: none !important; }
}
