:root {
  --paper: #fff9f3;
  --peach: #fdeee6;
  --peach-line: #f1e2d6;
  --card: #ffffff;
  --ink: #1f2a44;
  --muted: #6b7280;
  --line: #f1e2d6;
  --accent: #ef5a4c;
  --accent-deep: #c2412f;
  --accent-ink: #fff;
  --bar: #fdeee6;
  --bar-ink: #1f2a44;
  --radius: 14px;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--accent); min-height: 1em; margin: 8px 0; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.scroll {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

/* ---------- buttons ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.icon-btn.toggle.on,
.play-bar .icon-btn.toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 24px;
  border-radius: 999px;
  border: 0;
  font-weight: 600;
  cursor: pointer;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:disabled { opacity: 0.4; cursor: default; }
.secondary { background: #fff; border: 1.5px solid var(--line); color: var(--ink); }
.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  padding: 10px 0;
  cursor: pointer;
}

@media (hover: hover) {
  .icon-btn:not(.on):hover { background: rgba(127, 127, 127, 0.15); }
  .play-bar .icon-btn:not(.on):hover { background: var(--peach); border-color: var(--accent); }
}

/* ---------- front screens ---------- */

.wood {
  --cream: var(--ink);
  --cream-muted: var(--muted);
  color: var(--ink);
  background: var(--paper);
}
.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-deep);
}

/* ---------- logo: "Poozles" with two interlocking pieces for the o's ---------- */

.logo {
  display: inline-flex;
  align-items: baseline;
  font: 900 34px/1 var(--serif);
  font-variation-settings: 'SOFT' 100;
  color: var(--accent);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.logo-oo { width: 1.14em; height: 0.95em; margin: 0 0.03em; align-self: center; transform: translateY(0.06em); }

/* ---------- library ---------- */

.home-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 20px 12px;
}
.home-rule {
  max-width: calc(1100px - 40px);
  width: calc(100% - 40px);
  margin: 0 auto;
  border: 0;
  border-top: 1px solid var(--line);
}
.spacer { flex: 1; }
.avatar {
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--peach);
  color: var(--accent-deep);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.empty {
  max-width: 1100px;
  width: 100%;
  margin: 40px auto 0;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.empty-title { font: 650 26px/1.2 var(--serif); margin: 0 0 6px; }

.continue {
  max-width: 1100px;
  width: 100%;
  margin: 14px auto 0;
  padding: 0 20px;
}
.continue-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px;
  border-radius: 20px;
  background: var(--peach);
  color: var(--ink);
  transition: transform 0.2s ease;
}
.continue-card:active { transform: scale(0.99); }
.continue-img { flex: 0 0 200px; height: 130px; border-radius: 12px; overflow: hidden; background: #eee; }
.continue-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.continue-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.continue-title { font: 650 24px/1.15 var(--serif); }
.continue-btn { flex: none; min-height: 48px; padding: 0 28px; }
@media (max-width: 600px) {
  .continue-card { flex-wrap: wrap; gap: 12px; }
  .continue-img { flex: 0 0 110px; height: 80px; }
  .continue-title { font-size: 19px; }
  .continue-btn { flex: 1 0 100%; min-height: 44px; }
}

.lib-head {
  max-width: 1100px;
  width: 100%;
  margin: 26px auto 0;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.join-link { font-size: 15px; padding: 6px 4px; white-space: nowrap; }
.notice-card { text-align: center; }
.notice-card .primary { min-width: 120px; min-height: 46px; }
.code-input { text-align: center; font: 700 22px/1 ui-monospace, Menlo, monospace; letter-spacing: 0.2em; text-transform: uppercase; }
.lib-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
@media (max-width: 520px) {
  .lib-title-row h2 { flex-basis: 100%; }
  .lib-title-row .spacer { display: none; }
  .lib-title-row .join-link { margin-right: auto; }
}
.new-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}
@media (hover: hover) {
  .new-btn:hover { background: var(--peach); }
}
.lib-head h2 { white-space: nowrap; }
.new-short { display: none; }
@media (max-width: 420px) {
  .new-long { display: none; }
  .new-short { display: inline; }
}
.lib-head h2 { font: 650 22px/1.2 var(--serif); margin: 0; }
.lib-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.filter span { margin-left: 6px; color: var(--muted); font-weight: 500; }
.filter.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter.on span { color: rgba(255, 255, 255, 0.8); }
.lib-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px 20px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}
@media (min-width: 700px) {
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  transition: transform 0.2s ease;
}
@media (hover: hover) {
  .card:hover { transform: translateY(-3px); }
}
.card:active { transform: scale(0.98); }
.card-img { position: relative; aspect-ratio: 4 / 3; background: #eee5dc; border-radius: 14px; overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #2a9d8f;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.badge.shared { left: 8px; right: auto; background: #fff; color: var(--accent-deep); }
.card-body { padding: 6px 30px 0 2px; }
.card-title {
  font-weight: 650;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { font-size: 13px; color: var(--muted); margin-top: 1px; }
.progress {
  height: 5px;
  border-radius: 5px;
  background: #f1e6df;
  margin-top: 8px;
  overflow: hidden;
}
.progress.big { height: 7px; background: #fff; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.card-del {
  position: absolute;
  right: -4px;
  bottom: -2px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #b3a89c;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.card-del:hover { color: var(--accent); background: rgba(239, 90, 76, 0.1); }

/* ---------- welcome (signed out) ---------- */

.welcome-signin { font-size: 16px; padding: 8px 4px; }
.welcome { text-align: center; padding: 34px 20px 0; }
.welcome h1 { margin: 0; font: 650 clamp(34px, 6.2vw, 66px) / 1.05 var(--serif); color: var(--ink); letter-spacing: -0.01em; }
.welcome-sub { margin: 12px 0 0; font-size: clamp(18px, 2.4vw, 26px); color: var(--ink); }
.welcome-ctas { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; margin-top: 24px; }
.welcome-ctas button { min-height: 54px; padding: 0 30px; font-size: 17px; gap: 10px; }
.welcome-outline { background: #fff; border: 1.5px solid var(--accent); color: var(--accent); min-width: 200px; }
.welcome-pieces {
  display: block;
  width: 100%;
  max-width: 1536px;
  height: clamp(230px, 40vw, 590px);
  margin: 26px auto 0;
  object-fit: cover;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 6%, #000 94%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 6%, #000 94%, transparent);
}

/* Desktop: everything on the home page a size up */
@media (min-width: 900px) {
  .home-bar { max-width: 1240px; padding: calc(26px + env(safe-area-inset-top)) 32px 18px; }
  .home-rule { max-width: calc(1240px - 64px); width: calc(100% - 64px); }
  .home-bar .logo { font-size: 46px; }
  .welcome-signin { font-size: 18px; }
  .avatar { width: 46px; height: 46px; }
  .avatar svg { width: 24px; height: 24px; }
  .cloud-pill { height: 40px; padding: 0 18px; font-size: 16px; }
  .continue, .lib-head, .lib-grid, .empty { max-width: 1240px; padding-left: 32px; padding-right: 32px; }
  .continue { margin-top: 30px; }
  .continue-card { padding: 22px 26px 22px 22px; gap: 30px; border-radius: 24px; }
  .continue-img { flex-basis: 260px; height: 172px; border-radius: 14px; }
  .eyebrow { font-size: 15px; }
  .continue-title { font-size: 32px; }
  .continue-card .card-meta { font-size: 16px; }
  .continue-btn { min-height: 58px; padding: 0 38px; font-size: 19px; }
  .lib-head { margin-top: 38px; }
  .lib-head h2 { font-size: 30px; }
  .filter { height: 40px; padding: 0 16px; font-size: 15px; }
  .lib-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; padding-top: 22px; }
  .card-title { font-size: 18px; }
  .card-meta { font-size: 15px; }
  .new-btn { height: 50px; padding: 0 24px; font-size: 17px; }
}

/* ---------- new puzzle ---------- */

.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
}
.bar h2 { font: 650 24px/1.2 var(--serif); margin: 0 0 0 4px; }

.new-body {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 20px;
  display: flex;
  flex-direction: column;
}
.photo-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 320px;
  border: 2px dashed var(--accent);
  border-radius: 22px;
  background: var(--peach);
  cursor: pointer;
  text-align: center;
  padding: 24px;
  transition: border-color 0.2s, transform 0.2s;
}
.photo-drop strong { font: 650 26px/1.2 var(--serif); }
.drop-sub { color: var(--cream-muted); max-width: 300px; }
.drop-btn {
  margin-top: 14px;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}
.drop-pieces { position: relative; width: 150px; height: 90px; margin-bottom: 6px; }
.dp {
  position: absolute;
  filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.35));
  transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.dp1 { width: 62px; left: 8px; top: 18px; fill: #e9b949; transform: rotate(-16deg); }
.dp2 { width: 70px; left: 44px; top: 4px; fill: #c4553d; transform: rotate(6deg); z-index: 1; }
.dp3 { width: 58px; left: 88px; top: 22px; fill: #2a9d8f; transform: rotate(22deg); }
.photo-drop:hover, .photo-drop.over { border-color: var(--accent-deep); }
.photo-drop:hover .dp1, .photo-drop.over .dp1 { transform: translate(-8px, -6px) rotate(-28deg); }
.photo-drop:hover .dp2, .photo-drop.over .dp2 { transform: translateY(-10px) rotate(-4deg); }
.photo-drop:hover .dp3, .photo-drop.over .dp3 { transform: translate(8px, -4px) rotate(34deg); }
.photo-drop.busy { opacity: 0.6; pointer-events: none; }

.preview-wrap { display: flex; flex-direction: column; align-items: center; }
.preview-wrap canvas {
  border-radius: 6px;
  border: 8px solid #2a231d;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 20px 50px rgba(0, 0, 0, 0.45);
  max-width: 100%;
  box-sizing: content-box;
}


.panel {
  margin-top: 8px;
  padding: 4px 18px 18px;
  border-radius: 20px;
  background: var(--peach);
}
.field { margin-top: 16px; }
.label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
  display: block;
}
.wood .label { color: var(--accent-deep); }
.detail { color: var(--cream-muted); }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 10px; }
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 9px 6px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
.chip strong { font: 650 20px/1.1 var(--serif); }
.chip span { font-size: 12px; opacity: 0.75; }
.chip:active { transform: scale(0.96); }
.chip.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-2px);
}
.text {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 16px; /* 16px stops iOS zooming into the field */
}
.text:focus { outline: none; border-color: var(--accent); }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: #fff;
  cursor: pointer;
}
.switch-row > span { display: flex; flex-direction: column; gap: 2px; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: #e4d8cd;
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

#start-btn { margin-top: 6px; min-height: 56px; font-size: 17px; }

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

.play { background: #fff; }
/* No bar: round buttons float over the board (back on the left; picture and settings on
   the right), so the pieces get the whole screen. */
.play-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none; /* the board underneath stays draggable between the buttons */
}
.play-bar > * { pointer-events: auto; }
#btn-fit { margin-left: auto; } /* pushes zoom-out, picture and settings to the right */
.play-logo, .play-divider, .play-title { display: none; }
/* Wider screens: time and piece count in a pill beside the back button. Phones skip it. */
.play-info {
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(60, 30, 10, 0.2);
}
.play-info .play-sub { font-size: 14px; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
/* Settings → Button size scales every floating control. */
.play-bar > .icon-btn, .play-info, .players, .table-tools, .tray-views { zoom: var(--btn, 1); }
/* Wider screens: what the tray shows, bottom-right (same choice as in the Pieces view) */
.tray-views {
  position: absolute;
  /* positions are divided by the button size, since zoom also scales them */
  right: calc(12px / var(--btn, 1));
  bottom: calc((var(--tray-h, 112px) + 10px) / var(--btn, 1));
  background: #fff;
  box-shadow: 0 2px 8px rgba(60, 30, 10, 0.18);
}
@media (max-width: 520px) {
  .play-info, .wide-only { display: none !important; }
  #btn-ghost { margin-left: auto; } /* zoom-out is hidden on phones */
}
.play-bar .icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(60, 30, 10, 0.2);
}
.play-bar .icon-btn:first-child { color: var(--ink); }
.players { display: flex; flex: none; margin-left: 8px; align-items: center; }
.player.more { background: #fff; color: var(--accent-deep); font-size: 12px; box-shadow: 0 2px 8px rgba(60, 30, 10, 0.2); }
.player {
  width: 36px;
  height: 36px;
  margin-left: -6px;
  border: 2px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.play-line { position: absolute; top: 0; left: 0; right: 0; z-index: 4; height: 3px; background: rgba(255, 255, 255, 0.45); }
.play-line i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

.menu {
  position: absolute;
  right: 10px;
  top: calc(100% + 6px);
  width: 240px;
  padding: 14px;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(60, 30, 10, 0.22);
  z-index: 5;
}
.menu .label { color: var(--accent-deep); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.12);
  background: #444 center / cover;
  cursor: pointer;
}
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.slider-row input { flex: 1; accent-color: var(--accent); }
.slider-sm { font-size: 12px; opacity: 0.7; }
.slider-lg { font-size: 20px; opacity: 0.7; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 6px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  cursor: pointer;
  text-align: left;
}
.menu-item:not(.on) { opacity: 0.6; }

.play-area {
  position: relative;
  flex: 1;
  overflow: hidden;
}
#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--bar-ink);
  background: var(--bar);
}

/* ---------- cloud status ---------- */

.cloud-pill {
  max-width: 50%;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.cloud-pill[data-state='signed-out'], .cloud-pill[data-state='update'] { background: var(--accent); color: #fff; cursor: pointer; }
.cloud-pill[data-state='offline'] { color: var(--accent-deep); }
.conflict {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 12, 10, 0.55);
}
.conflict-card {
  width: min(360px, 100%);
  padding: 20px;
  border-radius: 18px;
  background: #fbf6ec;
  color: #2b2622;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.conflict-card strong { font: 650 20px/1.2 var(--serif); }
.conflict-card p { margin: 6px 0 16px; color: #7a6f64; }
.conflict-actions { display: flex; gap: 10px; }
.conflict-actions button { flex: 1; min-height: 46px; padding: 0 12px; }

.signin-card { text-align: center; }
.signin-buttons { display: flex; flex-direction: column; align-items: center; gap: 12px; min-height: 44px; }
.apple-btn { width: 280px; height: 44px; cursor: pointer; }
.native-signin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 280px;
  height: 46px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.native-signin.apple { background: #000; color: #fff; border: 0; }
.native-signin.google { background: #fff; color: #1f1f1f; border: 1px solid #dadce0; }
#signin-dev { width: 280px; min-height: 44px; }
.signin-note { font-size: 13px; margin-top: 14px !important; margin-bottom: 0 !important; }
.signin-card .error { min-height: 0; }
.share-card { text-align: center; }
.share-link {
  margin: 4px 0 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--peach);
  color: var(--ink);
  font-weight: 600;
  word-break: break-all;
  user-select: all;
}
.share-code-row { font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.share-code { font: 700 18px/1 ui-monospace, Menlo, monospace; letter-spacing: 0.12em; color: var(--ink); margin-left: 4px; }
.link-btn.danger { display: block; margin: 10px auto 0; color: #a33b28; font-size: 14px; }

/* ---------- all-pieces view ---------- */

/* tools floating above the tray */
.table-tools {
  position: absolute;
  left: calc(12px / var(--btn, 1));
  bottom: calc((var(--tray-h, 112px) + 10px) / var(--btn, 1));
  display: flex;
  gap: 6px;
}
/* phones: round icon buttons; their names show on hover/long-press (title) */
@media (max-width: 520px) {
  .table-tools { gap: 8px; }
  .table-tools .tool-pill { width: 44px; height: 44px; padding: 0; justify-content: center; }
  .table-tools .tool-pill span { display: none; }
  .table-tools .tool-pill svg { width: 21px; height: 21px; }
}
.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 13px 0 10px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(60, 30, 10, 0.18);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.tool-pill svg { color: var(--accent); }
.tool-pill.on { background: var(--accent); color: #fff; }
.tool-pill.on svg { color: #fff; }
.tool-pill:active { transform: scale(0.96); }

/* sort tab sitting just above the tray */
.tray-sort {
  position: absolute;
  right: 12px;
  bottom: calc(var(--tray-h, 112px) + 10px);
  z-index: 1;
  height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(60, 30, 10, 0.18);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tray-sort.on { background: var(--accent); color: #fff; }
/* phones: not enough room beside Pieces / Select / Tidy, so sit one row up */
.tray-sort svg { color: var(--accent); flex: none; }
.tray-sort.on svg { color: #fff; }
/* phones: just the palette icon, in the same row as Pieces / Select / Tidy */
@media (max-width: 520px) {
  .tray-sort { width: 36px; padding: 0; justify-content: center; }
  .tray-sort span { display: none; }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tray-h, 112px) + 58px);
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(24, 19, 15, 0.88);
  color: #f3ece0;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.pieces-panel {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: var(--ink);
  animation: slide-up 0.22s ease;
}
.pieces-bar { background: #fff; padding-top: calc(10px + env(safe-area-inset-top)); }
.pieces-bar .icon-btn { color: var(--ink); }
.pieces-title { font-weight: 650; font-size: 17px; margin-left: 4px; }
.pieces-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 14px 6px;
  flex-wrap: wrap;
}
.pieces-tools input[type='range'] { flex: 1; min-width: 90px; accent-color: var(--accent); }
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--peach);
}
.seg button {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.seg button span { margin-left: 3px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }
.seg button.on span { color: rgba(255, 255, 255, 0.85); }
.pieces-hint { margin: 0; padding: 0 16px 8px; font-size: 13px; color: var(--muted); }
.pieces-scroll {
  position: relative;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border-top: 4px solid #F6C7B3; /* the same peach line as above the tray */
}
#pieces-canvas {
  position: sticky;
  top: 0;
  display: block;
  width: 100%;
  /* press-and-hold moves a piece; no iPhone text-selection magnifier or menu */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.pieces-foot {
  display: flex;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
}
.pieces-foot .primary { flex: 1.3; }
.pieces-foot .secondary { flex: 1; border-color: var(--accent); color: var(--accent-deep); }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } }

/* ---------- completion ---------- */

.complete {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 12, 10, 0.55);
  animation: fade 0.3s ease;
}
.complete-card {
  position: relative;
  width: min(380px, 100%);
  padding: 18px 18px 22px;
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.complete-card img { width: 100%; border-radius: 12px; display: block; }
.complete-card h2 { font: 650 28px/1.2 var(--serif); margin: 16px 0 4px; }
.complete-card p { margin: 0 0 18px; }
.complete-actions { display: flex; gap: 10px; justify-content: center; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { top: 110%; transform: rotate(720deg) translateX(40px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
