:root {
  --bg: #0b1220;
  --card: #121a2b;
  --text: #e8eefc;
  --muted: #9fb0d0;
  --accent: #6aa9ff;
  --danger: #ff5c7a;
  --border: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% 0%, rgba(106,169,255,0.18), transparent), var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.app { max-width: 1200px; margin: 0 auto; padding: 18px; }
.topbar { display:flex; justify-content: space-between; align-items:center; margin-bottom: 16px; }
.brand { font-weight: 800; letter-spacing: 0.3px; }
.me { color: var(--muted); font-size: 14px; }

.card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.hidden { display: none; }

.row { display:flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.col { flex: 1; min-width: 260px; }

label { display:flex; flex-direction: column; gap: 6px; margin: 10px 0; color: var(--muted); font-size: 14px; }
input, select {
  background: rgba(0,0,0,0.2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  outline: none;
}

.last-from { background-color: rgba(106,169,255,0.45) !important; }
.last-to   { background-color: rgba(50,169,255,0.45) !important; }

button {
  background: var(--accent);
  color: #0b1220;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
}
button.secondary { background: rgba(255,255,255,0.10); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #120012; }

.status { margin-top: 10px; color: var(--muted); min-height: 20px; }
.error { margin-top: 10px; color: var(--danger); min-height: 20px; }

.gameHeader { display:flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.matchMeta { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.clocks { display:flex; gap: 10px; }
.clock { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: rgba(0,0,0,0.2); }
.clock.active { outline: 2px solid rgba(106,169,255,0.65); }

.boards { display:flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.boardWrap { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: rgba(0,0,0,0.16); }
.boardTitle { font-weight: 800; margin-bottom: 6px; }
.turnIndicator { color: var(--muted); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.board { width: 306px; }
.boardWrap.active { outline: 2px solid rgba(106,169,255,0.65); }
.boardWrap.finished { opacity: 0.7; }

/* allow overlay positioning */
.square-55d63 { position: relative; }
 
/* show a small number on squares that have data-piece-num */
.square-55d63 { position: relative; }
 
.premove-from { outline: 4px solid rgba(0, 255, 0, 0.95) !important; outline-offset: -4px !important; }
.premove-to   { outline: 4px solid rgba(0, 160, 0, 0.95) !important; outline-offset: -4px !important; }
 
.square-55d63[data-piece-num]::after {
  content: attr(data-piece-num);
  position: absolute;
  top: 2px;
  right: 2px;
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 5;
 
  /* white number with black border */
  color: #fff;
  -webkit-text-stroke: 1.5px #000;
  text-stroke: 1.5px #000;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
 

#rotateHint {
  display: none;
  padding: 16px;
  margin: 12px;
  border-radius: 12px;
  background: #1b2433;
  color: #fff;
}
 
/* position depends on the piece color */
.square-55d63[data-piece-color="w"][data-piece-num]::after {
  top: auto;
  bottom: 2px;   /* white side (bottom) */
  right: 2px;
}
 
.square-55d63[data-piece-color="b"][data-piece-num]::after {
  top: 2px;      /* black side (top) */
  right: 2px;
}

@media (max-width: 980px) {
  .board { width: 272px; }
}

/* hidden by default */
#rotateHint { display: none; }
 

html, body { height: 100%; overscroll-behavior: none; }
 
body.in-game {
  position: fixed;
  left: 0;
  right: 0;
  overflow: hidden;
  width: 100%;
  touch-action: none; /* prevents scroll gestures */
}


/* =========================
   Mobile behavior (final)
   ========================= */
html, body { height: 100%; overscroll-behavior: none; }
 
/* While in game, lock scrolling (mobile) */
body.in-game {
  position: fixed;
  left: 0; right: 0;
  width: 100%;
  overflow: hidden;
  touch-action: none;
}
 
/* Rotate hint hidden by default */
#rotateHint { display: none; }
 
/* Portrait on touch devices: hide boards, show rotate hint */
@media (pointer: coarse) and (max-width: 900px) and (orientation: portrait) {
  #gameCard .boards { display: none !important; }
  #rotateHint { display: block !important; }
}
 
/* Landscape on touch devices: compact header + 1-line clocks + 3 boards */
@media (pointer: coarse) and (max-width: 900px) and (orientation: landscape) {
  /* Hide non-essential stuff */
  .topbar { display: none !important; }
  #matchMeta { display: none !important; }
  .turnIndicator { display: none !important; }
  #gameStatus { display: none !important; }
  .boardTitle { display: none !important; }
  #rotateHint { display: none !important; }
 
  /* Reduce padding to fit */
  .app { max-width: none; width: 100vw; padding: 6px; }
  .card { padding: 10px; margin-bottom: 10px; }
 
  /* Critical: prevent the header from wrapping */
  .gameHeader {
    display: grid !important;
    grid-template-columns: 1fr auto !important;  /* left: clocks, right: buttons */
    align-items: center !important;
    gap: 8px !important;
  }
 
  /* One line: Active | Black | White */
  .clocks {
    display: grid !important;
    grid-template-columns: auto 1fr 1fr !important;
    gap: 6px !important;
    align-items: center !important;
    min-width: 0 !important;
  }
 
  .activeBoard,
  .clock {
    padding: 2px 8px !important;     /* shorter */
    font-size: 14px !important;
    line-height: 1.1 !important;
    white-space: nowrap !important;
    min-width: 0 !important;
  }
 
  .clock {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
 
  /* Buttons in one row */
  .gameActions {
    display: grid !important;
    grid-template-columns: auto auto !important;
    gap: 8px !important;
    justify-content: end !important;
    white-space: nowrap !important;
  }
 
  .gameActions button {
    padding: 6px 10px !important;
    font-size: 14px !important;
    white-space: nowrap !important;
  }
 
  /* Boards always 3 in a row */
  #gameCard .boards {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    width: 100% !important;
    margin-top: 8px !important;
  }
 
  #gameCard .boardWrap { min-width: 0 !important; padding: 6px !important; }
  #gameCard .board { width: 100% !important; max-width: 100% !important; }
}

.landscapePopup.hidden { display: none; }
 
.landscapePopup {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.landscapePopupCard {
  border: 2px solid rgba(22, 163, 74, 0.9);
  background: rgba(18, 26, 43, 0.95);
  border-radius: 16px;
  padding: 18px 16px;
  width: min(320px, 86vw);
  text-align: center;
}
 
.landscapePopupTitle {
  color: #16a34a;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.6px;
  margin-bottom: 12px;
}
 
.landscapePopupIcon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #16a34a;
  font-weight: 900;
  font-size: 22px;
}
 
.phonePortrait, .phoneLandscape {
  border: 2px solid #22c55e;
  border-radius: 8px;
  background: rgba(22, 163, 74, 0.14);
}
 
.phonePortrait { width: 28px; height: 52px; }
.phoneLandscape { width: 52px; height: 28px; }
 
@media (pointer: coarse) and (max-width: 900px) and (orientation: portrait) {
  #landscapePopup { display: flex; }
}