/* ============================================================
   Secret Jigsaw – styles
   ============================================================ */

:root {
  --bg: #e8ddcf;
  --orange: #cc7d2b;
  --orange-light: #e8a44c;
  --dark: #21130b;
  --muted: #8c7b65;
  --card: #fffdf9;
  --border: #e0d8ce;
  --shadow: rgba(33, 19, 11, 0.08);
  --radius-card: 28px;
  --radius-pill: 999px;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
}

/* ---- reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--dark);
  line-height: 1.5;
  min-height: 100dvh;
}

img { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
a { color: inherit; }

/* ---- homepage layout ---- */
.homepage {
  max-width: 460px;
  margin: 0 auto;
  padding: 36px 20px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- site logo ---- */
.site-logo {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--dark);
  letter-spacing: -0.01em;
  margin-bottom: 28px;
}

.site-logo .gram {
  color: var(--orange);
  font-style: normal;
}

/* ---- headline ---- */
.headline {
  font-family: var(--font-display);
  font-size: clamp(2rem, 7vw, 2.6rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.2;
  margin-bottom: 20px;
  color: var(--dark);
}

.headline .gram {
  color: var(--orange);
  font-style: italic;
}

.subheading {
  color: var(--muted);
  font-size: 1.15rem;
  margin-bottom: 24px;
  text-align: center;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

/* ---- cards ---- */
.card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 16px;
  width: 100%;
  box-shadow: 0 2px 12px var(--shadow);
  margin-bottom: 16px;
  transition: opacity 0.3s, border-color 0.3s;
}

.card--disabled {
  opacity: 0.45;
  pointer-events: none;
  border: 2px dashed var(--border);
  box-shadow: none;
}

.card--active {
  opacity: 1;
  pointer-events: auto;
}

.card--upload {
  background: linear-gradient(160deg, #fffdf9 0%, #f7f1e8 100%);
  box-shadow: 0 4px 24px rgba(33, 19, 11, 0.1);
  padding: 20px;
}

/* ---- step titles ---- */
.step-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 14px;
  color: var(--dark);
}

/* ---- image preview ---- */
.preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
  margin-bottom: 12px;
  background: #f0ebe4;
}

.preview-wrap img,
.preview-wrap canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.jigsaw-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.7;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 1rem;
  font-weight: 700;
  padding: 0 28px;
  height: 56px;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.btn:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

.btn:active { transform: scale(0.97); }

.btn--primary {
  background: var(--orange);
  color: #fff;
  width: 100%;
  box-shadow: 0 4px 16px rgba(204, 125, 43, 0.3);
}

.btn--primary:hover {
  background: #b86e22;
  box-shadow: 0 6px 20px rgba(204, 125, 43, 0.4);
}

.btn--secondary {
  background: transparent;
  color: var(--dark);
  border: 2px solid var(--border);
}

.btn--secondary:hover { background: rgba(0,0,0,0.03); }

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 16px;
  height: 44px;
  font-weight: 600;
}

.btn--small {
  height: 44px;
  font-size: 0.9rem;
  padding: 0 20px;
}

/* ---- upload dropzone ---- */
.upload-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1.5px dashed var(--border);
  border-radius: 20px;
  padding: 36px 24px;
  cursor: pointer;
  transition: border-color 0.25s, background 0.25s, box-shadow 0.25s, transform 0.15s;
  background: rgba(232, 221, 207, 0.25);
  margin-bottom: 12px;
}

.upload-dropzone:hover {
  border-color: var(--orange-light);
  background: rgba(232, 164, 76, 0.06);
  box-shadow: 0 4px 20px rgba(204, 125, 43, 0.08);
}

.upload-dropzone:active {
  transform: scale(0.99);
}

.dropzone-icon {
  position: relative;
  width: 68px;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border-radius: 50%;
  color: var(--muted);
  box-shadow: 0 2px 12px rgba(33, 19, 11, 0.08);
  transition: color 0.25s, box-shadow 0.25s;
}

.upload-dropzone:hover .dropzone-icon {
  color: var(--orange);
  box-shadow: 0 4px 18px rgba(204, 125, 43, 0.18);
}

.dropzone-arrow {
  position: absolute;
  bottom: -2px;
  right: -2px;
  color: #fff;
  background: var(--orange);
  border-radius: 50%;
  padding: 3px;
  box-shadow: 0 1px 4px rgba(204, 125, 43, 0.35);
  transition: background 0.25s;
}

.upload-dropzone:hover .dropzone-arrow {
  background: #b86e22;
}

.dropzone-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
  transition: color 0.25s;
}

.upload-dropzone:hover .dropzone-label {
  color: var(--orange);
}

.upload-btn {
  width: 100%;
  height: 48px;
  font-size: 0.95rem;
  padding: 0 24px;
  display: flex;
  margin: 0 auto 8px;
}

/* ---- privacy line ---- */
.privacy-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 10px;
}

.privacy-line svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ---- difficulty selector ---- */
.difficulty-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 16px;
  flex: 1;
  min-width: 0;
  height: 84px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.diff-icon {
  width: 20px;
  height: 20px;
  color: var(--border);
  margin-bottom: 2px;
}

.diff-btn:hover .diff-icon {
  color: var(--orange-light);
}

.diff-btn.selected .diff-icon {
  color: var(--orange);
}

.diff-btn:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

.diff-btn:hover {
  border-color: var(--orange-light);
}

.diff-btn.selected {
  border-color: var(--orange);
  background: rgba(204, 125, 43, 0.1);
}

.diff-num {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 900;
  line-height: 1;
  color: var(--dark);
}

.diff-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  margin-top: 2px;
}

/* ---- step 3 buttons ---- */
.share-row {
  display: flex;
  gap: 12px;
}

.share-row .btn {
  flex: 1;
  white-space: nowrap;
  font-size: 0.85rem;
  padding: 0 14px;
}

.share-row .btn svg { width: 18px; height: 18px; }

/* ---- footer ---- */
.site-footer {
  text-align: center;
  padding: 32px 20px 24px;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer p { margin-bottom: 8px; }

.footer-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  list-style: none;
}

.footer-links a {
  text-decoration: none;
  color: var(--muted);
  transition: color 0.2s;
}

.footer-links a:hover { color: var(--dark); }

/* ---- modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(33, 19, 11, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 32px 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(33, 19, 11, 0.2);
  transform: translateY(12px);
  transition: transform 0.25s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.modal p {
  color: var(--muted);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.modal .btn { margin-bottom: 10px; }
.modal .btn:last-child { margin-bottom: 0; }

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.modal-close:hover { background: rgba(0,0,0,0.05); }

/* ============================================================
   PLAY PAGE
   ============================================================ */

.play-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- header ---- */
.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.play-logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.3rem;
  text-decoration: none;
  color: var(--dark);
}

.play-logo .gram { color: var(--orange); font-style: italic; }

.toolbar {
  display: flex;
  gap: 4px;
}

.toolbar-btn {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.toolbar-btn:hover { background: rgba(0,0,0,0.05); color: var(--dark); }
.toolbar-btn:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.toolbar-btn svg { width: 22px; height: 22px; }

/* ---- workspace ---- */
.play-workspace {
  flex: 1;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.canvas-wrap {
  background: var(--bg);
  overflow: hidden;
  position: relative;
  width: 100%;
  height: 100%;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* ---- piece tray backdrop (full-width bar behind the canvas tray) ---- */
.piece-tray {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  pointer-events: none;
  z-index: 0;
  margin-bottom: 0;
}

.play-workspace {
  position: relative;
  z-index: 1;
}

/* ---- loading ---- */
.loading-screen {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-screen p { color: var(--muted); font-size: 0.95rem; }

/* ---- settings modal ---- */
.settings-list {
  list-style: none;
  text-align: left;
}

.settings-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.settings-list li:last-child { border-bottom: none; }

/* toggle switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  transition: background 0.2s;
  cursor: pointer;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-track { background: var(--orange); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--orange); outline-offset: 2px; }

/* ---- completion modal ---- */
.completion-time {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  color: var(--orange);
  margin-bottom: 8px;
}

/* ---- responsive ---- */
@media (max-width: 500px) {
  .card { padding: 14px; }
  .diff-btn { height: 72px; }
  .diff-num { font-size: 1.3rem; }
  .canvas-wrap { border-width: 0; }
}

/* ---- hidden file input ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- jigsaw overlay SVG ---- */
.preview-container {
  position: relative;
  display: flex;
  justify-content: center;
}

.jigsaw-overlay {
  transition: opacity 0.15s ease;
}

.jigsaw-overlay.fading {
  opacity: 0 !important;
}

/* ---- play page footer ---- */
.play-footer {
  text-align: center;
  padding: 6px 16px 10px;
  flex-shrink: 0;
  background: var(--card);
  position: relative;
  z-index: 2;
  border-top: 1px solid var(--border);
}

.create-link {
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
  letter-spacing: 0.01em;
  transition: color 0.2s;
}

.create-link:hover {
  color: var(--orange);
}

/* ---- toolbar zoom-in active state ---- */
.toolbar-btn.zoom-active {
  color: var(--orange);
  background: rgba(204, 125, 43, 0.1);
}
