/* Patch Pic Game - Ceramic Studio Theme */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif&family=Figtree:wght@400;500;600&display=swap');

:root {
  --cell-size: 78px;
  --grid-gap: 2px;
  --scroller-cell-size: 78px;

  /* Ceramic Studio palette */
  --bg-page: #faf8f5;
  --bg-warm: #f5f1eb;
  --bg-card: #ffffff;
  --bg-elevated: #faf7f2;
  --terracotta: #c9785d;
  --terracotta-light: rgba(201, 120, 93, 0.12);
  --terracotta-glow: rgba(201, 120, 93, 0.25);
  --sage: #7d8f76;
  --sage-light: rgba(125, 143, 118, 0.12);
  --sage-glow: rgba(125, 143, 118, 0.3);
  --clay: #a69080;
  --sand: #e8e0d5;
  --text-primary: #3d3830;
  --text-secondary: #6d665c;
  --text-muted: #a09a90;
  --border: #e5dfd6;
  --border-strong: #d4cdc2;
  --error: #c45c4d;
  --shadow-soft: 0 2px 8px rgba(60, 50, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(60, 50, 40, 0.08);
  --shadow-lg: 0 12px 40px rgba(60, 50, 40, 0.1);
  --shadow-warm: 0 8px 32px rgba(180, 140, 100, 0.12);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Figtree', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  background: var(--bg-page);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(201, 120, 93, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(125, 143, 118, 0.04) 0%, transparent 50%);
  padding: 20px;
  position: relative;
}

/* Subtle grain texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(/%23noise)'/%3E%3C/svg%3E");
  opacity: 0.025;
  pointer-events: none;
  z-index: 1;
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 2px solid var(--sand);
  border-top-color: var(--terracotta);
  border-radius: 50%;
  animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-screen p {
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Game Container */
.game-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  min-height: calc(100vh - 100px);
  position: relative;
  z-index: 2;
}

.container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px;
  max-width: 540px;
  min-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-warm);
  position: relative;
  overflow: visible;
}

/* Decorative corner accents */
.container::before,
.container::after {
  content: '';
  position: absolute;
  width: 80px;
  height: 80px;
  opacity: 0.5;
  pointer-events: none;
}

.container::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--terracotta);
  border-left: 2px solid var(--terracotta);
  border-top-left-radius: 20px;
}

.container::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--sage);
  border-right: 2px solid var(--sage);
  border-bottom-right-radius: 20px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-family: 'Instrument Serif', Georgia, serif;
  color: var(--text-primary);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  position: relative;
  display: inline-block;
}

header h1::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--terracotta), transparent);
}

/* Puzzle Area Layout */
.puzzle-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* Main 5x5 Grid */
.main-grid-wrapper {
  display: flex;
  justify-content: center;
  position: relative;
}

.main-grid {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  grid-template-rows: repeat(5, var(--cell-size));
  gap: var(--grid-gap);
  background: var(--sand);
  padding: var(--grid-gap);
  border-radius: 12px;
  box-shadow: var(--shadow-md), inset 0 1px 2px rgba(255, 255, 255, 0.6);
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-size: calc(var(--cell-size) * 5 + var(--grid-gap) * 4) calc(var(--cell-size) * 5 + var(--grid-gap) * 4);
  background-repeat: no-repeat;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-radius: 3px;
}

.grid-cell.broken {
  box-shadow: inset 0 0 0 2px var(--error);
  border: 2px solid var(--error);
  position: relative;
  overflow: hidden;
}

/* Broken cell live preview triangles */
.broken-upper,
.broken-lower {
  position: absolute;
  width: 100%;
  height: 100%;
  background-size: calc(var(--cell-size) * 5 + var(--grid-gap) * 4) calc(var(--cell-size) * 5 + var(--grid-gap) * 4);
  background-repeat: no-repeat;
  transition: background-position 0.15s ease-out;
}

.broken-upper {
  clip-path: polygon(0 0, 100% 0, 0 100%);
  z-index: 2;
}

.broken-lower {
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  z-index: 1;
}

.grid-cell.fixed {
  animation: fix-cell 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: inset 0 0 0 3px var(--sage);
}

@keyframes fix-cell {
  0% {
    transform: scale(1.15) rotate(2deg);
    box-shadow: inset 0 0 0 3px var(--sage), 0 0 20px var(--sage-glow);
  }
  50% { transform: scale(0.95) rotate(-1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Scroller Zone */
.scroller-zone {
  position: relative;
  width: calc(var(--scroller-cell-size) * 5);
  height: calc(var(--scroller-cell-size) * 5);
  margin-top: 8px;
}

/* Vertical Scroller */
.v-scroller-wrapper {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  overflow: hidden;
  width: var(--scroller-cell-size);
  height: calc(var(--scroller-cell-size) * 5);
  background: transparent;
  touch-action: none;
  z-index: 3;
}


.v-scroller {
  display: flex;
  flex-direction: column;
  transition: transform 0.18s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  cursor: grab;
}

.v-scroller:active {
  cursor: grabbing;
}

/* Horizontal Scroller */
.h-scroller-wrapper {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  overflow: hidden;
  width: calc(var(--scroller-cell-size) * 5);
  height: var(--scroller-cell-size);
  background: transparent;
  touch-action: none;
  z-index: 2;
}


.h-scroller {
  display: flex;
  flex-direction: row;
  transition: transform 0.18s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  cursor: grab;
}

.h-scroller:active {
  cursor: grabbing;
}

/* Scroller Cells */
.scroller-cell {
  width: var(--scroller-cell-size);
  height: var(--scroller-cell-size);
  position: relative;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-sizing: border-box;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.scroller-cell:hover {
  border-color: var(--clay);
  box-shadow: var(--shadow-soft);
}

.cell-upper,
.cell-lower {
  position: absolute;
  width: 100%;
  height: 100%;
  background-size: calc(var(--cell-size) * 5 + var(--grid-gap) * 4) calc(var(--cell-size) * 5 + var(--grid-gap) * 4);
  background-repeat: no-repeat;
}

/* Upper triangle */
.cell-upper {
  clip-path: polygon(0 0, 100% 0, 0 100%);
  z-index: 2;
}

/* Lower triangle */
.cell-lower {
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  z-index: 1;
}

/* V-scroller: only show upper triangle */
.v-scroller .cell-lower {
  display: none;
}

.v-scroller .cell-upper {
  background-color: var(--bg-elevated);
}

/* H-scroller: only show lower triangle */
.h-scroller .cell-upper {
  display: none;
}

.h-scroller .cell-lower {
  background-color: var(--bg-elevated);
}

/* V-scroller cells */
.v-scroller .scroller-cell {
  background: transparent;
  border: 1px solid rgba(166, 144, 128, 0.25);
}

/* H-scroller cells */
.h-scroller .scroller-cell {
  background: transparent;
  border: 1px solid rgba(166, 144, 128, 0.25);
}

/* At center intersection: clip cells for proper overlay */
.v-scroller .scroller-cell.at-center {
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.h-scroller .scroller-cell.at-center {
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

/* Cell labels */
.cell-label {
  position: absolute;
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  z-index: 5;
  pointer-events: none;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* V-scroller: label in lower-right */
.v-scroller .cell-label {
  bottom: 14px;
  right: 8px;
}

/* H-scroller: label in upper-left */
.h-scroller .cell-label {
  top: 14px;
  left: 10px;
}

/* Hide labels for cells at center intersection */
.scroller-cell.at-center .cell-label {
  display: none;
}

/* Intersection Point */
.intersection {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--scroller-cell-size);
  height: var(--scroller-cell-size);
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid var(--terracotta);
  border-radius: 6px;
  box-shadow: 0 0 0 4px var(--terracotta-light), var(--shadow-soft);
  z-index: 10;
  pointer-events: none;
  box-sizing: border-box;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.intersection-marker {
  display: none;
}

.intersection.aligned {
  border-color: var(--sage);
  box-shadow: 0 0 0 4px var(--sage-light), 0 0 20px var(--sage-glow);
}

/* Controls */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 28px;
  margin-bottom: 14px;
}

.btn {
  padding: 12px 28px;
  border: none;
  background: var(--terracotta);
  font-family: 'Figtree', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-soft), 0 2px 8px var(--terracotta-light);
  letter-spacing: 0.02em;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}

.btn:hover {
  background: #b86a4f;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 4px 16px var(--terracotta-glow);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-soft);
}

/* Status Message */
.status {
  text-align: center;
  min-height: 28px;
}

.message {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.message.success {
  color: var(--sage);
}

.message.info {
  color: var(--terracotta);
}

/* Win Celebration */
@keyframes celebration {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.02) rotate(0.5deg); }
  50% { transform: scale(1.04) rotate(-0.5deg); }
  75% { transform: scale(1.02) rotate(0.25deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.main-grid.celebrating {
  animation: celebration 0.8s ease-in-out;
}

.main-grid.celebrating .grid-cell {
  box-shadow: none;
}

/* Remove grid lines on completion */
.main-grid.completed {
  gap: 0;
  padding: 0;
  background: transparent;
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--sage-light);
  border-radius: 12px;
  overflow: hidden;
}

.main-grid.completed .grid-cell {
  background-size: calc(var(--cell-size) * 5) calc(var(--cell-size) * 5);
  border-radius: 0;
}

/* Responsive - allow horizontal scroll on small screens */
@media (max-width: 540px) {
  body {
    padding: 10px;
    overflow-x: auto;
  }

  .game-container {
    padding: 10px;
    justify-content: flex-start;
  }

  .container {
    padding: 24px 20px;
    border-radius: 16px;
    flex-shrink: 0;
  }

  .container::before,
  .container::after {
    width: 50px;
    height: 50px;
  }

  header h1 {
    font-size: 1.625rem;
  }

  header {
    margin-bottom: 24px;
  }

  .puzzle-area {
    gap: 20px;
  }

  .btn {
    padding: 11px 22px;
    font-size: 0.825rem;
  }

  .controls {
    margin-top: 20px;
  }
}
