*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #000000;
  --surface: #1C1C1E;
  --surface2: #2C2C2E;
  --surface3: #3A3A3C;
  --surface4: #48484A;
  --text: #F5F5F7;
  --text2: #98989D;
  --text3: #6E6E73;
  --x: #0A84FF;
  --o: #FF453A;
  --mini-pad: 8px;
  --grid-pad: 12px;
  --tray-bg: #141416;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

input { font-family: inherit; }
input::placeholder { color: var(--text3); }
button { font-family: inherit; }

.hidden { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── TOP BAR ── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 26px;
  background: rgba(0,0,0,0.72);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: inset 0 -1px 0 rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.logo-grid-sm {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface);
}

.logo-grid-sm div { width: 5px; height: 5px; border-radius: 1.5px; }

.topbar-title {
  font-size: 15px;
  font-weight: 590;
  letter-spacing: -0.015em;
}

.topbar-account { display: flex; align-items: center; gap: 10px; min-width: 0; }

.signed-out-actions, .signed-in-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.btn-text {
  padding: 8px 16px;
  border-radius: 980px;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  transition: color 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-text:hover { color: var(--text); }

.btn-pill-primary {
  padding: 8px 16px;
  border-radius: 980px;
  background: var(--x);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 590;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-pill-primary:hover { background: #3A9BFF; }

.label-short { display: none; }

.rating-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 980px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
  flex-shrink: 0;
}

.dot-online { width: 6px; height: 6px; border-radius: 50%; background: #30D158; flex-shrink: 0; }

.account-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 13px 5px 5px;
  border-radius: 980px;
  background: var(--surface);
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  transition: background 0.2s;
  min-width: 0;
  flex-shrink: 1;
}
.account-chip:hover { background: #232325; }

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.avatar-lg { width: 44px; height: 44px; font-size: 17px; }

.account-chip-name {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30vw;
}

@media (max-width: 400px) {
  .label-full { display: none; }
  .label-short { display: inline; }
  #btn-signin { display: none; }
  .rating-chip { display: none; }
  .account-chip-name { max-width: 22vw; }
}

.app-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Screens ──
   The page itself never scrolls (see html/body above) — a screen whose
   content doesn't fit scrolls internally within its own box instead. */

.screen {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vw, 44px) clamp(12px, 2.5vw, 24px) clamp(20px, 4vw, 60px);
  overflow: hidden;
}

.screen.active { display: flex; }

.center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  width: 100%;
  max-width: 520px;
  transform-origin: center center;
}

/* ── HOME ── */

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.logo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.logo-grid div {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.home-hero h1 {
  font-size: clamp(38px, 8vw, 52px);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.02;
  text-align: center;
}

.home-hero p {
  max-width: 420px;
  text-align: center;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text2);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  border-radius: 20px;
  background: var(--surface);
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  transition: background 0.2s, transform 0.15s;
  user-select: none;
}

.mode-card:hover {
  background: #232325;
  transform: translateY(-1px);
}

.mode-card:active { transform: translateY(0); }

.mode-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  line-height: 1;
  flex-shrink: 0;
}

.mode-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.mode-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.mode-sub {
  font-size: 14px;
  color: var(--text2);
}

.mode-chevron {
  font-size: 20px;
  color: var(--surface4);
  line-height: 1;
}

/* ── SHARED: back button, header, cards ── */

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--text2);
  cursor: pointer;
  transition: color 0.2s;
  padding: 0;
}

.back-btn:hover { color: var(--text); }

.lobby-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.lobby-header h2 {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.lobby-header p {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text2);
}

.card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.card-label {
  font-size: 12px;
  font-weight: 590;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text3);
}

/* ── SETUP ── */

.setup-card { gap: 14px; padding: 22px; border-radius: 24px; }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.preset-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 15px;
  border-radius: 15px;
  cursor: pointer;
  transition: background 0.18s;
  background: #000;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
}

.preset-card.active {
  background: rgba(10,132,255,0.16);
  box-shadow: 0 0 0 1.5px rgba(10,132,255,0.6);
}

.preset-card-label { font-size: 15px; font-weight: 590; letter-spacing: -0.01em; }
.preset-card.active .preset-card-label { color: var(--x); }
.preset-card-detail { font-size: 12px; color: #8E8E93; }

.setup-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 4px 0; }

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

.setup-row-info { display: flex; flex-direction: column; gap: 2px; }
.setup-row-title { font-size: 15px; font-weight: 500; letter-spacing: -0.01em; }
.setup-row-detail { font-size: 12px; color: #8E8E93; }

.segmented {
  display: flex;
  background: #000;
  border-radius: 11px;
  padding: 2px;
}

.segmented-opt {
  padding: 7px 13px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s;
  background: transparent;
  color: #8E8E93;
  border: none;
}

.segmented-opt.active { background: var(--surface2); color: var(--text); }


.toggle {
  width: 51px;
  height: 31px;
  border-radius: 980px;
  padding: 2px;
  cursor: pointer;
  transition: background 0.22s;
  background: #39393D;
}
.toggle.on { background: #30D158; }

.toggle-knob {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  transition: transform 0.22s;
}
.toggle.on .toggle-knob { transform: translateX(20px); }

.btn-confirm {
  width: 100%;
  text-align: center;
  padding: 15px;
  border-radius: 16px;
  background: var(--x);
  border: none;
  color: #fff;
  font-size: 16px;
  font-weight: 590;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-confirm:hover { background: #3A9BFF; }

/* ── LOBBY ── */

.room-code {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: 16px;
  background: #000;
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text);
}

.card-actions {
  display: flex;
  gap: 10px;
}

.room-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
}

.room-wait-text {
  font-size: 13px;
  color: var(--text2);
}

.btn-secondary {
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface2);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  text-align: center;
}
.btn-secondary:hover { background: var(--surface3); }

.btn-secondary-block {
  width: 100%;
  text-align: center;
  padding: 13px;
  border-radius: 14px;
  background: var(--surface2);
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary-block:hover { background: var(--surface3); }
.btn-danger-text { color: var(--o); }

.btn-primary {
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  background: var(--x);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  text-align: center;
}
.btn-primary:hover { background: #3A9BFF; }

.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  color: var(--surface4);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

.join-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.join-input {
  flex: 1;
  padding: 14px 18px;
  border-radius: 16px;
  border: none;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  letter-spacing: 0.12em;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.btn-join {
  padding: 14px 22px;
  border-radius: 16px;
  background: var(--text);
  color: #000;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  border: none;
}
.btn-join:hover { opacity: 0.86; }

/* ── WAITING ── */

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.82); }
}

.pulse-dots { display: flex; gap: 8px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #30D158;
  animation: pulseDot 1.3s ease-in-out infinite;
}

.wait-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
}
.wait-title .nowrap { white-space: nowrap; }

.btn-cancel {
  padding: 11px 22px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  transition: background 0.2s;
}
.btn-cancel:hover { background: #232325; }

/* ── GAME LAYOUT ── */

.game-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1320px;
  flex: 1;
}

.game-layout {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 22px;
  width: 100%;
  transform-origin: center center;
}

.online-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(10px);
  border-radius: 28px;
}

.online-overlay-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.overlay-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.setup-join-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.game-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.result-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 12px 12px 12px 18px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  font-size: 16px;
  font-weight: 590;
  letter-spacing: -0.01em;
}
.result-banner.active { display: flex; }
.result-banner-rematch {
  flex: 0 0 auto;
  padding: 9px 18px;
  font-size: 14px;
}

.history-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 10px 10px 10px 16px;
  border-radius: 16px;
  background: rgba(255,159,10,0.14);
  box-shadow: 0 0 0 1px rgba(255,159,10,0.3);
  font-size: 13px;
  font-weight: 500;
  color: #FF9F0A;
}
.history-banner.active { display: flex; }
.history-live-btn { flex: 0 0 auto; padding: 7px 14px; font-size: 13px; }

.boards-grid.viewing-history { pointer-events: none; }

.game-hint {
  max-width: 440px;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text3);
}

.game-side {
  flex: 0 1 320px;
  width: 100%;
  max-width: 320px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 28px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
  overflow: hidden;
  align-self: center;
  min-height: min(640px, 72vh);
  min-height: min(640px, 72dvh);
  max-height: 82vh;
  max-height: 82dvh;
  background: var(--tray-bg);
}

/* ── BOARD ── */

.boards-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(6px, 1.4vw, 14px);
  padding: var(--grid-pad);
  background: var(--tray-bg);
  border-radius: clamp(20px, 3.4vw, 36px);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
  width: 100%;
  max-width: min(714px, calc(100vh - 215px));
  max-width: min(714px, calc(100dvh - 215px));
  transition: opacity 0.2s ease;
}

.boards-grid.not-your-turn {
  opacity: 0.5;
  pointer-events: none;
}

.mini-board {
  position: relative;
  padding: var(--mini-pad);
  border-radius: clamp(13px, 2.3vw, 24px);
  background: var(--surface);
  transition: opacity 0.25s, box-shadow 0.25s;
}

.cell-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(3px, 0.6vw, 6px);
}

.game-cell {
  aspect-ratio: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: clamp(7px, 1.4vw, 14px);
  font-size: clamp(14px, 3.4vw, 28px);
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background 0.18s, transform 0.12s, box-shadow 0.15s;
}

.game-cell:hover { transform: scale(1.06); }
.game-cell:active { transform: scale(0.94); }

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: clamp(13px, 2.3vw, 24px);
  pointer-events: none;
  font-size: clamp(30px, 10vw, 76px);
  font-weight: 300;
  line-height: 1;
  transition: opacity 0.3s;
  background: rgba(20, 20, 22, 0.88);
  opacity: 0;
}

.win-line {
  position: absolute;
  inset: var(--mini-pad);
  overflow: visible;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.win-line-path {
  fill: none;
  stroke-width: 0.13;
  stroke-linecap: round;
}

.win-line-main {
  inset: var(--grid-pad);
}

.win-line-main .win-line-path {
  stroke-width: 0.05;
}

/* ── CLOCK PANELS ── */

.clock-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  box-shadow: inset 0 -1px 0 rgba(255,255,255,0.06);
  flex-shrink: 0;
}
#panel-bottom.clock-panel { box-shadow: inset 0 1px 0 rgba(255,255,255,0.06); }

.clock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 16px;
  transition: background 0.2s, box-shadow 0.2s;
  background: var(--tray-bg);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
}

.clock-row.active {
  background: var(--surface);
  box-shadow: 0 0 0 1.5px var(--x);
}
.clock-row.active.o-turn { box-shadow: 0 0 0 1.5px var(--o); }

.clock-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.clock-mark { font-size: 16px; line-height: 1; }
.clock-who-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.clock-label {
  font-size: 14px;
  font-weight: 590;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clock-sub { font-size: 11px; color: #8E8E93; }
.clock-time {
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.move-bar-row { display: flex; align-items: center; gap: 10px; }
.move-bar-track {
  flex: 1;
  height: 4px;
  border-radius: 980px;
  background: rgba(0,0,0,0.55);
  overflow: hidden;
}
.move-bar-fill {
  height: 100%;
  border-radius: 980px;
  transition: width 0.12s linear, background 0.2s;
  background: var(--x);
}
.move-bar-label {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: #8E8E93;
  flex-shrink: 0;
}

/* ── SIDE TABS / MENU ── */

.side-tabs {
  display: flex;
  padding: 12px;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.side-tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 13px;
  border: none;
  background: transparent;
  color: #8E8E93;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  position: relative;
}
.side-tab.active { background: var(--surface2); color: var(--text); }

.menu-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  border: none;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.2s;
  background: transparent;
  color: #98989D;
}
.menu-btn:hover, .menu-btn.active { background: var(--surface2); }

.menu-panel { flex-shrink: 0; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 0 12px 12px;
}

.menu-item {
  text-align: center;
  padding: 11px;
  border-radius: 13px;
  background: var(--surface);
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.menu-item:hover { background: #232325; }
.menu-item:disabled { opacity: 0.4; cursor: default; }
.menu-item-danger { color: var(--o); }

.tab-badge {
  position: absolute;
  top: 2px;
  right: 8px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--o);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}

@keyframes tabPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
.side-tab.tab-pulse { animation: tabPulse 0.9s ease-in-out 2; }

/* ── REMATCH ── */

.rematch-request {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  margin: 0 12px 10px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}
.rematch-request.active { display: flex; }
.rematch-request-actions { display: flex; gap: 8px; flex-shrink: 0; }
.rematch-request-actions button { flex: none; padding: 7px 12px; font-size: 12px; }

/* ── CHAT / LOG ── */

.side-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.side-panel.active { display: flex; }

.log-list, .chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.chat-list { gap: 9px; padding: 8px 16px 16px; }
.log-list { padding: 2px 6px 12px; }

.log-entry {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  color: #E5E5EA;
}
.log-entry.log-highlight { background: rgba(48,209,88,0.12); font-weight: 500; }
.log-entry.log-clickable { cursor: pointer; transition: background 0.15s; }
.log-entry.log-clickable:hover { background: rgba(255,255,255,0.06); }
.log-entry.log-active { background: rgba(255,159,10,0.16); box-shadow: 0 0 0 1px rgba(255,159,10,0.35); }
.log-entry .log-n { width: 22px; flex: 0 0 22px; font-size: 12px; font-variant-numeric: tabular-nums; color: #6E6E73; }

.log-footer {
  padding: 12px;
  font-size: 11px;
  line-height: 1.5;
  color: #6E6E73;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.chat-bubble {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 88%;
  align-self: flex-start;
}
.chat-bubble.mine { align-self: flex-end; }

@keyframes chatBubbleIn {
  0% { opacity: 0; transform: translateY(10px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-bubble-new { animation: chatBubbleIn 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.chat-bubble-new .chat-bubble-text { animation: tabPulse 0.5s ease-in-out 1; }
.chat-bubble-text {
  padding: 10px 15px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  background: var(--surface);
  color: #E5E5EA;
  word-break: break-word;
}
.chat-bubble.mine .chat-bubble-text { background: var(--x); color: #fff; }
.chat-bubble-meta { font-size: 11px; color: #6E6E73; align-self: inherit; }

.chat-empty {
  color: var(--text3);
  font-size: 12.5px;
  text-align: center;
  margin: auto;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border-radius: 980px;
  border: none;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.btn-chat-send {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  border: none;
  background: var(--x);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-chat-send:hover { opacity: 0.86; }

/* ── ACCOUNT MODAL ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(14px);
}

.modal-card {
  width: 100%;
  max-width: 380px;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 26px;
  border-radius: 26px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 30px 70px rgba(0,0,0,0.6);
  transform-origin: center center;
}

.modal-header { display: flex; flex-direction: column; gap: 5px; }
.modal-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.modal-subtitle { font-size: 14px; line-height: 1.45; color: var(--text2); }

#notice-modal { z-index: 60; }
.notice-card { max-width: 340px; }

.account-auth-form { display: flex; flex-direction: column; gap: 10px; }

.modal-input {
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  outline: none;
  background: #000;
  color: var(--text);
  font-size: 15px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.07);
}

.auth-error {
  font-size: 13px;
  color: var(--o);
  line-height: 1.4;
}

.account-profile { display: flex; flex-direction: column; gap: 12px; }

.profile-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px;
  border-radius: 16px;
  background: #000;
}
.profile-info { display: flex; flex-direction: column; gap: 2px; }
.profile-name { font-size: 16px; font-weight: 590; letter-spacing: -0.01em; }
.profile-meta { font-size: 13px; color: #8E8E93; }

.stat-row { display: flex; gap: 8px; }
.stat-tile {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  border-radius: 16px;
  background: #000;
}
.stat-value { font-size: 19px; font-weight: 600; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: #8E8E93; }

.profile-follow-counts { font-size: 12.5px; color: #8E8E93; }

.follow-section { display: flex; flex-direction: column; gap: 10px; }

.search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.search-empty {
  padding: 10px 2px;
  font-size: 13px;
  color: var(--text3);
  text-align: center;
}

.search-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 14px;
  background: #000;
}

.search-result-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.search-result-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-rating { font-size: 12px; color: #8E8E93; }

.btn-follow {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 980px;
  border: none;
  background: var(--x);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, background 0.2s;
}
.btn-follow:hover { opacity: 0.86; }
.btn-follow.following { background: var(--surface2); color: var(--text); }
.btn-follow:disabled { opacity: 0.5; cursor: default; }

/* ── RESPONSIVE ── */

@media (max-width: 860px) {
  .game-layout { flex-direction: column; align-items: center; }
  .game-side { flex: 0 1 auto; min-height: 320px; max-height: none; height: 60vh; height: 60dvh; width: 100%; max-width: 480px; }
  /* Stacked layout gives the side panel far less room than desktop's
     tall column, and the two clock panels were eating most of it —
     leaving the chat/log list a sliver. Trim their padding here so the
     actual message/log list gets real space to breathe. */
  .clock-panel { padding: 8px 10px; gap: 5px; }
  .clock-row { padding: 7px 10px; }
  .move-bar-row { gap: 6px; }
}

@media (max-width: 520px) {
  :root { --mini-pad: 6px; --grid-pad: 9px; }
  .topbar { padding: 12px 16px; }
  .screen { padding: 20px 14px 28px; }
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
  .boards-grid { gap: 7px; border-radius: 22px; }
  .mini-board { border-radius: 15px; }
  .cell-grid { gap: 4px; }
  .game-cell { border-radius: 8px; }
  .board-overlay { border-radius: 15px; }
  .rematch-request { flex-direction: column; align-items: stretch; text-align: center; }
  .game-side { height: 56vh; height: 56dvh; }
  .clock-time { font-size: 18px; }

  /* A label plus a 4-5 option segmented control never both fit on one row
     at phone widths — stack them instead of letting the control overflow. */
  .setup-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .segmented { width: 100%; }
  .segmented-opt { flex: 1; padding: 7px 4px; font-size: 12px; text-align: center; }
}
