:root {
  --bg: #fdf0d5;
  --bg-deep: #f5e4c4;
  --panel: #ffffff;
  --panel-2: #f7ebd0;
  --text: #2c2416;
  --muted: #7a6a52;
  --accent: #249d8f;
  --accent-2: #1a7a6f;
  --gold: #e9c46a;
  --coral: #e76f51;
  --border: rgba(36, 157, 143, 0.35);
  --ok: #249d8f;
  --danger: #e76f51;
  --sq-light: #f3e2b8;
  --sq-dark: #2a9d8f;
  --sq-last: rgba(233, 196, 106, 0.55);
  --sq-select: rgba(44, 36, 22, 0.22);
  --sq-check: rgba(231, 111, 81, 0.55);
  --move-dot: rgba(44, 36, 22, 0.28);
  --piece-w-fill: #fff8ef;
  --piece-w-stroke: #2c2416;
  --piece-b-fill: #2c2416;
  --piece-b-stroke: #14110c;
  --board-rim: #1a7a6f;
  --radius: 16px;
  --shadow:
    0 1px 0 rgba(255, 255, 255, 0.85) inset,
    0 10px 30px rgba(36, 157, 143, 0.12),
    0 2px 8px rgba(44, 36, 22, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    system-ui, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html { background-color: var(--bg-deep); }
body {
  line-height: 1.4;
  background-color: var(--bg-deep);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 12px 28px;
}

header.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 14px;
}

.nav-home {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

header.hero h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
  letter-spacing: -0.02em;
  font-weight: 750;
}

header.hero .sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.hero-auth {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hidden { display: none !important; }

.lobby {
  max-width: 640px;
  margin: 0 auto 18px;
  padding: 22px 22px 20px;
}

.lobby-kicker {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #c9543a;
}

.lobby h2 {
  margin: 0 0 8px;
  font-family: "Waukegan LDO", "Eurostile", "Arial Narrow", system-ui, sans-serif;
  font-size: 1.45rem;
}

.lobby-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.lobby-auth {
  margin: 16px 0 12px;
}

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.lobby-actions button {
  font-size: 1.08rem !important;
  padding: 12px 20px !important;
  min-height: 48px;
}

.join-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.join-form input {
  width: 12.5rem;
  min-width: 12.5rem;
  border: 3px solid #2c2416;
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: #fffbf3;
  color: var(--text);
  min-height: 48px;
}

.lobby-note {
  min-height: 1.2em;
  margin: 12px 0 0;
  color: var(--coral);
  font-weight: 700;
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.play-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.table-stage {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.seat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: #fffbf3;
  border: 3px solid #2c2416;
  border-radius: 18px;
  box-shadow: 4px 4px 0 #2c2416;
  min-height: 72px;
}

.seat.to-move {
  box-shadow: 4px 4px 0 var(--accent);
}

.seat .avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #2c2416;
  background: var(--panel-2);
  flex-shrink: 0;
}

.seat .avatar.placeholder {
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  color: #fff;
  background: linear-gradient(180deg, #3db5a3, var(--accent-2));
}

.seat.far .avatar.placeholder {
  background: linear-gradient(180deg, #f08a70, var(--coral));
}

.seat-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  color: inherit;
  text-decoration: none;
}

a.seat-profile:hover .seat-name {
  color: var(--accent-2);
  text-decoration: underline;
}

.seat-meta {
  min-width: 0;
  flex: 1;
}

.seat-name {
  font-weight: 800;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-color {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.captured {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0;
  max-width: 46%;
}

.captured .mini-piece {
  width: 18px;
  height: 18px;
  margin-left: -4px;
  object-fit: contain;
  pointer-events: none;
}

.seat-flag {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  border: 2px solid #2c2416;
  background: var(--gold);
  color: #2c2416;
  flex-shrink: 0;
}

.seat-flag.wait {
  background: #fff;
  color: var(--muted);
}

.board-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 10px;
  background: var(--board-rim);
  border: 3px solid #2c2416;
  border-radius: 18px;
  box-shadow: 5px 5px 0 #2c2416;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
}

button.sq {
  position: relative;
  border: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0;
  box-shadow: none !important;
  background: var(--sq-light) !important;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

button.sq.dark {
  background: var(--sq-dark) !important;
}

button.sq.last {
  box-shadow: inset 0 0 0 999px var(--sq-last) !important;
}

button.sq.selected {
  box-shadow: inset 0 0 0 999px var(--sq-select) !important;
}

button.sq.check {
  box-shadow: inset 0 0 0 999px var(--sq-check) !important;
}

button.sq:focus-visible {
  outline: 3px solid #2c2416;
  outline-offset: -3px;
  z-index: 2;
}

.coord {
  position: absolute;
  font-size: clamp(0.55rem, 1.8vw, 0.72rem);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  opacity: 0.72;
}

.coord.file {
  right: 3px;
  bottom: 3px;
}

.coord.rank {
  left: 3px;
  top: 3px;
}

button.sq.dark .coord { color: var(--sq-light); }
button.sq:not(.dark) .coord { color: var(--accent-2); }

.piece {
  display: block;
  width: 88%;
  height: 88%;
  margin: 6% auto 0;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 0 rgba(44, 36, 22, 0.18));
}

.piece.dragging {
  opacity: 0.35;
}

.move-dot,
.move-cap {
  position: absolute;
  pointer-events: none;
  z-index: 1;
}

.move-dot {
  width: 28%;
  height: 28%;
  left: 36%;
  top: 36%;
  border-radius: 50%;
  background: var(--move-dot);
}

.move-cap {
  inset: 6%;
  border-radius: 50%;
  border: 4px solid var(--move-dot);
}

.ghost-piece {
  position: fixed;
  pointer-events: none;
  z-index: 40;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 8px 12px rgba(44, 36, 22, 0.28));
}

.ghost-piece .piece {
  width: 100%;
  height: 100%;
  margin: 0;
}

.promo-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8%;
  background: rgba(44, 36, 22, 0.28);
}

.promo-overlay.bottom {
  align-items: flex-end;
}

.promo-list {
  display: flex;
  flex-direction: column;
  background: #fffbf3;
  border: 3px solid #2c2416;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 4px 4px 0 #2c2416;
}

.promo-list button {
  width: 64px;
  height: 64px;
  border: 0 !important;
  border-radius: 0 !important;
  background: #fffbf3 !important;
  box-shadow: none !important;
  padding: 4px !important;
}

.promo-list .piece {
  width: 100%;
  height: 100%;
  margin: 0;
}

.promo-list button:hover {
  background: #f3e2b8 !important;
  transform: none !important;
}

.wait-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(253, 240, 213, 0.72);
  backdrop-filter: blur(3px);
}

.wait-card {
  text-align: center;
  background: #fffbf3;
  border: 3px solid #2c2416;
  border-radius: 16px;
  padding: 16px 22px;
  box-shadow: 4px 4px 0 #2c2416;
  max-width: 340px;
}

.wait-kicker {
  margin: 0 0 6px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--muted);
}

.wait-code {
  margin: 0 0 12px;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  padding-right: 0.16em;
}

.wait-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wait-actions button {
  width: 100%;
}

#btn-share-x,
#btn-share-x-win,
#btn-share-wait,
.btn-x-share {
  background: linear-gradient(180deg, var(--gold) 0%, #d4a84a 100%) !important;
  border-color: color-mix(in srgb, var(--gold) 60%, #8a6a20) !important;
  color: #2c2416 !important;
  font-weight: 800;
}

.wait-hint {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.status {
  text-align: center;
  font-weight: 800;
  min-height: 1.3em;
  margin-top: 4px;
}

.status.check { color: var(--coral); }

.table-stage .btn-row {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  width: 100%;
  gap: 10px;
}

.table-stage .btn-row-line {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  width: 100%;
}

.table-stage .btn-row-line button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  font-size: 1.05rem !important;
  padding: 12px 16px !important;
}

.side-panel {
  padding: 16px 16px 18px;
}

.side-panel h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.howto {
  margin: 0 0 16px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.howto li { margin: 0 0 6px; }

.label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.invite-box,
.moves-box {
  margin-top: 12px;
}

.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.invite-row strong {
  font-size: 1.15rem;
  letter-spacing: 0.12em;
}

.move-list {
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 0 0 0 22px;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.auth-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.auth-chip img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #2c2416;
  object-fit: cover;
}

.auth-chip .name { font-weight: 800; font-size: 0.9rem; }

html.night-mode {
  --sq-light: #2a3548;
  --sq-dark: #1e2a38;
  --sq-last: rgba(201, 176, 122, 0.38);
  --sq-select: rgba(107, 181, 168, 0.32);
  --sq-check: rgba(212, 137, 114, 0.5);
  --move-dot: rgba(232, 226, 214, 0.35);
  --piece-w-fill: #efe8dc;
  --piece-w-stroke: #12161f;
  --piece-b-fill: #12161f;
  --piece-b-stroke: #8fcec4;
  --board-rim: #243040;
}

html.night-mode .seat,
html.night-mode .board-shell,
html.night-mode .wait-card,
html.night-mode .promo-list,
html.night-mode .join-form input {
  background: var(--panel-solid, #262c3d);
  border-color: #8fcec4;
  box-shadow: 4px 4px 0 #12161f;
}

html.night-mode .seat .avatar,
html.night-mode .auth-chip img {
  border-color: #8fcec4;
}
