/* Cogwork Arcade: brass, copper, walnut and a little steam. */

@font-face {
  font-family: 'Rye';
  src: url('/fonts/rye.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English SC';
  src: url('/fonts/im-fell-english-sc.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'Special Elite';
  src: url('/fonts/special-elite.woff2') format('woff2');
  font-display: swap;
}

:root {
  --walnut-0: #120b06;
  --walnut-1: #1d130b;
  --walnut-2: #2a1c10;
  --iron: #2b2622;
  --iron-light: #3a332d;
  --brass-hi: #f6dc8e;
  --brass: #d4a93a;
  --brass-mid: #a87c22;
  --brass-lo: #6b4c14;
  --copper: #c9683c;
  --verdigris: #45c0aa;
  --parchment: #f3e6c8;
  --parchment-dim: #c9b891;
  --ink: #23170c;
  --danger: #e2553f;
  --s0: #e9b93f;
  --s1: #dd6f3f;
  --s2: #45c0aa;
  --font-display: 'Rye', 'Copperplate', 'Georgia', serif;
  --font-head: 'IM Fell English SC', 'Copperplate', 'Georgia', serif;
  --font-body: 'Special Elite', 'Courier New', ui-monospace, monospace;
  --cell: clamp(34px, calc((100vw - 92px) / 7), 62px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  background-color: var(--walnut-0);
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(214, 150, 60, 0.28), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(69, 192, 170, 0.10), transparent 55%),
    repeating-linear-gradient(92deg, rgba(255, 220, 160, 0.025) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, var(--walnut-2), var(--walnut-0));
  background-attachment: fixed;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

a { color: var(--brass-hi); }

/* ---- spinning gears in the background ---- */

.gears {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.gear {
  position: absolute;
  opacity: 0.16;
  animation: spin 40s linear infinite;
}
.gear path { fill: var(--brass); }
.gear.copper path { fill: var(--copper); }
.gear.rev { animation-direction: reverse; }
.gear.g1 { width: 340px; height: 340px; top: -110px; left: -100px; animation-duration: 60s; }
.gear.g2 { width: 190px; height: 190px; top: 150px; left: 172px; animation-duration: 33.5s; }
.gear.g3 { width: 420px; height: 420px; bottom: -170px; right: -140px; animation-duration: 80s; }
.gear.g4 { width: 170px; height: 170px; bottom: 185px; right: 190px; animation-duration: 32.4s; }
.gear.g5 { width: 120px; height: 120px; top: 34%; right: -40px; animation-duration: 24s; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- layout ---- */

.wrap {
  position: relative;
  z-index: 1;
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 18px 16px 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.logo {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.05;
  margin: 0;
  color: var(--brass-hi);
  background: linear-gradient(180deg, #fff3c4 0%, var(--brass) 45%, var(--brass-lo) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.75)) drop-shadow(0 0 18px rgba(232, 170, 60, 0.25));
  text-decoration: none;
}
.logo.big { font-size: clamp(2.5rem, 9vw, 5rem); }
.logo.small { font-size: 1.55rem; }

.room-tag {
  font-family: var(--font-head);
  font-size: 1.05rem;
  color: var(--parchment-dim);
  padding: 6px 14px;
  border: 2px solid var(--brass-mid);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--iron-light), var(--iron));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 2px 6px rgba(0, 0, 0, 0.5);
}
.room-tag strong {
  font-family: var(--font-body);
  font-weight: 400;
  letter-spacing: 0.22em;
  color: var(--brass-hi);
  margin-left: 6px;
}

/* A riveted brass plate. */
.plate {
  position: relative;
  padding: 22px 22px 24px;
  border-radius: 14px;
  border: 3px solid transparent;
  background:
    linear-gradient(180deg, rgba(58, 51, 45, 0.97), rgba(33, 28, 24, 0.97)) padding-box,
    linear-gradient(135deg, var(--brass-hi), var(--brass-mid) 30%, var(--brass-lo) 55%, var(--brass) 80%, var(--brass-hi)) border-box;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}
.plate::before,
.plate::after {
  content: '';
  position: absolute;
  left: 9px;
  right: 9px;
  height: 9px;
  pointer-events: none;
  background:
    radial-gradient(circle at 4.5px 4.5px, var(--brass-hi) 0 1.5px, var(--brass-mid) 1.6px 3.6px, rgba(0, 0, 0, 0.55) 3.7px 4.5px, transparent 4.6px) left / 9px 9px no-repeat,
    radial-gradient(circle at 4.5px 4.5px, var(--brass-hi) 0 1.5px, var(--brass-mid) 1.6px 3.6px, rgba(0, 0, 0, 0.55) 3.7px 4.5px, transparent 4.6px) right / 9px 9px no-repeat;
}
.plate::before { top: 9px; }
.plate::after { bottom: 9px; }

h2 {
  font-family: var(--font-head);
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
  color: var(--brass-hi);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7);
}
h3 {
  font-family: var(--font-head);
  font-weight: 400;
  font-size: 1.3rem;
  margin: 0 0 6px;
  color: var(--brass-hi);
}

p { margin: 0 0 12px; }
.hint { color: var(--parchment-dim); font-size: 0.92rem; }

/* ---- buttons and fields ---- */

.btn {
  appearance: none;
  font-family: var(--font-head);
  font-size: 1.08rem;
  letter-spacing: 0.05em;
  color: var(--ink);
  padding: 9px 20px 8px;
  border-radius: 999px;
  border: 2px solid var(--brass-lo);
  background: linear-gradient(180deg, #ffe9a6 0%, var(--brass) 42%, var(--brass-mid) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), inset 0 -3px 0 rgba(80, 50, 10, 0.35), 0 4px 0 #3d2a0b, 0 8px 14px rgba(0, 0, 0, 0.45);
  text-shadow: 0 1px 0 rgba(255, 245, 200, 0.7);
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease, filter 0.15s ease;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 -2px 0 rgba(80, 50, 10, 0.35), 0 1px 0 #3d2a0b, 0 3px 6px rgba(0, 0, 0, 0.45);
}
.btn:focus-visible, input:focus-visible, .col:focus-visible, a:focus-visible {
  outline: 3px solid var(--verdigris);
  outline-offset: 3px;
}
.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.75) brightness(0.62);
}
.btn.big { font-size: 1.45rem; padding: 14px 34px 12px; }
.btn.copper {
  color: #fff3e6;
  border-color: #5a2410;
  background: linear-gradient(180deg, #f0a37c 0%, var(--copper) 45%, #8f3f1e 100%);
  text-shadow: 0 1px 0 rgba(60, 20, 0, 0.8);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -3px 0 rgba(60, 20, 0, 0.35), 0 4px 0 #3b170a, 0 8px 14px rgba(0, 0, 0, 0.45);
}
.btn.ghost {
  color: var(--parchment);
  border-color: var(--brass-mid);
  background: linear-gradient(180deg, var(--iron-light), var(--iron));
  text-shadow: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 0 #0e0a07, 0 8px 14px rgba(0, 0, 0, 0.45);
}

input[type='text'] {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: linear-gradient(180deg, #e6d6ae, var(--parchment));
  border: 2px solid var(--brass-lo);
  border-radius: 8px;
  padding: 9px 12px 7px;
  min-width: 0;
  box-shadow: inset 0 2px 5px rgba(60, 40, 10, 0.4);
}
label {
  font-family: var(--font-head);
  color: var(--parchment-dim);
  letter-spacing: 0.04em;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row > input { flex: 1 1 160px; }

/* ---- home ---- */

.hero { text-align: center; padding: 40px 22px 34px; }
.hero .tagline {
  font-family: var(--font-head);
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  color: var(--parchment);
  margin: 14px auto 26px;
  max-width: 34ch;
}
.hero .hint { margin-top: 18px; }
.divider {
  height: 2px;
  margin: 26px auto;
  max-width: 420px;
  background: linear-gradient(90deg, transparent, var(--brass-mid), transparent);
}
.join {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.join input {
  width: 9.5ch;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 1.15rem;
}
.form-error { color: #ffb4a4; min-height: 1.5em; margin: 10px 0 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 18px;
  margin-top: 22px;
}
.card {
  position: relative;
  padding: 18px 18px 20px;
  border-radius: 12px;
  border: 2px solid var(--brass-lo);
  background: linear-gradient(160deg, rgba(74, 52, 26, 0.55), rgba(22, 16, 11, 0.75));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 6px 16px rgba(0, 0, 0, 0.4);
  text-align: left;
}
.card .emblem { width: 68px; height: 68px; float: right; margin: 0 0 6px 12px; }
.card p { color: var(--parchment-dim); }
.card .btn { margin-top: 4px; }
.card .hint { margin: 10px 0 0; min-height: 1.4em; }

/* ---- room ---- */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.side { display: grid; gap: 18px; }
@media (max-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .stage { order: -1; }
}

.seats { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 9px; }
.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 7px;
  border-radius: 10px;
  border: 2px solid rgba(168, 124, 34, 0.55);
  background: linear-gradient(180deg, rgba(20, 15, 11, 0.75), rgba(34, 26, 18, 0.75));
  min-height: 46px;
}
.seat .dot {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8, transparent 45%), var(--seat, #555);
  box-shadow: inset 0 -3px 4px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(0, 0, 0, 0.6), 0 0 10px color-mix(in srgb, var(--seat, transparent) 55%, transparent);
}
.seat[data-seat='0'] { --seat: var(--s0); }
.seat[data-seat='1'] { --seat: var(--s1); }
.seat[data-seat='2'] { --seat: var(--s2); }
.seat .who { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .tag {
  flex: 0 0 auto;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px 1px;
  border-radius: 999px;
  border: 1px solid var(--brass-mid);
  color: var(--brass-hi);
}
.seat.empty { border-style: dashed; color: var(--parchment-dim); }
.seat.empty .dot { background: #2c2520; box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.7), 0 0 0 2px rgba(0, 0, 0, 0.6); }
.seat.away { opacity: 0.6; }
.seat.away .tag { border-color: var(--danger); color: #ffb4a4; }
.seat.you { border-color: var(--brass-hi); box-shadow: 0 0 0 1px rgba(246, 220, 142, 0.25), 0 0 16px rgba(232, 170, 60, 0.18); }

.stage { min-height: 420px; }
.status {
  font-family: var(--font-head);
  font-size: clamp(1.25rem, 3.6vw, 1.7rem);
  text-align: center;
  color: var(--parchment);
  margin: 0 0 6px;
  min-height: 1.6em;
}
.status.win { color: var(--brass-hi); animation: glow 1.1s ease-in-out infinite alternate; }
@keyframes glow {
  from { text-shadow: 0 0 6px rgba(246, 220, 142, 0.35); }
  to { text-shadow: 0 0 22px rgba(246, 220, 142, 0.95), 0 0 44px rgba(232, 150, 60, 0.6); }
}
.legend {
  display: flex;
  gap: 8px 18px;
  justify-content: center;
  flex-wrap: wrap;
  color: var(--parchment-dim);
  font-size: 0.92rem;
  margin: 0 0 14px;
  min-height: 1.5em;
}
.legend .chip { display: inline-flex; align-items: center; gap: 7px; }
.legend .chip i {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--seat, #777);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.6);
}
.chip[data-seat='0'] { --seat: var(--s0); }
.chip[data-seat='1'] { --seat: var(--s1); }
.chip[data-seat='2'] { --seat: var(--s2); }
.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* ---- Four in a Row ---- */

.board {
  display: flex;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 10px;
  border-radius: 16px;
  border: 3px solid var(--brass-lo);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 240, 190, 0.35), transparent 45%),
    linear-gradient(160deg, var(--brass) 0%, var(--brass-mid) 45%, #7d5a17 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), inset 0 -4px 0 rgba(60, 40, 5, 0.45), 0 12px 26px rgba(0, 0, 0, 0.55);
}
.col {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px 3px;
  margin: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}
.col:disabled { cursor: default; }
.col:not(:disabled):hover { background: rgba(255, 250, 220, 0.28); }
.cell {
  display: block;
  width: var(--cell);
  height: var(--cell);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #0c0805, #1c130c 70%);
  box-shadow: inset 0 4px 7px rgba(0, 0, 0, 0.85), 0 1px 0 rgba(255, 240, 190, 0.5);
}
.cell.s0 { --seat: var(--s0); }
.cell.s1 { --seat: var(--s1); }
.cell.s2 { --seat: var(--s2); }
.cell.s0, .cell.s1, .cell.s2 {
  background:
    radial-gradient(circle at 50% 50%, transparent 0 34%, rgba(0, 0, 0, 0.28) 35% 40%, transparent 41%),
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.75), transparent 38%),
    radial-gradient(circle at 50% 50%, var(--seat), color-mix(in srgb, var(--seat) 55%, #000) 100%);
  box-shadow: inset 0 -4px 6px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 240, 190, 0.5);
}
.cell.fresh { animation: drop 0.38s cubic-bezier(0.3, 0, 0.6, 1.25); }
@keyframes drop {
  from { transform: translateY(calc(var(--fall, 3) * -1 * (var(--cell) + 5px))); }
  to { transform: translateY(0); }
}
.cell.win { animation: pulse 0.7s ease-in-out infinite alternate; }
@keyframes pulse {
  from { box-shadow: inset 0 -4px 6px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 10px 3px var(--seat); }
  to { box-shadow: inset 0 -4px 6px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 26px 9px var(--seat); }
}

/* ---- Tri-Pong ---- */

.hud {
  display: flex;
  justify-content: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.life {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 3px;
  border-radius: 999px;
  border: 2px solid var(--seat, #777);
  background: rgba(15, 11, 8, 0.7);
  font-size: 0.92rem;
}
.life[data-seat='0'] { --seat: var(--s0); }
.life[data-seat='1'] { --seat: var(--s1); }
.life[data-seat='2'] { --seat: var(--s2); }
.life .cogs { color: var(--seat); letter-spacing: 0.1em; }
.life .who { max-width: 19ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.life.out { opacity: 0.45; text-decoration: line-through; }
#pong-canvas {
  display: block;
  width: min(100%, 620px);
  aspect-ratio: 10 / 9;
  margin: 0 auto;
  border-radius: 14px;
  background: radial-gradient(circle at 50% 55%, #241a11, #0d0906 75%);
  border: 2px solid var(--brass-lo);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
  touch-action: none;
  cursor: ew-resize;
}

/* ---- notices ---- */

.notice { text-align: center; max-width: 560px; margin: 8vh auto 0; }
.notice p { color: var(--parchment); }

#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 30px);
  z-index: 10;
  max-width: min(92vw, 460px);
  padding: 11px 18px 9px;
  border-radius: 10px;
  border: 2px solid var(--copper);
  background: rgba(30, 16, 10, 0.96);
  color: #ffe3d6;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#conn {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 11;
  padding: 7px 12px 5px;
  text-align: center;
  background: #6e2416;
  color: #ffe3d6;
  border-bottom: 2px solid var(--copper);
}

footer {
  position: relative;
  z-index: 1;
  text-align: center;
  color: rgba(201, 184, 145, 0.55);
  font-size: 0.8rem;
  padding: 0 16px 22px;
}

@media (prefers-reduced-motion: reduce) {
  .gear, .status.win, .cell.win, .cell.fresh { animation: none; }
  .btn { transition: none; }
}
