/* Connect Four: one-screen play area, themed to match rtwl.fun (body.fx). */
html:has(body.c4-page), body.c4-page {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  color-scheme: dark;
}
body.c4-page {
  min-height: 0;
  touch-action: manipulation;
}

body.c4-page .game-wrap {
  width: min(1180px, calc(100% - 16px));
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: max(6px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  box-sizing: border-box;
}

/* ---- header ---- */
.c4-top {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-shrink: 0;
  min-height: 0;
}
.c4-top .back {
  margin: 0;
  flex-shrink: 0;
  color: var(--fx-neon, #3dff8a);
  font-size: 0.92rem;
}
body.c4-page .c4-top .gg-head {
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
}
body.c4-page .c4-top h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2.2vw + 0.4rem, 1.75rem);
  line-height: 1.1;
  filter: drop-shadow(0 0 12px rgba(25, 193, 85, 0.4));
}
body.c4-page .gg-links a,
body.c4-page .c4-boards-btn,
body.c4-page .c4-boards-close {
  font-weight: 600;
  color: var(--fx-text, #e6fff0);
  text-decoration: none;
  padding: 4px 12px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--fx-edge, rgba(61, 255, 138, 0.24));
  border-radius: 999px;
  background: rgba(25, 193, 85, 0.08);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
body.c4-page .gg-links a:hover,
body.c4-page .gg-links a:focus-visible,
body.c4-page .c4-boards-btn:hover,
body.c4-page .c4-boards-close:hover {
  background: rgba(25, 193, 85, 0.16);
  border-color: var(--fx-neon, #3dff8a);
  outline: none;
}
body.c4-page .c4-boards-btn,
body.c4-page .c4-boards-close { display: none; }
body.c4-page .c4-boards-close { font-size: 0.9rem; }
.c4-boards-mask { display: none; }

.c4-boards-check {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

/* ---- setup / controls ---- */
body.c4-page .setup {
  flex-shrink: 0;
  margin: 0;
  padding: 8px 12px;
}
body.c4-page .setup .row {
  flex-wrap: nowrap;
  gap: 8px 10px;
  align-items: flex-end;
}
body.c4-page .setup .row > * { flex: 1 1 0; min-width: 0; }
body.c4-page .setup .row > .btn { flex: 0 0 auto; }
body.c4-page .setup .field { margin-bottom: 0; color: var(--fx-neon, #3dff8a); font-size: 0.72rem; letter-spacing: 0.1em; }
body.c4-page input[type=text],
body.c4-page select {
  margin-top: 3px;
  padding: 6px 10px;
  color: var(--fx-text, #e6fff0);
  background: rgba(3, 15, 9, 0.72);
  border: 1px solid rgba(61, 255, 138, 0.3);
  border-radius: 12px;
}
body.c4-page input::placeholder { color: #7fae96; }
body.c4-page input:focus,
body.c4-page select:focus {
  outline: 2px solid var(--fx-neon, #3dff8a);
  outline-offset: 1px;
  border-color: var(--fx-neon, #3dff8a);
}
body.c4-page .btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #3dff8a, #19c155);
  color: #03140b;
  box-shadow: 0 0 18px rgba(25, 193, 85, 0.45);
}
body.c4-page .btn:active { transform: translateY(1px); box-shadow: 0 0 10px rgba(25, 193, 85, 0.35); }
body.c4-page .btn.ghost {
  background: rgba(25, 193, 85, 0.08);
  color: var(--fx-text, #e6fff0);
  box-shadow: none;
  border: 1px solid var(--fx-edge, rgba(61, 255, 138, 0.24));
}
body.c4-page .btn:disabled { opacity: .5; cursor: default; }

/* ---- play + scores layout ---- */
.c4-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 10px;
  align-items: stretch;
}
.c4-play {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 8px 12px 10px;
}
body.c4-page .c4-side {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.c4-page .c4-side > .panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.c4-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
body.c4-page .c4-side h3 {
  color: #fff;
  text-shadow: 0 0 14px rgba(25, 193, 85, 0.35);
  margin: 0 0 8px;
  font-size: 1.15rem;
}
.c4-board-table { font-size: 0.9rem; overflow: auto; min-height: 0; flex: 0 1 auto; }
body.c4-page .c4-rules {
  font-size: 0.8rem;
  line-height: 1.35;
  margin: 10px 0 0;
  color: var(--fx-dim, #a6d8bb);
}
body.c4-page .tab {
  background: rgba(3, 15, 9, 0.55);
  color: var(--fx-dim, #a6d8bb);
  border-color: var(--fx-edge, rgba(61, 255, 138, 0.24));
  padding: 4px 10px;
}
body.c4-page .tab.on {
  background: rgba(25, 193, 85, 0.16);
  color: #7dffb0;
  border-color: var(--fx-neon, #3dff8a);
}
body.c4-page .muted { color: var(--fx-dim, #a6d8bb); }
body.c4-page .msg { color: #7dffb0; margin: 4px 0 0; min-height: 1.15em; font-size: 0.95rem; }
body.c4-page .msg.bad { color: #ffb4ab; }

/* ---- hud, board, status ---- */
.hud {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.hud .k {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fx-neon, #3dff8a);
  font-weight: 600;
}
.hud .v {
  font-family: Chango, Georgia, serif;
  font-size: clamp(1.05rem, 2.2vh, 1.5rem);
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.c4-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  place-items: center;
  container-type: size;
}
.c4-stage {
  /* Cap width so a 7x6 board plus column heads stays inside the remaining height. */
  width: min(100cqw, calc(100cqh * 7 / 6.85), calc(100cqh - 8px));
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(2px, 0.8cqi, 6px);
  min-height: 0;
}
@supports not (container-type: size) {
  .c4-stage { width: min(100%, 70vw, calc((100dvh - 14rem) * 7 / 6.85)); }
}

.c4-heads {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(3px, 0.9cqi, 8px);
  padding: 0 clamp(4px, 1.2cqi, 10px);
  margin: 0;
  height: clamp(22px, 8cqi, 36px);
  flex: 0 0 auto;
}
.c4-head {
  height: 100%;
  min-height: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  color: var(--fx-neon, #3dff8a);
  padding: 0;
}
.c4-head:hover:not(:disabled)::before { content: '▼'; filter: drop-shadow(0 0 6px var(--fx-neon, #3dff8a)); }
.c4-head:disabled { cursor: default; opacity: 0.4; }
.c4-head:focus-visible { outline: 3px solid var(--fx-neon, #3dff8a); outline-offset: 1px; }

.c4-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: clamp(3px, 0.9cqi, 8px);
  padding: clamp(4px, 1.2cqi, 10px);
  width: 100%;
  flex: 0 0 auto;
  background: linear-gradient(180deg, #128a3e 0%, #0e7a36 40%, #052e18 100%);
  border-radius: 18px;
  border: 1px solid var(--fx-edge, rgba(61, 255, 138, 0.24));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 0 24px rgba(25, 193, 85, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.c4-cell {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  border-radius: 50%;
  background: #04150d;
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(61, 255, 138, 0.12);
  position: relative;
}
.c4-cell.r::after, .c4-cell.y::after {
  content: '';
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  animation: drop .28s ease-in;
}
.c4-cell.r::after {
  background: radial-gradient(circle at 35% 30%, #ff8a80, #d92d20 70%);
  box-shadow: 0 0 10px rgba(217, 45, 32, 0.45);
}
.c4-cell.y::after {
  background: radial-gradient(circle at 35% 30%, #ffe27a, #f0b400 70%);
  box-shadow: 0 0 10px rgba(240, 180, 0, 0.4);
}
.c4-cell.win {
  box-shadow: 0 0 0 3px #04150d, 0 0 0 6px #3dff8a, 0 0 14px #3dff8a;
  z-index: 1;
}
@keyframes drop { from { transform: translateY(-260%); } to { transform: none; } }

.c4-foot { flex-shrink: 0; text-align: center; }
.status-line {
  text-align: center;
  font-weight: 600;
  font-size: clamp(0.92rem, 1.8vh, 1.1rem);
  margin: 6px 0 0;
  min-height: 1.3em;
  color: #fff;
}
.quip {
  text-align: center;
  margin: 0;
  min-height: 1.2em;
  color: var(--fx-dim, #a6d8bb);
  font-style: italic;
  font-size: 0.92rem;
}
.tools { justify-content: center; margin-top: 4px; }
.tools .btn { flex: 0 1 auto; }

/* Chat FAB sits over the scores column on wide screens; nudge it in a little. */
@media (min-width: 800px) {
  body.c4-page .ggc-fab { right: 20px; }
}

/* ---- compact / phone ---- */
@media (max-width: 799px), (orientation: portrait) and (max-width: 899px) {
  .c4-layout { grid-template-columns: 1fr; }
  body.c4-page .c4-boards-btn { display: inline-flex; }
  body.c4-page .c4-side {
    display: none;
    position: fixed;
    inset: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
    z-index: 90;
    max-width: 420px;
    margin: 0 auto;
    overflow: hidden;
  }
  body.c4-page .c4-side > .panel {
    background: linear-gradient(160deg, rgba(10, 46, 28, 0.98), rgba(3, 15, 9, 0.98) 55%);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7), 0 0 30px rgba(25, 193, 85, 0.25);
  }
  #c4-show-boards:checked ~ .c4-boards-mask {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(0, 0, 0, 0.62);
    cursor: pointer;
  }
  body.c4-page .c4-boards-close { display: inline-flex; }
  #c4-show-boards:checked ~ .c4-layout .c4-side { display: flex; }
  #c4-show-boards:checked ~ .c4-top .c4-boards-btn { border-color: var(--fx-neon, #3dff8a); background: rgba(25, 193, 85, 0.2); }
}
@media (max-width: 640px) {
  .back-full { display: none; }
  body.c4-page .setup .row { flex-wrap: wrap; }
  body.c4-page .setup .row > * { flex: 1 1 calc(50% - 10px); }
  body.c4-page .setup .row > .field:nth-child(3) { flex: 1 1 52%; }
  body.c4-page .setup .row > .btn { flex: 1 1 36%; }
  body.c4-page .c4-top { flex-wrap: wrap; gap: 4px 8px; }
  body.c4-page .c4-top .gg-head { display: contents; }
  body.c4-page .c4-top h1 { font-size: 1.12rem; flex: 1 1 auto; min-width: 0; }
  body.c4-page .c4-top .gg-links { width: 100%; justify-content: center; flex-wrap: nowrap; gap: 6px; }
  body.c4-page .gg-links a, body.c4-page .c4-boards-btn { min-height: 30px; padding: 3px 10px; font-size: 0.88rem; }
  body.c4-page .game-wrap { width: calc(100% - 12px); gap: 6px; }
}
@media (max-height: 520px) {
  body.c4-page .game-wrap { padding-top: 4px; padding-bottom: 4px; gap: 4px; }
  body.c4-page .setup { padding: 4px 10px; }
  body.c4-page .setup .field { font-size: 0; letter-spacing: 0; }
  body.c4-page .setup input, body.c4-page .setup select { padding: 4px 8px; font-size: 0.88rem; letter-spacing: 0; text-transform: none; }
  .hud { margin-bottom: 2px; }
  .hud .v { font-size: 1rem; }
  .quip { display: none; }
  .c4-rules { display: none; }
  .status-line { margin-top: 2px; font-size: 0.88rem; }
  body.c4-page .c4-top h1 { font-size: 1.05rem; }
  body.c4-page .c4-play { padding: 4px 8px 6px; }
  body.c4-page .btn { padding: 6px 12px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  body.c4-page .setup .row { flex-wrap: nowrap; }
  body.c4-page .setup .row > * { flex: 1 1 0; }
  body.c4-page .setup .row > .btn { flex: 0 0 auto; }
  .c4-layout { grid-template-columns: minmax(0, 1fr) minmax(180px, 230px); }
  body.c4-page .c4-side {
    display: flex;
    position: static;
    inset: auto;
    max-width: none;
    margin: 0;
  }
  body.c4-page .c4-boards-btn,
  body.c4-page .c4-boards-close { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .c4-cell.r::after, .c4-cell.y::after { animation: none; }
  body.c4-page .btn:active { transform: none; }
}
