/* ==========================================================================
   Fantasy Craft - Modern Dark Medieval Alchemy Theme
   ========================================================================== */

:root {
  --bg-main: #0b0e14;
  --bg-desk: #10141d;
  --bg-sidebar: #151a24;
  --bg-card: #1c2230;
  --bg-card-hover: #262e40;
  --bg-card-active: #2f384d;
  --border-color: rgba(212, 175, 55, 0.2);
  --border-glow: rgba(212, 175, 55, 0.5);
  --gold-accent: #d4af37;
  --gold-bright: #ffd700;
  --gold-dim: #997f26;
  --text-main: #f0e6d2;
  --text-muted: #8b949e;
  --text-dim: #5c6370;
  --danger: #e06c75;
  --success: #98c379;
  --magic-blue: #61afef;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-hover: 0 6px 18px rgba(212, 175, 55, 0.25);
  --radius-card: 8px;
  --radius-pill: 20px;
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Cinzel", "Georgia", serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  height: -webkit-fill-available;
  width: 100vw;
  overscroll-behavior: none;
}

/* ==========================================================================
   Layout Structure
   ========================================================================== */

.game-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Canvas (Desk) Area
   -------------------------------------------------------------------------- */

.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-desk);
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(212, 175, 55, 0.03) 0%, transparent 80%),
    radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 28px 28px;
  overflow: hidden;
}

.canvas-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(16, 20, 29, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 28px;
  filter: drop-shadow(0 0 10px rgba(212, 175, 55, 0.6));
  animation: pulse-glow 3s infinite alternate;
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--gold-bright);
  text-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
}

.brand-text .subtext {
  font-size: 12px;
  color: var(--text-muted);
}

.canvas-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--gold-accent);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.25);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 16px;
}

.btn-primary {
  background: var(--gold-accent);
  color: #0b0e14;
  border-color: var(--gold-bright);
}

.btn-primary:hover {
  background: var(--gold-bright);
}

.btn-mobile-toggle {
  display: none;
}

.sidebar-top-bar {
  display: none;
  justify-content: space-between;
  align-items: center;
}

.sidebar-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.5px;
}

.btn-close-sidebar {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-close-sidebar:hover {
  color: #fff;
}

/* The Desk Workspace */
.desk {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0.6;
  transition: opacity 0.4s ease;
}

.empty-hint.fade {
  opacity: 0;
}

.rune-circle {
  font-size: 44px;
  margin-bottom: 12px;
  opacity: 0.8;
  animation: float-soft 3s ease-in-out infinite;
}

.empty-hint p {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 6px;
}

.empty-hint .hint-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Draggable Crafting Cards on Desk
   -------------------------------------------------------------------------- */

.desk-item {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  cursor: grab;
  box-shadow: var(--shadow-card);
  z-index: 5;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
  will-change: transform, left, top;
}

.desk-item:hover {
  border-color: var(--gold-accent);
  box-shadow: var(--shadow-hover);
}

.desk-item.dragging {
  cursor: grabbing;
  z-index: 1000 !important;
  opacity: 0.95;
  transform: scale(1.05);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.7), 0 0 20px rgba(212, 175, 55, 0.4);
  border-color: var(--gold-bright);
}

/* When another item is dragged over this item (Magnet proximity) */
.desk-item.snap-target {
  border-color: var(--gold-bright);
  box-shadow: 0 0 25px rgba(255, 215, 0, 0.6);
  transform: scale(1.12);
  background: #2b281f;
  animation: pulse-border 1s infinite alternate;
}

.desk-item .item-emoji {
  font-size: 18px;
  line-height: 1;
}

.desk-item .item-title {
  white-space: nowrap;
}

.desk-item.spawn-anim {
  animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.desk-item.shake-anim {
  animation: shake 0.4s ease-in-out;
}

/* --------------------------------------------------------------------------
   Sidebar (Elements Inventory)
   -------------------------------------------------------------------------- */

.sidebar {
  width: 360px;
  min-width: 320px;
  max-width: 440px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-color);
  box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

.sidebar-header {
  padding: 18px 20px 12px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 36px 9px 34px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: all 0.2s;
}

.search-box input:focus {
  border-color: var(--gold-accent);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
  background: var(--bg-card-hover);
}

.search-box input::placeholder {
  color: var(--text-dim);
}

.btn-clear-search {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.btn-clear-search:hover {
  color: var(--text-main);
}

/* Progress Section */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.stats-label {
  color: var(--text-muted);
}

.stats-count {
  color: var(--gold-bright);
  font-weight: 700;
}

.progress-bar-bg {
  height: 6px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright));
  border-radius: 4px;
  transition: width 0.4s ease;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-tab {
  padding: 5px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.filter-tab:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.filter-tab.active {
  background: var(--gold-accent);
  color: #0b0e14;
  border-color: var(--gold-bright);
}

/* Elements List (Infinite Craft Pills) */
.elements-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
}

.elements-list::-webkit-scrollbar {
  width: 6px;
}

.elements-list::-webkit-scrollbar-track {
  background: transparent;
}

.elements-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.elements-list::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 175, 55, 0.4);
}

/* Sidebar Pill Card */
.sidebar-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-pill:hover {
  background: var(--bg-card-hover);
  border-color: var(--gold-accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.sidebar-pill:active {
  transform: scale(0.96);
}

.sidebar-pill .pill-emoji {
  font-size: 15px;
}

.sidebar-pill.is-new-discovery {
  border-color: var(--gold-bright);
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
  animation: pop-in 0.3s ease;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.footer-info {
  color: var(--text-dim);
}

.btn-text-danger {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  transition: color 0.2s;
}

.btn-text-danger:hover {
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   Discovery Toast Banner
   -------------------------------------------------------------------------- */

.discovery-toast {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: linear-gradient(135deg, #1c2230, #2b281f);
  border: 1px solid var(--gold-bright);
  border-radius: var(--radius-card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 30px rgba(255, 215, 0, 0.4);
  z-index: 2000;
  animation: slide-down 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}

.discovery-toast.hidden {
  display: none;
}

.toast-sparkles {
  font-size: 30px;
  animation: spin 3s linear infinite;
}

.toast-content .toast-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--gold-bright);
}

.toast-content h3 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin: 2px 0;
}

.toast-content p {
  font-size: 12px;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Particles and Visual Effects
   -------------------------------------------------------------------------- */

.particle {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  z-index: 1500;
}

/* --------------------------------------------------------------------------
   Keyframe Animations
   -------------------------------------------------------------------------- */

@keyframes pop-in {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slide-down {
  0% { transform: translate(-50%, -30px); opacity: 0; }
  100% { transform: translate(-50%, 0); opacity: 1; }
}

@keyframes pulse-glow {
  0% { transform: scale(1); filter: drop-shadow(0 0 5px rgba(212, 175, 55, 0.4)); }
  100% { transform: scale(1.08); filter: drop-shadow(0 0 14px rgba(255, 215, 0, 0.8)); }
}

@keyframes pulse-border {
  0% { border-color: var(--gold-accent); }
  100% { border-color: var(--gold-bright); }
}

@keyframes float-soft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Mobile & Safari iOS Responsive Adaptations
   ========================================================================== */

@media (max-width: 768px) {
  .canvas-header {
    padding: 10px 14px;
  }

  .brand-text h1 {
    font-size: 16px;
  }

  .brand-text .subtext {
    display: none;
  }

  .brand-icon {
    font-size: 22px;
  }

  .btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  .btn-mobile-toggle {
    display: inline-flex;
    font-weight: 700;
  }

  /* Sidebar transforms into full slide-over drawer */
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 88vw;
    max-width: 380px;
    height: 100%;
    z-index: 5000;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -10px 0 35px rgba(0, 0, 0, 0.85);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-top-bar {
    display: flex;
    margin-bottom: 8px;
  }

  .desk-item {
    padding: 10px 16px;
    font-size: 15px;
    touch-action: none;
  }

  .desk-item .item-emoji {
    font-size: 20px;
  }

  .discovery-toast {
    width: 90%;
    top: 65px;
    padding: 12px 16px;
    font-size: 13px;
  }

  .toast-content h3 {
    font-size: 16px;
  }
}

