/* PuzzleX — the Cozy Table skin.
   Warm walnut wood, amber lamplight, felt board. Sits on the shared
   StrmrX core chrome by remapping the --sx-* tokens. */

:root {
  --sx-accent: #e8a24a;
  --sx-accent2: #c96f3b;
  --sx-accent-hover: #f2b463;
  --sx-accent-ink: #2a1608;
  --sx-accent-soft: rgba(232, 162, 74, .14);
  --sx-bg: #16100b;
  --sx-bg-hi: #1e1610;
  --sx-bg-lo: #110c08;
  --sx-surface: #251a11;
  --sx-surface2: #2d2015;
  --sx-surface-2: #2d2015;
  --sx-panel: rgba(37, 26, 17, .94);
  --sx-panel2: rgba(45, 32, 21, .94);
  --sx-border: rgba(232, 162, 74, .16);
  --sx-border2: rgba(232, 162, 74, .28);
  --sx-text: #f4ead9;
  --sx-muted: #bda88d;
  --sx-muted2: #8f7c64;
  --sx-glow-1: rgba(232, 162, 74, .13);
  --sx-glow-2: rgba(146, 84, 48, .15);

  --wood-hi: #3f2b1a;
  --wood-mid: #332214;
  --wood-lo: #271910;
  --felt: #27392c;
  --felt-lo: #1e2d22;
}

/* ---------- shared bits ---------- */

.x { color: var(--sx-accent); }
.brand-sub { color: var(--sx-muted); font-size: .78rem; letter-spacing: .06em; }

.by-strmrx {
  position: fixed; left: 14px; bottom: 12px; z-index: 300;
  font-size: .72rem; color: var(--sx-muted2); text-decoration: none;
  padding: 4px 9px; border-radius: 999px; background: rgba(20, 13, 8, .55);
  backdrop-filter: blur(4px); transition: color var(--sx-dur-fast) var(--sx-ease-out);
}
.by-strmrx b { color: #ff7828; font-weight: 700; }
.by-strmrx:hover { color: var(--sx-text); }

.beta-chip {
  font-size: .62rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--sx-accent); border: 1px solid var(--sx-border2);
  padding: 2px 7px; border-radius: 999px;
}

/* ---------- landing ---------- */

.landing main { max-width: 1040px; margin: 0 auto; padding: 24px 18px 80px; }
.hero { text-align: center; padding: 48px 10px 26px; }
.hero h1 { font-size: clamp(2rem, 5.5vw, 3.4rem); margin: 0 0 10px; letter-spacing: -.02em; }
.hero p.lede { color: var(--sx-muted); font-size: 1.08rem; max-width: 560px; margin: 0 auto 26px; }

.landing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 12px; }
@media (max-width: 760px) { .landing-grid { grid-template-columns: 1fr; } }

.lib-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
@media (max-width: 560px) { .lib-grid { grid-template-columns: repeat(2, 1fr); } }
.lib-thumb {
  position: relative; border-radius: var(--sx-radius-sm); overflow: hidden; cursor: pointer;
  border: 2px solid transparent; aspect-ratio: 4 / 3; background: var(--sx-surface);
  transition: transform var(--sx-dur-fast) var(--sx-ease-out), border-color var(--sx-dur-fast) var(--sx-ease-out);
}
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-thumb span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px; font-size: .72rem;
  background: linear-gradient(transparent, rgba(10, 6, 3, .85)); color: var(--sx-text);
}
.lib-thumb:hover { transform: translateY(-2px); }
.lib-thumb.sel { border-color: var(--sx-accent); box-shadow: 0 0 0 3px var(--sx-accent-soft); }

.size-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 16px; }
.size-chip {
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: .85rem;
  border: 1px solid var(--sx-border); background: var(--sx-surface); color: var(--sx-muted);
  transition: all var(--sx-dur-fast) var(--sx-ease-out);
}
.size-chip small { display: block; font-size: .64rem; opacity: .75; }
.size-chip:hover { color: var(--sx-text); border-color: var(--sx-border2); }
.size-chip.sel { background: var(--sx-accent); color: var(--sx-accent-ink); border-color: var(--sx-accent); }

.code-row { display: flex; gap: 10px; }
.code-row input { flex: 1; text-transform: uppercase; letter-spacing: .2em; font-family: var(--sx-mono); }

/* ---------- play page ---------- */

.page-play { overflow: hidden; height: 100dvh; }
.page-play body, body.playing { overscroll-behavior: none; }

#stage {
  position: fixed; inset: 0; touch-action: none; overflow: hidden;
  background:
    radial-gradient(1100px 700px at 50% 20%, rgba(255, 200, 120, .07), transparent 65%),
    linear-gradient(180deg, var(--sx-bg-hi), var(--sx-bg-lo));
  cursor: grab;
}
#stage.panning { cursor: grabbing; }

#table {
  position: absolute; top: 0; left: 0; transform-origin: 0 0;
  border-radius: 18px;
  background:
    radial-gradient(1200px 900px at 50% 32%, rgba(255, 205, 130, .12), transparent 62%),
    repeating-linear-gradient(93deg, rgba(0, 0, 0, .045) 0 3px, transparent 3px 11px),
    repeating-linear-gradient(1deg, rgba(255, 255, 255, .012) 0 2px, transparent 2px 14px),
    linear-gradient(160deg, var(--wood-hi), var(--wood-mid) 45%, var(--wood-lo));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 220, 160, .08);
}

#board {
  position: absolute; border-radius: 6px;
  background: linear-gradient(165deg, var(--felt), var(--felt-lo));
  box-shadow: inset 0 3px 22px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(0, 0, 0, .3);
  border: 10px solid transparent;
  border-image: linear-gradient(150deg, #5a3f26, #3a2818 60%, #4a3420) 1;
}
#board .ghost {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill;
  opacity: .15; filter: saturate(.75) brightness(1.05); pointer-events: none;
  transition: opacity var(--sx-dur-base) var(--sx-ease-in-out);
}
#board.no-ghost .ghost { opacity: 0; }

/* pieces */
.piece { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; z-index: 5; will-change: transform; }
.piece .rim { fill: none; stroke: rgba(25, 12, 4, .5); stroke-width: 1.5; transition: stroke var(--sx-dur-fast) var(--sx-ease-out); }
.piece .hit { fill: #000; fill-opacity: 0; pointer-events: visibleFill; cursor: grab; }
.piece.lifted { z-index: 60; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .5)); }
.piece.lifted .rim { stroke: var(--sx-accent); stroke-width: 2.2; }
.piece.locked-other .hit { cursor: not-allowed; }
.piece.locked-other .rim { stroke-width: 2.2; }
.piece.warning { animation: px-warn .7s var(--sx-ease-in-out) infinite; }
.piece.placed { z-index: 1; }
.piece.placed .rim { stroke: rgba(25, 12, 4, .22); }
.piece.placed .hit { pointer-events: none; cursor: default; }
.piece.snapped { animation: px-settle .38s var(--sx-spring); }

@keyframes px-settle {
  0% { transform: var(--px-t) scale(1.09); }
  55% { transform: var(--px-t) scale(.97); }
  100% { transform: var(--px-t) scale(1); }
}
@keyframes px-warn {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

/* cursors */
#cursors { position: absolute; inset: 0; pointer-events: none; }
.cursor { position: absolute; top: 0; left: 0; z-index: 220; pointer-events: none; transition: opacity .3s var(--sx-ease-out); }
.cursor svg { display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); }
.cursor .tag {
  margin: 2px 0 0 12px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  color: #1c0f06; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

/* HUD */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 250;
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: linear-gradient(rgba(16, 10, 6, .85), rgba(16, 10, 6, .35) 75%, transparent);
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.05rem; text-decoration: none; color: var(--sx-text); }
.hud .puzzle-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.hud .puzzle-meta .t { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .puzzle-meta .c { font-size: .68rem; color: var(--sx-muted); }

.progress-wrap { flex: 1; max-width: 340px; display: flex; align-items: center; gap: 10px; }
.progress-track { flex: 1; height: 10px; border-radius: 999px; background: rgba(0, 0, 0, .45); overflow: hidden; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5); }
.progress-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--sx-accent2), var(--sx-accent));
  transition: width .5s var(--sx-ease-out);
}
.progress-label { font-size: .78rem; color: var(--sx-muted); font-family: var(--sx-mono); white-space: nowrap; }

.players-bar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; max-width: 30vw; }
.player-chip {
  display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 6px; border-radius: 999px;
  background: rgba(0, 0, 0, .4); font-size: .74rem; animation: px-pop-in .32s var(--sx-spring);
}
.player-chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.player-chip .score { color: var(--sx-muted); font-family: var(--sx-mono); font-size: .68rem; }
.player-chip .kick { cursor: pointer; color: var(--sx-muted2); font-size: .8rem; padding: 0 2px; display: none; }
.player-chip .kick:hover { color: var(--sx-danger, #e46f6f); }
body.is-host .player-chip .kick { display: inline; }

@keyframes px-pop-in {
  from { transform: scale(.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.hud-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--sx-border);
  background: rgba(0, 0, 0, .4); color: var(--sx-text); cursor: pointer; font-size: 16px;
  display: grid; place-items: center;
  transition: all var(--sx-dur-fast) var(--sx-ease-out);
}
.hud-btn:hover { border-color: var(--sx-border2); background: rgba(30, 18, 10, .7); }
.hud-btn:active { transform: scale(.94); }

.room-chip {
  display: flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--sx-border2); background: rgba(0, 0, 0, .4); cursor: pointer;
  font-family: var(--sx-mono); font-size: .8rem; letter-spacing: .08em;
  color: var(--sx-accent); font-weight: 600;
  transition: all var(--sx-dur-fast) var(--sx-ease-out);
}
.room-chip:hover { border-color: var(--sx-border2); }

/* modals */
.px-modal {
  position: fixed; inset: 0; z-index: 400; display: none; place-items: center;
  background: rgba(10, 6, 3, .6); backdrop-filter: blur(5px); padding: 18px;
}
.px-modal.open { display: grid; }
.px-modal .box {
  width: min(520px, 96vw); max-height: 88dvh; overflow: auto;
  background: var(--sx-panel); border: 1px solid var(--sx-border); border-radius: var(--sx-radius);
  padding: 22px; box-shadow: var(--sx-shadow), 0 0 60px rgba(232, 162, 74, .06);
  animation: px-modal-in .32s var(--sx-spring);
}
.px-modal.closing .box { animation: px-modal-out .2s var(--sx-ease-in) forwards; }
.px-modal .box h2 { margin: 0 0 4px; font-size: 1.3rem; }
.px-modal .box .sub { color: var(--sx-muted); font-size: .86rem; margin: 0 0 16px; }
@keyframes px-modal-in { from { transform: scale(.94) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes px-modal-out { to { transform: scale(.96) translateY(6px); opacity: 0; } }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--sx-border); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .lab { font-size: .92rem; }
.setting-row .lab small { display: block; color: var(--sx-muted); font-size: .74rem; margin-top: 2px; }
.setting-row input[type="range"] { width: 150px; accent-color: var(--sx-accent); }
.hold-val { font-family: var(--sx-mono); font-size: .8rem; color: var(--sx-accent); min-width: 42px; text-align: right; }

/* podium */
.podium { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.podium-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--sx-radius-sm);
  background: var(--sx-surface); animation: px-pop-in .4s var(--sx-spring) backwards;
}
.podium-row:nth-child(1) { background: linear-gradient(90deg, rgba(232, 162, 74, .22), var(--sx-surface)); }
.podium-row .medal { font-size: 1.1rem; width: 26px; }
.podium-row .nm { flex: 1; font-weight: 600; }
.podium-row .ct { font-family: var(--sx-mono); color: var(--sx-muted); }

.finish-time { text-align: center; color: var(--sx-muted); font-size: .9rem; margin-bottom: 4px; }
.finish-time b { color: var(--sx-accent); font-family: var(--sx-mono); }

/* overlay mode */
body.overlay { background: transparent; }
body.overlay .hud { background: none; }
body.overlay #stage { cursor: default; }
.watermark {
  position: fixed; right: 14px; bottom: 12px; z-index: 300;
  display: flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  background: rgba(16, 10, 6, .72); color: var(--sx-text); font-size: .76rem; font-weight: 600;
  border: 1px solid var(--sx-border);
}
.watermark b { color: var(--sx-accent); }

/* connection banner */
#conn-banner {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 380;
  padding: 8px 16px; border-radius: 999px; background: rgba(60, 30, 12, .92);
  border: 1px solid var(--sx-border2); font-size: .82rem; display: none;
}
#conn-banner.show { display: block; animation: px-pop-in .3s var(--sx-spring); }

/* small screens */
@media (max-width: 640px) {
  .hud { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .hud .puzzle-meta { display: none; }
  .players-bar { display: none; }
  .progress-wrap { max-width: none; }
  .room-chip { font-size: .7rem; padding: 5px 9px; }
}
