/*
  Daily Pieces interface
  ----------------------
  This stylesheet controls the complete responsive game UI, puzzle workspace,
  dialogs, progress states, drag feedback, and completion celebration.
*/

:root {
  color-scheme: light;
  --paper: #f6f0e8;
  --paper-deep: #eee4d7;
  --card: rgba(255, 253, 249, 0.94);
  --card-solid: #fffdf9;
  --ink: #25231f;
  --muted: #766f65;
  --line: rgba(45, 40, 33, 0.13);
  --line-strong: rgba(45, 40, 33, 0.22);
  --accent: #d95f40;
  --accent-dark: #ac4028;
  --accent-soft: #f7ded4;
  --green: #48745d;
  --workspace: #e9e0d4;
  --shadow: 0 22px 70px rgba(57, 45, 31, 0.12);
  --small-shadow: 0 8px 24px rgba(57, 45, 31, 0.1);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --stage-scale: 1;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(217, 95, 64, 0.12), transparent 30rem),
    radial-gradient(circle at 92% 12%, rgba(72, 116, 93, 0.09), transparent 26rem),
    linear-gradient(180deg, #faf6ef 0%, var(--paper) 48%, var(--paper-deep) 100%);
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(217, 95, 64, 0.35);
  outline-offset: 3px;
}

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 45px;
  height: 45px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--card-solid);
  background: var(--ink);
  box-shadow: var(--small-shadow);
}

.brand-mark svg {
  width: 31px;
  fill: currentColor;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
}

.header-actions,
.toolbar-actions,
.game-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.text-button,
.button {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
}

.icon-button:hover,
.text-button:hover,
.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.icon-button:active,
.text-button:active,
.button:active:not(:disabled) {
  transform: translateY(0);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: rgba(255, 253, 249, 0.72);
  border: 1px solid var(--line);
  border-radius: 13px;
}

.icon-button svg,
.text-button svg,
.button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.game-card {
  overflow: hidden;
  padding: clamp(20px, 3vw, 36px);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.daily-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.035em;
}

h1 {
  max-width: 760px;
  margin-bottom: 8px;
  font-size: clamp(2rem, 4.8vw, 4.4rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 12px;
  font-size: clamp(1.7rem, 4vw, 2.45rem);
  line-height: 1.05;
}

.subheading {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.countdown-card {
  min-width: 160px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  text-align: right;
}

.countdown-card span,
.countdown-card strong {
  display: block;
}

.countdown-card span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.countdown-card strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  letter-spacing: 0.03em;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 30px 0 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.score-item {
  position: relative;
  padding: 15px 20px;
}

.score-item + .score-item::before {
  content: "";
  position: absolute;
  inset: 14px auto 14px 0;
  width: 1px;
  background: var(--line);
}

.score-item span,
.score-item strong {
  display: block;
}

.score-item > span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.score-item strong {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.score-item strong .streak-flame,
.score-item strong #streak {
  display: inline;
}

.streak-flame {
  margin-left: 4px;
  font-size: 0.95rem;
}

.puzzle-toolbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.progress-copy {
  width: min(360px, 48%);
}

.progress-copy > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  background: var(--paper-deep);
  border-radius: 999px;
}

.progress-track span {
  width: 0;
  height: 100%;
  display: block;
  background: var(--green);
  border-radius: inherit;
  transition: width 300ms ease;
}

.text-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 11px;
  color: var(--muted);
  background: transparent;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 750;
}

.text-button:hover {
  color: var(--ink);
  background: var(--paper);
}

.text-button svg {
  width: 18px;
  height: 18px;
}

.workspace-viewport {
  position: relative;
  width: 100%;
  overflow: hidden;
  margin-top: 10px;
  background:
    linear-gradient(rgba(255,255,255,.1), rgba(255,255,255,.1)),
    repeating-linear-gradient(45deg, rgba(73, 62, 48, 0.025) 0 1px, transparent 1px 11px),
    var(--workspace);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
}

.workspace-stage {
  position: relative;
  width: 1100px;
  height: 800px;
  overflow: hidden;
  transform: scale(var(--stage-scale));
  transform-origin: top left;
  touch-action: none;
}

.assembly-guide {
  position: absolute;
  left: 270px;
  top: 120px;
  width: 560px;
  height: 560px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(67, 58, 46, 0.14);
  border-radius: 24px;
  pointer-events: none;
}

.assembly-guide::before,
.assembly-guide::after {
  content: "";
  position: absolute;
  background: rgba(67, 58, 46, 0.07);
}

.assembly-guide::before {
  width: 1px;
  height: 100%;
}

.assembly-guide::after {
  width: 100%;
  height: 1px;
}

.assembly-guide span {
  padding: 7px 11px;
  color: rgba(67, 58, 46, 0.34);
  background: var(--workspace);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.pieces-layer {
  position: absolute;
  inset: 0;
}

.piece {
  position: absolute;
  cursor: grab;
  user-select: none;
  touch-action: none;
  will-change: transform;
}

.piece:active,
.piece.is-dragging {
  cursor: grabbing;
}

.piece-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 7px 5px rgba(51, 42, 31, 0.2));
  transition: filter 120ms ease, transform 120ms ease;
  pointer-events: none;
}

.piece.is-dragging .piece-svg {
  filter: drop-shadow(0 15px 10px rgba(51, 42, 31, 0.26));
  transform: translateY(-3px);
}

.piece.is-snapping .piece-svg {
  animation: snap-pop 250ms ease;
}

.piece-outline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.74);
  stroke-width: 1.7;
  vector-effect: non-scaling-stroke;
}

.drag-hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 500;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  color: rgba(37, 35, 31, 0.7);
  background: rgba(255, 253, 249, 0.86);
  border: 1px solid rgba(45, 40, 33, 0.1);
  border-radius: 999px;
  box-shadow: 0 5px 18px rgba(49, 41, 31, 0.08);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

.drag-hint.is-hidden {
  opacity: 0;
  transform: translate(-50%, 10px);
}

.game-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 18px;
  border-radius: 13px;
  font-size: 0.88rem;
  font-weight: 800;
}

.button svg {
  width: 19px;
  height: 19px;
}

.button-primary {
  color: white;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(172, 64, 40, 0.2);
}

.button-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: 0 11px 24px rgba(172, 64, 40, 0.24);
}

.button-secondary {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--paper-deep);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
}

.button-full {
  width: 100%;
}

.site-footer {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: var(--muted);
  font-size: 0.73rem;
}

.modal {
  width: min(520px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  overflow: visible;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
}

.modal::backdrop {
  background: rgba(31, 28, 24, 0.5);
  backdrop-filter: blur(7px);
}

.modal[open] {
  animation: modal-in 180ms ease both;
}

.modal-card {
  position: relative;
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 30px;
  background: var(--card-solid);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 24px;
  box-shadow: 0 28px 90px rgba(28, 24, 19, 0.3);
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 3;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.instruction-list {
  display: grid;
  gap: 18px;
  margin: 26px 0;
}

.instruction {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 13px;
}

.instruction-number {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: 11px;
  font-weight: 850;
}

.instruction strong {
  display: block;
  margin: 1px 0 3px;
}

.instruction p,
.win-subtitle,
.next-puzzle-copy {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.modal-copy {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.modal-actions .button {
  flex: 1;
}

.modal-note {
  margin: 0 0 22px;
  padding: 14px 15px;
  color: var(--muted);
  background: var(--paper);
  border-left: 3px solid var(--green);
  border-radius: 0 12px 12px 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.modal-note strong {
  color: var(--ink);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 24px 0;
}

.stats-grid div {
  padding: 15px 8px;
  text-align: center;
  background: var(--paper);
  border-radius: 13px;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid strong {
  margin-bottom: 4px;
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.2;
}

.stats-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}

.stats-detail span {
  color: var(--muted);
}

.stats-detail + .button {
  margin-top: 20px;
}

.preview-modal {
  width: min(720px, calc(100% - 28px));
}

.preview-modal .modal-card {
  padding: 14px;
}

.modal-close-on-image {
  color: white;
  background: rgba(28, 24, 19, 0.5);
  border-color: rgba(255,255,255,.25);
  backdrop-filter: blur(8px);
}

.preview-frame,
.win-picture {
  overflow: hidden;
  background: var(--paper-deep);
  border-radius: 17px;
}

.preview-frame {
  aspect-ratio: 1;
}

.preview-frame img,
.win-picture img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.preview-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 10px 7px;
}

.preview-caption h2,
.preview-caption .eyebrow {
  margin-bottom: 0;
}

.win-modal {
  text-align: center;
}

.win-badge {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin: 0 auto 17px;
  color: white;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(72,116,93,.24);
  font-size: 1.5rem;
  font-weight: 900;
}

.win-picture {
  width: min(310px, 100%);
  aspect-ratio: 1;
  margin: 22px auto;
  box-shadow: var(--small-shadow);
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.win-stats div {
  position: relative;
  padding: 14px 8px;
}

.win-stats div + div::before {
  content: "";
  position: absolute;
  inset: 12px auto 12px 0;
  width: 1px;
  background: var(--line);
}

.win-stats span,
.win-stats strong {
  display: block;
}

.win-stats span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.win-stats strong {
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.next-puzzle-copy {
  margin-top: 14px;
  text-align: center;
}

.day-rollover {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 1400;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 12px 14px 12px 20px;
  background: var(--card-solid);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 650;
}

.day-rollover[hidden] {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 1500;
  transform: translate(-50%, 18px);
  padding: 11px 16px;
  color: white;
  background: rgba(37, 35, 31, 0.95);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(28,24,19,.22);
  opacity: 0;
  pointer-events: none;
  font-size: 0.82rem;
  font-weight: 750;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 999;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  animation: confetti-fall var(--duration) cubic-bezier(.15,.62,.25,1) var(--delay) forwards;
}

@keyframes snap-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.045); }
  100% { transform: scale(1); }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes confetti-fall {
  0% { transform: translate3d(0, -4vh, 0) rotate(0); opacity: 1; }
  100% { transform: translate3d(var(--drift), 108vh, 0) rotate(var(--spin)); opacity: 0.9; }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1240px);
  }

  .topbar {
    min-height: 76px;
  }

  .brand small {
    display: none;
  }

  .brand strong {
    font-size: 1.15rem;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .game-card {
    padding: 18px 14px 16px;
    border-radius: 22px;
  }

  .daily-heading {
    align-items: flex-end;
    gap: 12px;
  }

  h1 {
    font-size: clamp(2rem, 10vw, 3.1rem);
  }

  .countdown-card {
    min-width: 112px;
    padding: 10px 11px;
  }

  .countdown-card span {
    font-size: 0.58rem;
  }

  .countdown-card strong {
    font-size: 0.93rem;
  }

  .score-strip {
    margin-top: 22px;
  }

  .score-item {
    padding: 12px 8px;
    text-align: center;
  }

  .score-item > span {
    font-size: 0.58rem;
  }

  .score-item strong {
    font-size: 1.02rem;
  }

  .puzzle-toolbar {
    min-height: 46px;
  }

  .progress-copy {
    width: 46%;
  }

  .toolbar-actions {
    gap: 0;
  }

  .text-button {
    padding-inline: 8px;
    font-size: 0.74rem;
  }

  .text-button svg {
    width: 16px;
  }

  .drag-hint {
    bottom: 12px;
    padding: 8px 10px;
    font-size: 10px;
  }

  .game-actions {
    justify-content: stretch;
  }

  .game-actions .button {
    flex: 1;
  }

  .site-footer {
    min-height: 66px;
    justify-content: center;
    text-align: center;
  }

  .site-footer span:last-child {
    display: none;
  }

  .modal-card {
    padding: 24px 20px;
    border-radius: 20px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .preview-modal .modal-card {
    padding: 10px;
  }

  .preview-caption {
    align-items: flex-end;
    padding: 16px 5px 4px;
  }

  .preview-caption h2 {
    font-size: 1.45rem;
  }
}

@media (max-width: 480px) {
  .subheading {
    font-size: 0.8rem;
  }

  .daily-heading .eyebrow {
    font-size: 0.62rem;
  }

  .countdown-card {
    display: none;
  }

  .daily-heading {
    display: block;
  }

  .puzzle-toolbar {
    gap: 8px;
  }

  .progress-copy {
    width: 38%;
  }

  .progress-copy > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.69rem;
  }

  .text-button {
    gap: 4px;
  }

  .game-actions .button {
    padding-inline: 10px;
    font-size: 0.78rem;
  }

  .preview-caption .button {
    min-height: 40px;
    padding-inline: 12px;
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
