/* Art Reverie — web / YouTube Playables build.
   Palette and type follow the iOS app's MuseumTheme and CanvasNotePalette. */

:root {
  --ink: #13181f;
  --charcoal: #1c2229;
  --paper: #ede0c4;
  --muted-paper: #b8ab91;
  --terracotta: #b85940;
  --canvas: #ddd1b8;
  --canvas-shadow: #85755c;
  --note-ink: #181612;
  --faded-ink: #4d4233;
  --note-edge: rgba(107, 89, 66, 0.7);
  --paper-patch: rgba(245, 230, 199, 0.42);
  --tape: rgba(209, 189, 145, 0.58);
  --terracotta-text: #c9846a;
  --accent: var(--terracotta);
  --accent-text: var(--terracotta-text);
  --pack-accent: var(--terracotta);
  --pack-accent-text: var(--terracotta-text);

  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  --script: "Snell Roundhand", "Apple Chancery", "Segoe Script", "Dancing Script", cursive;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --drop-ease: cubic-bezier(0.38, 0.02, 0.58, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:focus-visible, .art-card:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 3px;
}

#app {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen.dropping {
  transform-origin: 0 0;
  transform: translate(var(--drop-x, 0px), calc(100% + 90px)) rotate(var(--drop-rotation, 0deg));
  box-shadow: 0 -12px 22px rgba(0, 0, 0, 0.4);
  transition: transform 820ms var(--drop-ease), box-shadow 820ms var(--drop-ease);
  pointer-events: none;
}

.paper-bg {
  background:
    radial-gradient(520px circle at 0 0, rgba(77, 97, 110, 0.13), transparent 70%),
    linear-gradient(135deg, rgba(31, 38, 46, 0.72), rgba(14, 19, 26, 0.82)),
    var(--ink);
}

.measuring-room {
  position: absolute;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------------------------------------------------------------- Loading */

.loading-screen {
  align-items: center;
  justify-content: center;
  background: var(--ink);
  z-index: 100;
  transition: opacity 400ms ease;
}

.loading-screen.gone { opacity: 0; pointer-events: none; }

.wordmark {
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 5px;
  color: var(--muted-paper);
}

.loading-rule {
  width: 120px;
  height: 1px;
  margin-top: 16px;
  background: rgba(237, 224, 196, 0.12);
  overflow: hidden;
}

.loading-rule span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--terracotta);
  transition: width 200ms ease;
}

/* ------------------------------------------------------------ Icon button */

.icon-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--paper);
  flex: none;
}

.icon-button svg { width: 20px; height: 20px; }

.text-button {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  color: var(--paper);
  padding: 6px 4px;
  min-height: 48px;
}

.text-button.muted { color: var(--muted-paper); }
.text-button:active { opacity: 0.45; }

.eyebrow {
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2.6px;
  color: var(--terracotta-text);
}

.eyebrow.light { font-size: 10px; color: var(--muted-paper); }

/* ------------------------------------------------------------ Level card */

.stage-screen {
  align-items: center;
  justify-content: center;
  background: var(--ink);
}

.level-screen { cursor: pointer; }
.level-screen:focus { outline: none; }

.fit { transform: scale(var(--fit, 1)); }

.stage-screen::before {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: radial-gradient(430px circle at center, var(--accent), transparent 100%);
  opacity: 0.16;
}

.level-card {
  position: relative;
  width: 260px;
  height: 350px;
  border-radius: 28px;
  background: var(--charcoal);
  border: 1px solid rgba(237, 224, 196, 0.16);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.46);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  animation: card-in 600ms cubic-bezier(0.2, 0.8, 0.2, 1), card-float 7s ease-in-out 600ms infinite;
}

.level-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.level-pack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.level-pack-title {
  font-family: var(--serif);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2.1px;
  color: var(--muted-paper);
  text-transform: uppercase;
  white-space: nowrap;
}

.ornament {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--pack-accent);
  opacity: 0.8;
}

.ornament i {
  display: block;
  width: 34px;
  height: 0.5px;
  background: currentColor;
}

.ornament b {
  display: block;
  width: 5px;
  height: 5px;
  background: currentColor;
  transform: rotate(45deg);
}

.level-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3.4px;
  color: var(--pack-accent-text);
}

.level-number {
  font-family: var(--serif);
  font-size: 116px;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  color: var(--paper);
}

.screen-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(34px + var(--safe-bottom));
  text-align: center;
  font-size: 12px;
  letter-spacing: 1.3px;
  color: var(--muted-paper);
}

@keyframes card-in {
  from { opacity: 0; transform: perspective(700px) translateY(14px) scale(0.88); }
}

@keyframes card-float {
  0%, 100% { transform: perspective(700px) rotateX(1.6deg) rotateY(-2.2deg); }
  50% { transform: perspective(700px) rotateX(-1.6deg) rotateY(2.2deg); }
}

/* ----------------------------------------------------------- Puzzle screen */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 18px 0;
  flex: none;
  position: relative;
  z-index: 5;
}

.board-host {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 18px 0 calc(18px + var(--safe-bottom));
}

.board {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  touch-action: none;
}

.piece {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell-w);
  height: var(--cell-h);
  transition: transform 220ms cubic-bezier(0, 0, 0.58, 1);
  will-change: transform;
  perspective: 900px;
  cursor: grab;
}

.board.no-anim .piece, .piece.dragging { transition: none; }
.piece.dragging { cursor: grabbing; }

.piece::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  border: 0.75px solid rgba(28, 34, 41, 0.82);
  pointer-events: none;
  transition: opacity 180ms ease;
}

.piece.joined::after { opacity: 0; }

.board:focus { outline: none; }

/* Keyboard cursor: only shown once the player starts using the keyboard. */
.piece::before {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 3;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3px rgba(19, 24, 31, 0.6);
  opacity: 0;
  transition: opacity 120ms ease;
}

.board.keyboard .piece.cursor::before { opacity: 1; }

.piece-flip {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform-style: preserve-3d;
  transition: transform 420ms ease-in-out;
}

.board.story .piece-flip { transform: rotateY(180deg); }

.face {
  position: absolute;
  top: -0.5px; right: -0.5px; bottom: -0.5px; left: -0.5px;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.face.front {
  background-color: var(--charcoal);
  background-repeat: no-repeat;
}

.face.back {
  transform: rotateY(180deg);
  background: var(--canvas);
}

.note-window {
  position: absolute;
  left: 0;
  top: 0;
}

.drag-shadows {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 500;
  pointer-events: none;
}

.drag-shadow {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell-w);
  height: var(--cell-h);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.48);
  transition: opacity 220ms ease, transform 220ms cubic-bezier(0, 0, 0.58, 1);
}

.drag-shadow.fading { opacity: 0; }

/* Drag coach */

.coach {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 3000;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.coach.hidden { opacity: 0; }
.coach svg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: visible; }
.coach-dim { fill: rgba(0, 0, 0, 0.66); }
.coach-target { fill: none; stroke: rgba(237, 224, 196, 0.92); stroke-width: 1.6; stroke-dasharray: 7 5; }
.coach-source { fill: none; stroke: var(--terracotta); stroke-width: 2; }

.coach-finger {
  position: absolute;
  left: -20px;
  top: -20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(237, 224, 196, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
  animation: coach-drag 2.4s cubic-bezier(0.45, 0, 0.25, 1) infinite;
}

@keyframes coach-drag {
  0% { transform: translate(var(--from-x), var(--from-y)) scale(1.25); opacity: 0; }
  16% { transform: translate(var(--from-x), var(--from-y)) scale(0.9); opacity: 1; }
  23% { transform: translate(var(--from-x), var(--from-y)) scale(0.9); opacity: 1; }
  75% { transform: translate(var(--to-x), var(--to-y)) scale(0.9); opacity: 1; }
  80% { transform: translate(var(--to-x), var(--to-y)) scale(1.05); opacity: 1; }
  100% { transform: translate(var(--to-x), var(--to-y)) scale(1.2); opacity: 0; }
}

.coach-card {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 14px 20px;
  border-radius: 16px;
  background: rgba(28, 34, 41, 0.97);
  border: 1px solid rgba(237, 224, 196, 0.15);
  text-align: center;
}

.coach-body {
  margin-top: 7px;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-line;
  color: var(--paper);
}

@media (max-width: 360px) {
  .coach-card { padding: 10px 14px; }
  .coach-body { margin-top: 5px; font-size: 13px; line-height: 1.35; }
}

/* ------------------------------------------------------------ Studio note */

.note {
  --s: 1;
  --pad: 23px;
  --gap: 12px;
  --title: 27px;
  --body: 18px;
  --detail: 13px;
  --lead: 16px;
  --signature: 18px;
  position: relative;
  overflow: hidden;
  color: var(--note-ink);
}

.note.compact {
  --pad: 13px;
  --gap: 5px;
  --title: 20px;
  --body: 12.5px;
  --detail: 10.5px;
  --lead: 12px;
  --signature: 13px;
}

.note-texture {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background:
    radial-gradient(circle at center, transparent 35%, rgba(133, 117, 92, 0.14) 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.055) 0 0.6px, transparent 0.6px 2px, rgba(0, 0, 0, 0.045) 2px 2.6px, transparent 2.6px 4px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.045) 0 0.5px, transparent 0.5px 2px, rgba(255, 255, 255, 0.05) 2px 2.5px, transparent 2.5px 4px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 50%, rgba(133, 117, 92, 0.2)),
    var(--canvas);
}

.note-content {
  position: absolute;
  top: var(--pad); right: var(--pad); bottom: var(--pad); left: var(--pad);
  display: flex;
  flex-direction: column;
  gap: calc(var(--gap) * var(--s));
  overflow: hidden;
}

.note-eyebrow {
  font-size: calc(8px * var(--s));
  font-weight: 700;
  letter-spacing: 2.1px;
  color: var(--faded-ink);
}

.note-title {
  font-family: var(--script);
  font-size: calc(var(--title) * var(--s));
  line-height: 1.15;
  color: var(--note-ink);
}

.note-rule {
  display: block;
  width: 100%;
  height: 8px;
  flex: none;
  overflow: visible;
}

.note-rule path {
  fill: none;
  stroke: var(--accent);
  stroke-opacity: 0.72;
  stroke-width: 1.15;
}

.note-description {
  margin: 0;
  font-family: var(--serif);
  font-size: calc(var(--body) * var(--s));
  line-height: 1.32;
}

.note-detail {
  position: relative;
  padding: calc(11px * var(--s));
  background: var(--paper-patch);
}

.note.compact .note-detail { padding: calc(7px * var(--s)); }

.note-tape {
  position: absolute;
  left: 18px;
  top: -6px;
  width: 46px;
  height: 11px;
  background: var(--tape);
  transform: rotate(-4deg);
}

.note-detail-lead {
  font-family: var(--script);
  font-size: calc(var(--lead) * var(--s));
  color: var(--accent);
  margin-bottom: 4px;
}

.note-detail-text {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: calc(var(--detail) * var(--s));
  line-height: 1.3;
  color: rgba(24, 22, 18, 0.92);
}

.note-spacer { flex: 1 1 0; min-height: 0; }

.note-signature {
  font-family: var(--script);
  font-size: calc(var(--signature) * var(--s));
  text-align: right;
  white-space: nowrap;
  color: rgba(24, 22, 18, 0.88);
}

.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
}

.note-meta-item b {
  display: block;
  font-size: calc(12px * var(--s));
  font-weight: 600;
}

.note-meta-item span {
  display: block;
  margin-top: 3px;
  font-size: calc(8px * var(--s));
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--faded-ink);
}

.note-meta-item.right { text-align: right; max-width: 62%; }

.note-edge {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  border: 1.2px solid var(--note-edge);
  pointer-events: none;
}

.note.framed, .note.framed.compact { --pad: 19px; }

.note.framed .note-edge { top: 7px; right: 7px; bottom: 7px; left: 7px; border-radius: 17px; }

.note.panorama { --pad: 10%; }
.note.panorama .note-content { flex-direction: row; gap: 14px; }
.note-heading { flex: 1; min-width: 0; }
.note.panorama .note-title { font-size: calc(15px * var(--s)); }
.note-byline { font-family: var(--serif); font-size: calc(7.5px * var(--s)); font-weight: 700; }
.note.panorama .note-description { flex: 1; font-size: calc(10.5px * var(--s)); }

/* ----------------------------------------------------------- Artwork card */

.art-card {
  position: relative;
  transform: rotate(-0.7deg);
  perspective: 1400px;
  cursor: pointer;
  flex: none;
}

.art-card-flip {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform-style: preserve-3d;
  transition: transform 620ms cubic-bezier(0.3, 1.2, 0.4, 1);
}

.art-card.flipped .art-card-flip { transform: rotateY(180deg); }

.art-card-face {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  border-radius: 24px;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  display: flex;
  flex-direction: column;
}

.art-card-face.back { transform: rotateY(180deg); }

.art-card-image {
  flex: none;
  background-color: var(--ink);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.art-card-label {
  flex: 1;
  min-height: 0;
  padding: 0 18px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  color: var(--ink);
}

.art-card-original {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: rgba(28, 34, 41, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.art-card-title {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  line-height: 1.12;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.art-card-by {
  font-size: 12px;
  font-weight: 500;
  color: rgba(28, 34, 41, 0.75);
}

/* ------------------------------------------------------- Completion screen */

.completion-screen {
  background-color: var(--ink);
  transition: background-color 450ms ease;
}

.completion-screen.morph-from { background-color: rgba(19, 24, 31, 0); transition: none; }
.puzzle-screen.fading-out { opacity: 0; transition: opacity 300ms ease 300ms; }

.card-mover { transform-origin: 0 0; }
.card-mover.morphing { transition: transform 900ms cubic-bezier(0.22, 1, 0.36, 1); }
.card-mover.morph-start .art-card { transform: none; }
.card-mover.morph-start .art-card-face { border-radius: 0; box-shadow: none; }
.card-mover.morph-start .art-card-label { opacity: 0; }
.card-mover.morphing .art-card { transition: transform 900ms ease; }
.card-mover.morphing .art-card-face { transition: border-radius 700ms ease, box-shadow 800ms ease; }
.card-mover.morphing .art-card-label { transition: opacity 500ms ease 350ms; }

.completion-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: calc(16px + var(--safe-top));
}

.completion-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 20px calc(14px + var(--safe-bottom));
  transition: opacity 400ms ease;
}

.completion-screen.morph-from .completion-actions,
.completion-screen.morph-settling .completion-actions { opacity: 0; }

.completion-screen.wide { flex-direction: row; }
.completion-screen.wide .completion-stage { flex: 1 1 auto; padding-top: 0; }
.completion-screen.wide .completion-actions {
  width: min(42%, 380px);
  justify-content: center;
  padding: 20px 24px calc(20px + var(--safe-bottom)) 8px;
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--accent-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing svg { flex: none; width: 14px; height: 14px; }

.moves-note {
  margin-top: 2px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted-paper);
}

.coach-ring {
  padding-left: 24px;
  padding-right: 24px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1.5px var(--terracotta-text);
  animation: ring-pulse 2.2s ease-in-out infinite;
}

@keyframes ring-pulse {
  0%, 100% { box-shadow: inset 0 0 0 1.5px rgba(201, 132, 106, 0.45); }
  50% { box-shadow: inset 0 0 0 1.5px rgba(201, 132, 106, 1); }
}

/* ------------------------------------------------------- Overlays & sheets */

.overlay {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  background: rgba(0, 0, 0, 0.78);
  animation: fade-in 180ms ease;
}

.overlay-row { display: flex; gap: 12px; }

.overlay-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
  color: var(--paper);
  text-align: center;
  padding: 0 24px;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.sheet {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  animation: sheet-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet-header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: calc(12px + var(--safe-top)) 18px 10px;
}

.sheet-heading { flex: 1; min-width: 0; }

.sheet-title {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
}

.sheet-subtitle {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted-paper);
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: 8px 18px calc(24px + var(--safe-bottom));
}

.section-label {
  margin: 22px 0 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.4px;
  color: var(--muted-paper);
}

.section-label:first-child { margin-top: 6px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.setting-row + .setting-row { margin-top: 8px; }
.setting-row[aria-checked="true"].choice { border-color: var(--terracotta); background: rgba(184, 89, 64, 0.12); }

.setting-title { font-family: var(--serif); font-size: 17px; }
.setting-detail { margin-top: 3px; font-size: 12px; line-height: 1.35; color: var(--muted-paper); }

.choice-mark {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid rgba(237, 224, 196, 0.35);
  display: grid;
  place-items: center;
}

.setting-row[aria-checked="true"] .choice-mark { border-color: var(--terracotta); }
.setting-row[aria-checked="true"] .choice-mark::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--terracotta);
}

.switch {
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: rgba(237, 224, 196, 0.2);
  transition: background 180ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--paper);
  transition: transform 180ms ease;
}

.setting-row[aria-checked="true"] .switch { background: var(--terracotta); }
.setting-row[aria-checked="true"] .switch::after { transform: translateX(20px); }

.credits {
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted-paper);
}

.credits p { margin: 0 0 6px; }

/* Gallery */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.gallery-item {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: var(--charcoal);
  border: 1px solid rgba(237, 224, 196, 0.12);
  text-align: left;
}

.gallery-thumb {
  position: relative;
  height: 0;
  padding-top: 75%;
  background-color: var(--ink);
  background-size: cover;
  background-position: center;
}

.gallery-item.locked { cursor: default; }

.gallery-item.locked .gallery-thumb {
  background-image: repeating-linear-gradient(135deg, rgba(237, 224, 196, 0.05) 0 8px, transparent 8px 16px);
}

.gallery-thumb span {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: grid;
  place-items: center;
  padding: 0 10px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--muted-paper);
}

.gallery-caption { padding: 10px 12px 12px; }
.gallery-title { font-family: var(--serif); font-size: 15px; line-height: 1.2; }
.gallery-artist { margin-top: 3px; font-size: 11px; color: var(--muted-paper); }
.gallery-item.locked .gallery-title { color: var(--muted-paper); }

.detail-view {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  animation: fade-in 200ms ease;
}

.detail-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 20px calc(18px + var(--safe-bottom));
}

/* Gallery coach */

.gallery-coach {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.68);
  animation: fade-in 250ms ease;
  cursor: pointer;
}

.icon-button.replica { position: absolute; background: var(--charcoal); border-color: rgba(255, 255, 255, 0.16); }

.gallery-coach-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.6px solid var(--terracotta);
  animation: coach-ring 1.3s ease-out infinite;
}

@keyframes coach-ring {
  from { transform: scale(1.05); opacity: 0.9; }
  to { transform: scale(1.5); opacity: 0.2; }
}

.gallery-coach-card {
  position: absolute;
  left: 18px;
  max-width: 300px;
  padding: 18px;
  border-radius: 18px;
  background: rgba(28, 34, 41, 0.97);
  border: 1px solid rgba(237, 224, 196, 0.15);
}

.gallery-coach-card p {
  margin: 8px 0 8px;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.4;
}

.gallery-coach-card small { font-size: 11px; color: var(--muted-paper); }

/* Collection complete */

.finale-card {
  position: relative;
  transform: scale(var(--fit-tall, 1));
  width: min(300px, calc(100% - 48px));
  padding: 34px 26px 28px;
  border-radius: 28px;
  background: var(--charcoal);
  border: 1px solid rgba(237, 224, 196, 0.16);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.46);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.finale-title { font-family: var(--serif); font-size: 28px; line-height: 1.15; }
.finale-body { font-family: var(--serif); font-size: 16px; line-height: 1.45; color: var(--muted-paper); }

.finale-strip {
  display: grid;
  grid-template-columns: repeat(4, 38px);
  justify-content: center;
  gap: 6px;
}
.finale-strip span {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(237, 224, 196, 0.2);
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } }

@media (prefers-reduced-motion: reduce) {
  .level-card, .coach-finger, .coach-ring, .gallery-coach-ring { animation: none; }
  .piece-flip, .art-card-flip { transition-duration: 1ms; }
  .screen.dropping { transform: none; opacity: 0; transition: opacity 200ms ease; }
}

/* YouTube has paused the game: all motion and input stop until onResume. */
#app.yt-paused, #app.yt-paused * { animation-play-state: paused !important; }
#app.yt-paused { pointer-events: none; }

/* Short, wide viewports (e.g. 21:9 and 32:9): the toolbar floats in the
   corners so the painting can use the full height, and the level card turns
   sideways instead of shrinking its type. */
@media (min-aspect-ratio: 8/5) and (max-height: 560px) {
  .puzzle-screen .toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding-top: calc(12px + var(--safe-top));
  }
  .puzzle-screen .board-host { margin: 12px 80px calc(12px + var(--safe-bottom)); }
}

@media (max-height: 480px) {
  .level-card {
    width: 420px;
    height: 220px;
    flex-direction: row;
    gap: 34px;
  }
  .level-meta, .level-meta .level-pack { align-items: flex-start; }
  .level-number { font-size: 104px; }
  .screen-hint { bottom: calc(16px + var(--safe-bottom)); }
}
