/* Factory Bloom Chess */
:root {
  --pink: #ff2fa8; --purple: #a436ff; --lime: #b6ff2e; --cyan: #22f0ff; --orange: #ff8a1f; --yellow: #ffd91f;
  --bg: #0d0820; --panel: rgba(22, 13, 48, .88); --ink: #f6f0ff; --muted: #c2b3e0;
  --day: #ffb23d; --night: #3cf3ff;
  --display: "Bungee", "Arial Black", Impact, system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4; overflow-x: hidden; -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- backdrop ---------- */
#bg { position: fixed; inset: 0; z-index: -2; overflow: hidden; }
#bg > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.gear { position: absolute; animation: spin 60s linear infinite; opacity: .92; }
.gear svg { display: block; width: 100%; height: 100%; }
.gear.g1 { width: 40vmin; height: 40vmin; left: -9vmin; bottom: 6vmin; }
.gear.g2 { width: 22vmin; height: 22vmin; left: 25vmin; bottom: 32vmin; animation-duration: 34s; animation-direction: reverse; }
.gear.g3 { width: 32vmin; height: 32vmin; right: -7vmin; top: 12vmin; animation-duration: 48s; }
.gear.g4 { width: 17vmin; height: 17vmin; right: 21vmin; top: 5vmin; animation-duration: 26s; animation-direction: reverse; }
.conveyor { position: absolute; left: 0; right: 0; bottom: 0; height: 100px; }
.conveyor .belt {
  position: absolute; left: 0; right: 0; bottom: 6px; height: 24px; background-color: #1b1e33;
  background-image: radial-gradient(circle at 20px 50%, #7683b5 0 6px, #2a3050 6.5px 8px, transparent 8.5px);
  background-size: 40px 100%; border-top: 4px solid #7683b5; border-bottom: 4px solid #4b557e; border-radius: 12px;
}
.conveyor .riders {
  position: absolute; left: -320px; right: 0; bottom: 30px; height: 70px;
  background-repeat: repeat-x; background-size: 320px 70px; animation: ride 11s linear infinite;
}
#petals { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.petal {
  position: absolute; top: 0; border-radius: 80% 0 80% 0; background: currentColor; opacity: .7;
  box-shadow: 0 0 10px currentColor; animation: fall linear infinite;
}
@keyframes fall { from { transform: translate3d(0, -8vh, 0) rotate(0); } to { transform: translate3d(var(--dx, 60px), 112vh, 0) rotate(540deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ride { from { transform: translateX(0); } to { transform: translateX(320px); } }
@keyframes sway { from { transform: rotate(-11deg); } to { transform: rotate(11deg); } }
@keyframes pulse { from { transform: scale(.82); } to { transform: scale(1.08); } }
@keyframes blink { from { opacity: .55; } to { opacity: 1; } }
@keyframes land { from { transform: scale(1.22) translateY(-6%); } to { transform: none; } }
@keyframes glowText { from { filter: brightness(1); } to { filter: brightness(1.25); } }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; max-width: 1240px; margin: 0 auto;
}
.logo { background: rgba(13, 8, 32, .78); padding: 6px 14px; border-radius: 14px; font-family: var(--display); font-weight: 400; font-size: clamp(20px, 4.6vw, 38px); margin: 0; line-height: 1.05; letter-spacing: .02em; animation: glowText 3s ease-in-out infinite alternate; }
.logo .w1 { color: #dfe6f2; text-shadow: 0 2px 0 #55608a, 0 0 14px rgba(34, 240, 255, .7); }
.logo .w2 { color: var(--pink); text-shadow: 0 0 8px var(--pink), 0 0 26px var(--purple); }
.logo .w3 { color: var(--lime); text-shadow: 0 0 8px rgba(182, 255, 46, .9), 0 0 26px rgba(34, 240, 255, .7); }
.top-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: var(--panel); border: 2px solid var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.pill.connected { color: var(--lime); border-color: var(--lime); }
.pill.waiting, .pill.connecting { color: var(--yellow); border-color: var(--yellow); }
.pill.waiting::before, .pill.connecting::before, .pill.lost::before { animation: blink .7s ease-in-out infinite alternate; }
.pill.lost, .pill.replaced { color: #ff6b8e; border-color: #ff6b8e; }
.pill.solo { color: var(--cyan); border-color: var(--cyan); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--cyan); background: var(--panel);
  font-size: 20px; line-height: 1; box-shadow: 0 0 14px rgba(34, 240, 255, .45);
}
.icon-btn.off { border-color: var(--muted); box-shadow: none; opacity: .8; }

/* ---------- panels ---------- */
.panel {
  position: relative; background: var(--panel); border-radius: 18px; padding: 26px 18px 18px;
  border: 2px solid #5b4a9a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .06) inset, 0 0 26px rgba(164, 54, 255, .38), 0 10px 30px rgba(0, 0, 0, .5);
}
.panel h3, .roster summary {
  font-family: var(--display); font-weight: 400; font-size: 17px; margin: 0 0 10px; color: var(--yellow);
  text-shadow: 0 0 12px rgba(255, 138, 31, .8); letter-spacing: .03em;
}
.pvine { position: absolute; left: 14px; right: 14px; top: -20px; width: calc(100% - 28px); height: 40px; pointer-events: none; overflow: visible; }
.pcorner { position: absolute; width: 84px; height: 84px; pointer-events: none; overflow: visible; }
.pcorner.tl { right: -30px; top: -34px; }
.pcorner.br { left: -30px; bottom: -30px; }

/* ---------- buttons ---------- */
.btn {
  position: relative; border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 800; font-size: 16px; color: #150a2e;
  background: linear-gradient(180deg, #fff 0%, var(--c, var(--pink)) 16%, var(--c, var(--pink)) 70%, rgba(0, 0, 0, .25) 160%), var(--c, var(--pink));
  box-shadow: 0 0 0 2px #150a2e, 0 0 0 4px var(--c, var(--pink)), 0 0 22px var(--c, var(--pink)); transition: transform .08s;
}
.btn:active { transform: translateY(2px) scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.pink { --c: var(--pink); } .btn.cyan { --c: var(--cyan); } .btn.lime { --c: var(--lime); } .btn.yellow { --c: var(--yellow); }
.btn.outline { background: transparent; color: var(--ink); box-shadow: 0 0 0 2px var(--muted); }
.btn.big { font-family: var(--display); font-weight: 400; font-size: clamp(18px, 4.4vw, 24px); padding: 18px 26px; min-width: 230px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; font-size: 15px; }
.row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ---------- home ---------- */
.screen { padding: 14px 16px 120px; overflow-x: clip; }
.hero { max-width: 660px; margin: 3vh auto 0; text-align: center; padding: 34px 22px 26px; }
.hero-art { display: flex; align-items: center; justify-content: center; gap: 8px; }
.hero-piece { width: clamp(84px, 24vw, 150px); flex-shrink: 0; }
.hero-piece svg { width: 100%; height: auto; display: block; overflow: visible; filter: drop-shadow(0 0 14px rgba(255, 47, 168, .55)); }
.hero-mid h2 { font-family: var(--display); font-weight: 400; font-size: clamp(22px, 5.6vw, 40px); line-height: 1.05; margin: 0; color: var(--yellow); text-shadow: 0 0 14px var(--orange), 0 0 34px var(--pink); }
.tagline { color: var(--muted); max-width: 46ch; margin: 14px auto 22px; }
.menu { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.subview { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.label { margin: 0; font-weight: 700; color: var(--ink); }
.label.small { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, "Courier New", monospace; font-weight: 800; font-size: clamp(40px, 12vw, 76px); letter-spacing: .14em; padding: 6px 4px 6px .14em; line-height: 1.1;
  color: #fff; text-shadow: 0 0 10px var(--cyan), 0 0 30px var(--cyan), 0 0 60px var(--purple); user-select: all;
}
.code-input {
  font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, "Courier New", monospace; font-weight: 800; font-size: clamp(30px, 9vw, 52px); letter-spacing: .14em; text-align: center; text-transform: uppercase;
  width: min(100%, 360px); padding: 10px 6px; border-radius: 14px; border: 3px solid var(--cyan); background: #0d0820; color: #fff;
  box-shadow: 0 0 22px rgba(34, 240, 255, .5); outline: none;
}
.code-input::placeholder { color: #4b3f78; }
.code-input:focus { border-color: var(--lime); box-shadow: 0 0 26px rgba(182, 255, 46, .6); }
.wait { margin: 0; min-height: 1.4em; font-weight: 700; color: var(--yellow); }
.wait.err { color: #ff8fa8; }

/* ---------- game layout ---------- */
.layout { display: grid; grid-template-columns: auto 350px; gap: 34px; justify-content: center; align-items: start; max-width: 1240px; margin: 0 auto; }
.board-col { width: min(calc(100vw - 32px - 384px), max(calc(100vh - 300px), 440px), 800px); min-width: 300px; }
.side { display: flex; flex-direction: column; gap: 34px; padding-top: 14px; min-width: 0; }

.bar {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; margin: 8px 0; min-height: 44px; border-radius: 12px;
  background: var(--panel); border: 2px solid transparent; position: relative; z-index: 4;
}
.bar.day { border-color: rgba(255, 178, 61, .45); } .bar.night { border-color: rgba(60, 243, 255, .45); }
.bar.turn.day { box-shadow: 0 0 20px rgba(255, 178, 61, .8); border-color: var(--day); }
.bar.turn.night { box-shadow: 0 0 20px rgba(60, 243, 255, .8); border-color: var(--night); }
.bar-name { font-family: var(--display); font-size: 15px; }
.day .bar-name, .name.day { color: var(--day); text-shadow: 0 0 10px rgba(255, 138, 31, .7); }
.night .bar-name, .name.night { color: var(--night); text-shadow: 0 0 10px rgba(164, 54, 255, .9); }
.bar-who { font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .12); }
.caps { margin-left: auto; display: flex; flex-wrap: wrap; justify-content: flex-end; padding-left: 6px; }
.caps svg { width: 20px; height: 20px; margin-left: -5px; display: block; }

.banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; text-align: center;
  min-height: 46px; padding: 8px 14px; margin: 8px 0 22px; border-radius: 12px; font-weight: 800; font-size: 16px;
  background: var(--panel); border: 2px solid #5b4a9a; position: relative; z-index: 4;
}
.banner.day { color: var(--day); } .banner.night { color: var(--night); }
.banner.check {
  color: #fff; border-color: #ff2a5f; font-family: var(--display); font-weight: 400;
  background: repeating-linear-gradient(-45deg, #b3123f 0 14px, #7a0b2a 14px 28px); box-shadow: 0 0 26px rgba(255, 42, 95, .9); animation: blink .6s ease-in-out infinite alternate;
}
.banner.over {
  color: #150a2e; border-color: #fff; font-family: var(--display); font-weight: 400; font-size: clamp(17px, 3.6vw, 24px); padding: 14px;
  background: linear-gradient(90deg, var(--pink), var(--yellow), var(--lime), var(--cyan)); box-shadow: 0 0 34px rgba(255, 217, 31, .9);
}
.banner.over .btn { font-family: system-ui, sans-serif; font-size: 15px; --c: #fff; box-shadow: 0 0 0 2px #150a2e; }

/* ---------- board ---------- */
.board-frame {
  position: relative; padding: 4.2%; border-radius: 16px; margin: 0;
  background:
    repeating-linear-gradient(45deg, rgba(0, 0, 0, .16) 0 10px, transparent 10px 20px),
    linear-gradient(135deg, #8791a8, #3b4257 45%, #8d97ae 60%, #2c3246);
  box-shadow: 0 0 0 3px #1a1430, 0 0 0 6px rgba(255, 217, 31, .4), 0 0 44px rgba(255, 47, 168, .5), 0 0 100px rgba(34, 240, 255, .28), inset 0 0 14px rgba(0, 0, 0, .7);
}
.frame-decor { position: absolute; inset: -6%; pointer-events: none; z-index: 3; }
.frame-decor > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.sway-bloom { position: absolute; aspect-ratio: 1; animation: sway 6s ease-in-out infinite alternate; }
.sway-bloom svg { display: block; width: 100%; height: 100%; overflow: visible; }

.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 1;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 3px #14102a, 0 0 18px rgba(0, 0, 0, .8);
}
.sq {
  position: relative; min-width: 0; min-height: 0; background-repeat: no-repeat;
}
.sq.l {
  background-image: 
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .16) 0 1px, rgba(0, 0, 0, .035) 1px 3px),
    linear-gradient(135deg, #e6ecf3, #b5c0cd);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5), inset 0 0 8px rgba(60, 70, 90, .35);
}
.sq.d {
  background-image: 
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .06) 0 1px, rgba(0, 0, 0, .06) 1px 3px),
    linear-gradient(135deg, #6b7a91, #414c60);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14), inset 0 0 8px rgba(0, 0, 0, .45);
}
.sq.mine { cursor: grab; }

.sq::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.sq.last::before { background: rgba(255, 217, 31, .45); box-shadow: inset 0 0 0 3px rgba(255, 217, 31, .95), inset 0 0 14px rgba(255, 138, 31, .8); }
.sq.sel::before { background: rgba(34, 240, 255, .5); box-shadow: inset 0 0 0 3px var(--cyan), inset 0 0 16px var(--cyan); }
.sq.chk::before { background: radial-gradient(circle, rgba(255, 20, 70, 1), rgba(255, 20, 70, .35) 72%); box-shadow: inset 0 0 0 3px #ff1446; animation: blink .55s ease-in-out infinite alternate; }
.sq.hover::before { box-shadow: inset 0 0 0 4px var(--lime), inset 0 0 18px var(--lime); }

/* legal move markers: glowing flower dots, and a glowing ring on pieces that can be captured */
.sq.legal { cursor: pointer; }
.sq.legal::after {
  content: ""; position: absolute; inset: 29%; z-index: 2; pointer-events: none;
  background: var(--dotf) center / contain no-repeat;
  filter: drop-shadow(0 0 5px var(--lime)) drop-shadow(0 0 10px var(--cyan));
  animation: pulse .9s ease-in-out infinite alternate;
}
.sq.legal.occ::after {
  inset: 5%; background: none; border-radius: 50%; border: 4px dotted var(--pink);
  box-shadow: 0 0 12px var(--pink), inset 0 0 12px var(--pink); filter: none;
}

.piece { position: absolute; inset: 1.5%; z-index: 1; pointer-events: none; }
.piece svg { display: block; width: 100%; height: 100%; overflow: visible; }
.sq.dragging .piece { opacity: .28; }
.sq.moved .piece { animation: land .28s ease-out; }
#coords { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
#coords span {
  position: absolute; transform: translate(-50%, -50%); min-width: 1.5em; padding: .12em 0; text-align: center; border-radius: 999px;
  font-weight: 800; font-size: clamp(8px, 1.5vmin, 12px); line-height: 1.15; color: var(--yellow); background: rgba(21, 10, 46, .88);
}
.ghost { position: fixed; z-index: 1000; pointer-events: none; transform: translate(-50%, -50%); filter: drop-shadow(0 12px 10px rgba(0, 0, 0, .55)); }
.ghost svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ---------- chat ---------- */
.chat-log {
  height: 250px; overflow-y: auto; padding: 10px; border-radius: 12px; background: rgba(8, 4, 20, .7);
  border: 1px solid #3a2d6b; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain;
}
.msg { max-width: 92%; padding: 7px 11px; border-radius: 14px; background: rgba(255, 255, 255, .07); border-left: 4px solid; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.day { border-color: var(--day); } .msg.night { border-color: var(--night); }
.msg.me { align-self: flex-end; border-left: 0; border-right: 4px solid; border-color: inherit; }
.msg.me.day { border-color: var(--day); } .msg.me.night { border-color: var(--night); }
.msg .name { display: block; font-size: 12px; font-weight: 800; letter-spacing: .03em; }
.msg.sys { align-self: center; border: 0; background: none; color: var(--muted); font-size: 13px; font-style: italic; text-align: center; padding: 2px; }
.chat-empty { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }
.chat-form { display: flex; gap: 10px; margin-top: 12px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 2px solid #5b4a9a; background: #0d0820; outline: none; font-size: 16px;
}
.chat-form input:focus { border-color: var(--lime); box-shadow: 0 0 14px rgba(182, 255, 46, .5); }

/* ---------- controls + roster ---------- */
.room-line { margin: 0 0 12px; color: var(--muted); }
.room-line b { font-family: ui-monospace, Consolas, Menlo, monospace; font-weight: 800; color: #fff; letter-spacing: .12em; text-shadow: 0 0 10px var(--cyan); }
.promo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.promo button {
  background: rgba(255, 255, 255, .06); border: 2px solid #5b4a9a; border-radius: 12px; padding: 4px 2px 6px; font-size: 12px; font-weight: 700; color: var(--muted);
}
.promo button svg { display: block; width: 100%; height: auto; overflow: visible; }
.promo button.on { border-color: var(--lime); color: var(--lime); background: rgba(182, 255, 46, .12); box-shadow: 0 0 14px rgba(182, 255, 46, .55); }
.roster summary { cursor: pointer; margin: 0; }
.roster[open] summary { margin-bottom: 10px; }
.crew { display: grid; grid-template-columns: 46px 46px 1fr; align-items: center; gap: 8px; padding: 4px 0; }
.crew svg { display: block; width: 46px; height: 46px; overflow: visible; }
.crew b { display: block; font-size: 15px; } .crew span { color: var(--muted); font-size: 13px; }

/* ---------- notice ---------- */
.notice { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(5, 2, 14, .8); }
.notice .panel { max-width: 440px; text-align: center; padding: 34px 24px 24px; }
.notice p { font-size: 18px; font-weight: 700; margin: 0 0 18px; }

/* ---------- phones and narrow screens ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 30px; }
  .board-col { width: min(calc(100vw - 28px), 640px); min-width: 0; margin: 0 auto; }
  .side { width: min(calc(100vw - 28px), 640px); margin: 0 auto; padding-top: 6px; }
  .screen { padding: 8px 14px 120px; }
  .topbar { padding: 8px 12px; }
  .pill { font-size: 12px; padding: 6px 10px; }
  .logo { font-size: 17px; padding: 5px 10px; max-width: 11.5em; }
  .chat-log { height: 210px; }
  .hero { margin-top: 1vh; padding: 30px 14px 22px; }
  .btn.big { min-width: 0; width: 100%; }
  .menu { gap: 18px; }
  .gear { opacity: .6; }
}
@media (max-width: 420px) {
  .bar-name { font-size: 13px; } .caps svg { width: 17px; height: 17px; }
  .banner { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
