/* Sand & Light Art: Magic Table — Stylesheet */

:root {
  --s-wood-dark: #451a03;
  --s-wood-mid: #78350f;
  --s-wood-light: #92400e;
  --s-sand-grain: #d97706;
  --s-gold: #f59e0b;
  --s-table-w: min(84vw, 780px);
  --s-table-h: min(72vh, 520px);
}

body {
  background: radial-gradient(circle at 50% 25%, #292524 0%, #0c0a09 100%);
  color: #f8fafc;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.sand-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  height: calc(100vh - 110px);
  max-height: calc(100vh - 110px);
  padding: 8px 16px;
  box-sizing: border-box;
  overflow: hidden;
}

/* Toolbar */
.sand-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: rgba(28, 25, 23, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  z-index: 10;
  max-height: 94%;
  overflow-y: auto;
  scrollbar-width: thin;
}

.toolbar-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
  margin: 2px 0;
}

.tool-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Sand Tools Buttons */
.sand-tool-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  color: #f8fafc;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-sizing: border-box;
}

.sand-tool-btn .tool-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.sand-tool-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.sand-tool-btn:active {
  transform: scale(0.94);
}

.sand-tool-btn.active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(217, 119, 6, 0.2));
  border-color: #f59e0b;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.45);
}

/* Light Table Backlight Mood Buttons */
.light-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.light-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
  padding: 4px;
}

.light-preview {
  font-size: 1.35rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.light-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-2px);
}

.light-btn.active {
  border-color: #fbbf24;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.5);
  transform: scale(1.05);
}

.light-btn[data-light="amber"].active { background: rgba(245, 158, 11, 0.25); }
.light-btn[data-light="rainbow"].active { background: rgba(168, 85, 247, 0.25); }
.light-btn[data-light="space"].active { background: rgba(59, 130, 246, 0.25); }
.light-btn[data-light="ocean"].active { background: rgba(6, 182, 212, 0.25); }

/* Actions */
.action-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.smooth-btn {
  grid-column: span 2;
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #ffffff;
  border-color: #f59e0b;
  justify-content: center;
}

.smooth-btn:hover {
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.55);
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  color: #f8fafc;
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-2px);
}

.save-btn {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-color: #60a5fa;
}

/* Center Light Table Stage */
.sand-table-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.table-bezel {
  position: relative;
  width: var(--s-table-w);
  height: var(--s-table-h);
  background: linear-gradient(145deg, #78350f, #451a03 70%, #291002 100%);
  border-radius: 32px;
  padding: 14px;
  box-sizing: border-box;
  box-shadow:
    0 16px 42px rgba(0, 0, 0, 0.7),
    0 2px 8px rgba(251, 191, 36, 0.15),
    inset 0 3px 6px rgba(255, 255, 255, 0.25),
    inset 0 -6px 12px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.light-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.6);
  touch-action: none;
  cursor: pointer;
}

.light-canvas,
.sand-canvas,
.fx-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.fx-canvas {
  pointer-events: none;
  z-index: 5;
}

.tool-btn:disabled,
.action-btn:disabled,
.light-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

.instruction-banner {
  cursor: pointer;
}

.instruction-banner:focus-visible {
  outline: 2px solid var(--s-gold);
  outline-offset: 2px;
}

/* Wooden Smoothing Bar */
.smoothing-bar {
  position: absolute;
  top: -28px;
  left: 0;
  right: 0;
  height: 24px;
  background: linear-gradient(180deg, #b45309 0%, #78350f 50%, #451a03 100%);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.65), 0 0 10px rgba(245, 158, 11, 0.3);
  border-bottom: 2px solid #f59e0b;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
}

.smoothing-bar.active {
  opacity: 1;
  animation: sweep-down 0.85s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes sweep-down {
  0% { top: -28px; opacity: 1; }
  85% { top: 100%; opacity: 1; }
  100% { top: 104%; opacity: 0; }
}

/* Toast */
.feedback-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 25, 23, 0.95);
  color: #ffffff;
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 1.05rem;
  font-weight: 700;
  border: 1px solid var(--s-gold);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 16px rgba(245, 158, 11, 0.4);
  z-index: 100;
  pointer-events: none;
  animation: toast-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Responsive */
@media (max-width: 820px) {
  .sand-field {
    flex-direction: column-reverse;
    gap: 8px;
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    padding: 4px 8px;
  }

  .sand-toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px;
    max-height: 38vh;
    border-radius: 18px;
  }

  .tool-section {
    flex-direction: row;
    align-items: center;
  }

  .toolbar-divider {
    width: 1px;
    height: 32px;
    margin: 0 4px;
  }

  .sand-tool-btn {
    min-height: 42px;
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  .sand-tool-btn .tool-label {
    display: none;
  }

  .light-section {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .light-btn {
    min-height: 40px;
    padding: 4px;
  }

  .action-buttons {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .smooth-btn {
    grid-column: span 1;
  }

  .smooth-btn .tool-label {
    display: none;
  }

  :root {
    --s-table-w: 94vw;
    --s-table-h: 54vh;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .sand-field {
    flex-direction: row;
    height: calc(100vh - 76px);
    max-height: calc(100vh - 76px);
    padding: 4px 8px;
    gap: 8px;
  }

  .sand-toolbar {
    flex-direction: column;
    padding: 6px;
    gap: 4px;
    max-height: 98%;
  }

  .sand-tool-btn {
    min-height: 36px;
    padding: 4px 6px;
  }

  .sand-tool-btn .tool-label,
  .smooth-btn .tool-label {
    display: none;
  }

  .light-section {
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
  }

  .light-btn,
  .action-btn {
    min-height: 34px;
    padding: 2px;
  }

  :root {
    --s-table-w: min(78vw, 680px);
    --s-table-h: min(84vh, 440px);
  }
}
