/* Contraption Lab: the Inventor's Workshop look Doug picked (6 Oct, "wood style"): a pegboard wall, a wooden
   bench for the board, brass and copper parts, cream cards with brown ink, Fraunces for titles and Fredoka for
   reading. Its own look; games.css only gives the shared rules (no selecting text, the Back button, pop-ups). */
@font-face { font-family: Fraunces; src: url(/fonts/Fraunces.woff2) format('woff2'); font-weight: 400 900; font-display: swap; }
:root {
  --bg: #a9784a; --bg2: #8f6238; --panel: #f4e4c1; --panel2: #fbf1dc; --line: #c9a777; --ink: #4a2a10;
  --text: #3b220c; --soft: #7a5432; --accent: #b0451d; --good: #4f9a2e; --brass: #d4a437; --radius: 16px;
}
html { background: var(--bg); }
body.cl {
  min-height: 100dvh; font-family: Fredoka, system-ui, sans-serif; color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(circle at 11px 11px, #6b4626 3px, transparent 3.5px);
  background-size: 22px 22px;
  overflow: hidden;
}
body.cl.reading { overflow: auto; }
a { color: var(--accent); }
.cl button { background: var(--panel); color: var(--ink); border: 2px solid #8a5a2b; border-radius: 14px; box-shadow: 0 4px 0 #6b4626; font-family: Fredoka, sans-serif; font-weight: 600; }
.cl button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #6b4626; }
.cl button:focus-visible { outline: 3px solid #ffd24a; outline-offset: 2px; }
#board:focus { outline: none; }
.cl .muted { color: var(--soft); }
.cl .leave-ask .card, .cl .lock-pop .lk-card { background: var(--panel); color: var(--text); border-color: #8a5a2b; box-shadow: 0 6px 0 #6b4626; }

#app { height: 100dvh; display: flex; flex-direction: column; }
.cl-top { display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 12px 6px; min-height: 56px; box-sizing: border-box; }
.cl-top .where {
  flex: 1; min-width: 0; margin: 0; text-align: center; font: 700 clamp(18px, 5vw, 26px)/1.1 Fraunces, serif; color: #5b3412;
  background: var(--panel); border: 2px solid #8a5a2b; border-radius: 14px; padding: 8px 10px; box-shadow: 0 4px 0 #6b4626;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.on-home .cl-top .where { visibility: hidden; }
.count { background: var(--panel); border: 2px solid #8a5a2b; border-radius: 14px; padding: 4px 10px; text-align: center; box-shadow: 0 4px 0 #6b4626; min-width: 52px; }
.count small { display: block; font-size: 10px; letter-spacing: .06em; color: var(--soft); }
.count b { font-size: 18px; color: var(--accent); }

/* ---------- pages ---------- */
.page { flex: 1; overflow-y: auto; padding: 4px 16px 24px; box-sizing: border-box; max-width: 640px; width: 100%; margin: 0 auto; }
.page h2 { font: 700 26px Fraunces, serif; color: #5b3412; margin: 6px 0 4px; text-align: center; background: var(--panel); border: 2px solid #8a5a2b; border-radius: 14px; padding: 8px; box-shadow: 0 4px 0 #6b4626; }
.page > .muted { text-align: center; margin: 8px 0 14px; color: #fff3dc; text-shadow: 0 1px 0 #6b4626; }
.home { display: flex; flex-direction: column; gap: 12px; justify-content: center; overflow: hidden; }
.logo { margin: 0; text-align: center; font: 900 clamp(32px, 10vw, 48px)/1 Fraunces, serif; color: #5b3412; background: var(--panel); border: 3px solid #8a5a2b; border-radius: 18px; padding: 14px 10px; box-shadow: 0 6px 0 #6b4626; }
.tag { margin: 0; text-align: center; color: #fff6e4; font-weight: 600; text-shadow: 0 1px 0 #5b3412; }
.pick { background: #f4e4c1e6; border: 2px solid #8a5a2b; border-radius: 16px; padding: 10px; display: grid; gap: 6px; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.chips button { min-height: 44px; padding: 4px 6px; font-size: 15px; border-radius: 22px; box-shadow: 0 3px 0 #6b4626; }
.chips button[aria-checked='true'] { background: var(--accent); color: #fff; border-color: #6b2a10; }
#level-chips button[aria-checked='true'] { background: var(--good); border-color: #2c5d14; }
.blurb { margin: 0; text-align: center; font-size: 14px; color: var(--soft); min-height: 2.4em; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile-btn { display: grid; justify-items: center; gap: 2px; padding: 10px 8px 12px; min-height: 120px; }
.tile-btn .ic { width: 56px; height: 56px; display: grid; place-items: center; }
.tile-btn .ic svg { width: 56px; height: 56px; }
.tile-btn b { font: 700 19px Fraunces, serif; }
.tile-btn small { font-weight: 500; color: var(--soft); font-size: 13px; }
.tile-btn.gold { background: linear-gradient(#fff0b0, #e9c766); }
.row-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.wood-btn { min-height: 44px; padding: 6px 14px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; background: var(--panel); color: var(--ink); border: 2px solid #8a5a2b; border-radius: 14px; box-shadow: 0 4px 0 #6b4626; font-weight: 600; }
.wood-btn.small { font-size: 15px; }
.start-btn { min-height: 56px; padding: 6px 18px; font: 700 22px Fredoka, sans-serif; color: #fff !important; background: linear-gradient(#6fb244, #4f9a2e) !important; border: 3px solid #2c5d14 !important; border-radius: 30px !important; box-shadow: 0 5px 0 #2c5d14 !important; letter-spacing: .02em; }
.start-btn.stop { background: linear-gradient(#e06a4a, #b0451d) !important; border-color: #6b2a10 !important; box-shadow: 0 5px 0 #6b2a10 !important; }
.start-btn.wide { width: 100%; margin-top: 16px; }

.pz-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pz-grid button { width: 100%; min-height: 84px; display: grid; gap: 2px; justify-items: center; padding: 8px; }
.pz-grid b { font: 700 16px Fraunces, serif; }
.pz-grid .n { font-size: 12px; color: var(--soft); }
.pz-grid .st { color: #d4a437; letter-spacing: 2px; font-size: 16px; text-shadow: 0 1px 0 #6b4626; }
.pz-grid button:disabled { opacity: .55; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cards .pc { background: var(--panel); border: 2px solid #8a5a2b; border-radius: 16px; padding: 8px; box-shadow: 0 4px 0 #6b4626; text-align: center; }
.cards .pc .art { background: linear-gradient(135deg, #d39a5f, #a8693a); border-radius: 12px; height: 92px; display: grid; place-items: center; }
.cards .pc .art svg { width: 86px; height: 86px; }
.cards .pc h3 { margin: 6px 0 2px; font: 700 17px Fraunces, serif; color: #5b3412; }
.cards .pc p { margin: 0; font-size: 13.5px; color: #6b4a2a; }
.how-list li { margin-bottom: 8px; }
.how { background: #f4e4c1f2; border-radius: 16px; margin-top: 8px; margin-bottom: 16px; padding-top: 12px; }
.how h2 { box-shadow: none; }

/* ---------- the board ---------- */
.play { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage { position: relative; flex: 1; min-height: 0; margin: 0 8px; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; border-radius: 18px; }
.zoom { display: flex; gap: 6px; }
.zoom button { width: 46px; min-width: 0; padding: 0; font-size: 22px; line-height: 1; }
.bubble { position: absolute; display: flex; gap: 6px; padding: 6px; background: #f4e4c1f2; border: 2px solid #8a5a2b; border-radius: 16px; box-shadow: 0 4px 0 #6b4626; transform: translate(-50%, -100%); z-index: 3; }
.bubble button { width: 44px; height: 44px; padding: 0; font-size: 22px; border-radius: 12px; box-shadow: 0 3px 0 #6b4626; }
.bubble #remove { color: #b0451d; }
.toast { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); max-width: calc(100% - 32px); box-sizing: border-box; background: #fbf1dc; border: 2px solid #8a5a2b; border-radius: 14px; padding: 8px 14px; font-weight: 600; box-shadow: 0 4px 0 #6b4626; z-index: 4; text-align: center; }
.dock { padding: 8px 8px max(10px, env(safe-area-inset-bottom)); display: grid; gap: 6px; }
.tray { display: flex; gap: 6px; justify-content: center; }
.tray button { position: relative; flex: 1 1 0; max-width: 92px; min-width: 0; min-height: 84px; padding: 4px 2px 6px; display: grid; justify-items: center; align-content: start; gap: 0; border-radius: 14px; }
.tray button[aria-checked='true'] { background: #fff8e8; border: 3px solid var(--accent); }
.tray .pi { width: 44px; height: 44px; }
.tray .pi svg { width: 44px; height: 44px; }
.tray b { font-size: 13.5px; line-height: 1.1; }
.tray small { font-size: 10.5px; color: var(--soft); font-weight: 500; line-height: 1.1; white-space: nowrap; }
.tray .left { position: absolute; top: -8px; right: -6px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--good); color: #fff; font-size: 13px; line-height: 22px; border: 2px solid #fff; box-sizing: border-box; padding: 0 4px; }
.tray .left.none { background: #a08a72; }
.hint-line { margin: 0; text-align: center; font-size: 13px; color: #fff3dc; text-shadow: 0 1px 0 #5b3412; }
.dock-btns { display: flex; gap: 8px; }
.dock-btns .start-btn { flex: 1; }
.dock-btns .wood-btn { min-width: 46px; padding: 0 6px; font-size: 22px; }
#shared:empty { display: none; }

/* ---------- end card ---------- */
.end { display: grid; place-items: center; position: fixed; inset: 0; background: #2a160866; z-index: 20; padding: 16px; }
.end-card { width: min(380px, 100%); background: var(--panel); border: 3px solid #8a5a2b; border-radius: 20px; box-shadow: 0 8px 0 #6b4626; padding: 18px; text-align: center; animation: g-pop .3s ease-out; }
.end-card h2 { margin: 0 0 6px; font: 900 30px Fraunces, serif; color: #5b3412; background: none; border: 0; box-shadow: none; padding: 0; }
.end-stars { font-size: 40px; letter-spacing: 6px; color: #d4a437; text-shadow: 0 2px 0 #6b4626; }
.end-stars .off { color: #cdb592; }
.end-line { font-size: 17px; margin: 6px 0 14px; }
.end-btns { display: grid; gap: 8px; }
.end-btns button { width: 100%; min-height: 50px; }

@media (max-height: 680px) {
  .tile-btn { min-height: 96px; padding: 6px; }
  .tile-btn .ic, .tile-btn .ic svg { width: 40px; height: 40px; }
  .logo { padding: 8px; }
  .home { gap: 8px; }
  .tray button { min-height: 70px; }
  .tray .pi, .tray .pi svg { width: 34px; height: 34px; }
  .hint-line { display: none; }
}
/* Sideways phones and wide screens: the tray and the buttons go down the right side of the board. */
@media (orientation: landscape) and (min-width: 600px) {
  .play { flex-direction: row; }
  .dock { width: 300px; flex: 0 0 auto; box-sizing: border-box; align-content: center; }
  .tray { flex-wrap: wrap; }
  .tray button { flex: 0 0 84px; }
  .dock-btns { flex-wrap: wrap; }
  .dock-btns .start-btn { flex: 1 1 100%; order: -1; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .home { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; align-content: center; max-width: 900px; }
  .home .logo { grid-column: 1 / -1; font-size: 30px; padding: 6px; }
  .home .tag { display: none; }
  .home .pick { padding: 8px; gap: 4px; }
  .home .chips button { min-height: 40px; }
  .home .blurb { min-height: 0; font-size: 13px; }
  .tiles { align-content: stretch; }
  .tile-btn { min-height: 0; }
  .tile-btn .ic, .tile-btn .ic svg { width: 40px; height: 40px; }
  .row-btns { grid-column: 1 / -1; }
  .dock { width: 260px; padding-top: 4px; }
  .tray button { flex: 0 0 72px; min-height: 62px; }
  .tray .pi, .tray .pi svg { width: 30px; height: 30px; }
  .tray small { display: none; }
  .hint-line { display: none; }
  .start-btn { min-height: 48px; font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) { .end-card { animation: none; } }
