/* まぜるなきけん — Lab Dark Theme */

:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --card: #22223a;
  --card-hover: #2c2c48;
  --border: #333355;
  --text: #e8e6f0;
  --text2: #8888aa;
  --accent: #a855f7;
  --accent-light: rgba(168,85,247,0.15);
  --accent2: #22d3ee;
  --accent2-light: rgba(34,211,238,0.12);
  --green: #34d399;
  --green-light: rgba(52,211,153,0.12);
  --warn: #f59e0b;
  --warn-light: rgba(245,158,11,0.12);
  --font: 'Noto Sans JP', sans-serif;
  --sidebar-w: 270px;
  --radius: 10px;
  --pill: 100px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --glow: 0 0 12px rgba(168,85,247,0.25);
  --fast: 0.18s ease;
}

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

html, body {
  height: 100%; overflow: hidden;
  font-family: var(--font); background: var(--bg); color: var(--text);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: var(--font); cursor: pointer; border: none;
  background: none; color: var(--text);
}

/* Layout */
#app {
  display: flex; height: 100vh; width: 100vw;
}

/* Canvas */
#canvas {
  flex: 1; position: relative; overflow: hidden;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(168,85,247,0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(34,211,238,0.05) 0%, transparent 50%);
}

#canvas-hint {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center; color: var(--text2);
  pointer-events: none; transition: opacity 0.3s;
  font-size: 14px; line-height: 2;
}

/* Canvas elements */
.c-el {
  position: absolute; display: flex; align-items: center; gap: 7px;
  padding: 10px 16px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: grab;
  white-space: nowrap; z-index: 10;
  box-shadow: var(--shadow);
  transition: box-shadow var(--fast), transform var(--fast), border-color var(--fast);
}
.c-el:hover { box-shadow: var(--glow); border-color: var(--accent); }
.c-el.dragging { cursor: grabbing; z-index: 100; box-shadow: 0 8px 24px rgba(168,85,247,0.3); transform: scale(1.06); border-color: var(--accent); }
.c-el.target { box-shadow: 0 0 0 2px var(--accent2); background: var(--accent2-light); border-color: var(--accent2); }
.c-el .em { font-size: 18px; line-height: 1; }

@keyframes pop { 0%{transform:scale(0.5);opacity:0} 70%{transform:scale(1.05)} 100%{transform:scale(1);opacity:1} }
.c-el.appear { animation: pop 0.25s ease-out; }

@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
.c-el.fail { animation: shake 0.3s ease; border-color: var(--warn); }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w); height: 100vh;
  display: flex; flex-direction: column;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

#sidebar-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(168,85,247,0.08), rgba(34,211,238,0.06));
}

#brand {
  font-size: 17px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

#stats { font-size: 13px; color: var(--text2); margin-top: 2px; }
#stats #count { font-size: 20px; font-weight: 700; color: var(--accent); -webkit-text-fill-color: var(--accent); }

#search-box { padding: 8px 12px 4px; }
#search {
  width: 100%; padding: 8px 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); font-family: var(--font);
  font-size: 13px; color: var(--text); outline: none;
  transition: border-color var(--fast);
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
#search::placeholder { color: var(--text2); }

#sort-row {
  display: flex; gap: 4px; padding: 6px 12px 6px;
}
.sort-btn {
  flex: 1; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 11px; color: var(--text2);
  transition: all var(--fast);
}
.sort-btn:hover { background: var(--card); color: var(--text); }
.sort-btn.active {
  background: var(--accent-light); border-color: var(--accent);
  color: var(--accent); font-weight: 600;
}

#el-list {
  flex: 1; overflow-y: auto; padding: 8px 10px;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 7px;
}
#el-list::-webkit-scrollbar { width: 4px; }
#el-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.s-el {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: grab;
  white-space: nowrap; box-shadow: var(--shadow);
  transition: all var(--fast); flex-shrink: 0;
}
.s-el:hover { box-shadow: var(--glow); border-color: var(--accent); transform: translateY(-1px); }
.s-el:active { transform: scale(0.96); }
.s-el .em { font-size: 16px; }
.s-el .nm { font-size: 12px; }
.s-el-tap { transform: scale(0.9); border-color: var(--accent); box-shadow: var(--glow); }

@keyframes sPop { 0%{transform:scale(0);opacity:0} 60%{transform:scale(1.08)} 100%{transform:scale(1);opacity:1} }
.s-el.new {
  animation: sPop 0.3s ease-out;
  border-color: var(--green); background: var(--green-light);
  box-shadow: 0 0 10px rgba(52,211,153,0.2);
}

#sidebar-foot {
  padding: 10px 12px; border-top: 1px solid var(--border);
}
#reset-btn {
  width: 100%; padding: 7px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 11px; color: var(--text2);
  transition: all var(--fast);
}
#reset-btn:hover { background: rgba(245,158,11,0.1); border-color: var(--warn); color: var(--warn); }

/* Canvas btns */
#canvas-btns { position: fixed; bottom: 14px; left: 14px; z-index: 30; display: flex; gap: 6px; }
#clear-btn {
  padding: 6px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 12px; color: var(--text2); box-shadow: var(--shadow);
  transition: all var(--fast);
}
#clear-btn:hover { border-color: var(--accent); color: var(--text); }

/* Drag ghost */
.ghost {
  position: fixed; display: flex; align-items: center; gap: 6px;
  padding: 10px 18px; background: var(--card);
  border: 1.5px solid var(--accent); border-radius: var(--radius);
  font-size: 15px; font-weight: 500; pointer-events: none;
  z-index: 1000; box-shadow: 0 8px 24px rgba(168,85,247,0.25);
  transform: translate(-50%, -50%);
}

/* Mobile bar */
#mobile-bar {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 50; padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--border);
  align-items: center; justify-content: center; gap: 8px;
}
.slot {
  flex: 1; max-width: 130px; padding: 10px 12px;
  background: var(--card); border: 1.5px dashed var(--border);
  border-radius: var(--radius); text-align: center;
  font-size: 13px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--fast);
}
.slot[data-empty="false"] { border-style: solid; border-color: var(--accent); background: var(--accent-light); }
.slot-ph { color: var(--text2); font-size: 11px; }
.slot-sep { color: var(--text2); font-size: 16px; font-weight: 700; }

/* Slot animations */
@keyframes slotPop { 0%{transform:scale(0.8);opacity:0.5} 50%{transform:scale(1.08)} 100%{transform:scale(1);opacity:1} }
@keyframes slotOut { 0%{transform:scale(1);opacity:1} 100%{transform:scale(0.85);opacity:0} }
@keyframes slotGlow { 0%{box-shadow:0 0 0 0 rgba(168,85,247,0.4)} 70%{box-shadow:0 0 0 8px rgba(168,85,247,0)} 100%{box-shadow:0 0 0 0 rgba(168,85,247,0)} }
.slot-pop { animation: slotPop 0.25s ease-out, slotGlow 0.5s ease-out; }
.slot-out { animation: slotOut 0.15s ease-in forwards; }

#mix-btn {
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-radius: var(--radius); color: #fff;
  font-size: 15px; font-weight: 700; min-height: 44px;
  box-shadow: 0 4px 16px rgba(168,85,247,0.3);
  transition: all var(--fast);
}
#mix-btn:disabled { opacity: 0.3; cursor: not-allowed; box-shadow: none; }
#mix-btn:not(:disabled):hover { box-shadow: 0 6px 24px rgba(168,85,247,0.45); }
#mix-btn:not(:disabled):active { transform: scale(0.96); }

/* Mix button ready animation */
@keyframes mixBounceReady { 0%{transform:scale(1)} 30%{transform:scale(1.1)} 60%{transform:scale(0.95)} 100%{transform:scale(1)} }
@keyframes mixGlowReady { 0%{box-shadow:0 4px 16px rgba(168,85,247,0.3)} 50%{box-shadow:0 4px 24px rgba(168,85,247,0.6)} 100%{box-shadow:0 4px 16px rgba(168,85,247,0.3)} }
.mix-ready { animation: mixBounceReady 0.4s ease-out, mixGlowReady 0.6s ease-out; }

/* Discovery popup */
#popup {
  position: fixed; top: 50px; left: 50%;
  transform: translateX(-50%); z-index: 200; pointer-events: none;
}
#popup.hide { display: none; }
#popup-inner {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; background: var(--bg2);
  border: 1px solid var(--green); border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(52,211,153,0.2);
  animation: slideDown 0.3s ease-out;
}
#popup-label { font-size: 12px; font-weight: 700; color: var(--green); }
#popup-emoji { font-size: 18px; }
#popup-name { font-size: 14px; font-weight: 700; }
#share-btn {
  padding: 4px 12px; margin-left: 4px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 11px; font-weight: 700; pointer-events: auto;
  transition: all var(--fast); color: var(--text2);
}
#share-btn:hover { border-color: var(--accent); color: var(--accent); }

@keyframes slideDown { 0%{transform:translateY(-10px);opacity:0} 100%{transform:translateY(0);opacity:1} }

/* Mike character — desktop: fixed bottom-left of canvas */
#mike {
  position: fixed; bottom: 20px; left: 20px;
  z-index: 60; max-width: 340px;
  pointer-events: none;
}
#mike-inner {
  display: flex; align-items: flex-end; gap: 10px;
}

#mike-face {
  width: 80px; height: 80px; flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(168,85,247,0.4));
}
#mike-face img {
  width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; border: 3px solid var(--accent);
  transition: border-color 0.3s;
}
#mike-bubble {
  flex: 1; min-width: 0;
  padding: 10px 14px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px 12px 12px 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  pointer-events: auto;
}
#mike-text {
  font-size: 13px; font-weight: 500; line-height: 1.5;
  display: block;
}
@keyframes mikeSpeak { 0%{opacity:0;transform:translateY(4px)} 100%{opacity:1;transform:translateY(0)} }
#mike-text.speak { animation: mikeSpeak 0.3s ease-out; }

#mike-share {
  display: inline-block; margin-top: 5px;
  padding: 3px 12px; font-size: 11px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; border: none;
  border-radius: var(--radius); cursor: pointer;
  box-shadow: 0 2px 6px rgba(168,85,247,0.3);
}
#mike-share.hide { display: none; }
#mike-share:active { transform: scale(0.95); }

/* Mixing overlay */
#loader {
  position: fixed; inset: 0; z-index: 150;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,15,26,0.7); backdrop-filter: blur(8px);
}
#loader.hide { display: none; }

#mix-card {
  background: var(--bg2); border-radius: 16px;
  border: 1px solid var(--border);
  padding: 28px 36px; text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4), 0 0 40px rgba(168,85,247,0.1);
  animation: mixIn 0.3s ease-out;
}
@keyframes mixIn { 0%{transform:scale(0.8);opacity:0} 100%{transform:scale(1);opacity:1} }

#mix-els {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 16px;
}
.mix-el {
  padding: 6px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
}
.mix-plus {
  font-size: 22px;
  animation: mixBounce 0.6s ease-in-out infinite;
}
@keyframes mixBounce { 0%,100%{transform:translateY(0) rotate(0deg)} 50%{transform:translateY(-6px) rotate(15deg)} }

#mix-slot {
  font-size: 36px; height: 48px; line-height: 48px;
  margin-bottom: 10px; overflow: hidden;
}
#mix-reel {
  display: inline-block;
  animation: reelSpin 0.15s steps(1) infinite;
}

#mix-msg {
  font-size: 13px; color: var(--text2); font-weight: 500;
  animation: msgPulse 1.5s ease-in-out infinite;
}
@keyframes msgPulse { 0%,100%{opacity:0.5} 50%{opacity:1} }

/* Toast */
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  padding: 8px 20px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-weight: 500; z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: slideDown 0.25s ease-out;
}
#toast.hide { display: none; }

/* Mobile — full-screen element list, no canvas */
@media (max-width: 768px) {
  #app { flex-direction: column; }

  /* Hide canvas entirely on mobile */
  #canvas { display: none !important; }
  #canvas-btns { display: none !important; }

  /* Sidebar becomes the full-screen main area */
  #sidebar {
    width: 100%; flex: 1; border-left: none;
    order: 1; display: flex; flex-direction: column;
    height: calc(100vh - 62px); /* minus mobile-bar height */
  }

  #sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px 8px;
    background: linear-gradient(135deg, rgba(168,85,247,0.1), rgba(34,211,238,0.06));
  }
  #brand { font-size: 15px; margin-bottom: 0; }
  #stats #count { font-size: 16px; }

  #search-box { padding: 6px 12px 2px; }
  #search { padding: 7px 10px; font-size: 13px; }

  #sort-row { padding: 4px 12px; }

  /* Element list takes remaining space */
  #el-list {
    flex: 1; overflow-y: auto; padding: 6px 10px;
    display: flex; flex-wrap: wrap; align-content: flex-start;
    gap: 6px;
  }

  .s-el {
    padding: 8px 12px; font-size: 13px;
  }
  .s-el .em { font-size: 15px; }
  .s-el .nm { font-size: 12px; }

  #sidebar-foot { display: none; }

  /* Mobile bar fixed at bottom */
  #mobile-bar {
    display: flex; order: 2;
    position: fixed; bottom: 0; left: 0; right: 0;
  }

  /* Loader center */
  #loader { inset: 0; }
  #mix-card { padding: 24px 28px; }

  /* Mike — fixed top on mobile */
  #mike {
    position: fixed; top: 0; left: 0; right: 0;
    bottom: auto; max-width: none;
    padding: 8px 10px; pointer-events: auto;
    z-index: 70;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
  }
  #mike-inner { align-items: center; }
  #mike-face { width: 40px; height: 40px; }
  #mike-face img { border-width: 2px; }
  #mike-bubble {
    background: var(--card);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    padding: 6px 10px;
  }
  #mike-text { font-size: 11px; }
  #mike-share { font-size: 10px; padding: 2px 8px; }

  /* Push sidebar below mike bar */
  #sidebar { margin-top: 56px; height: calc(100vh - 56px - 62px); }

  /* Discovery popup */
  #popup { top: 10px; }
  #popup-inner { padding: 8px 14px; gap: 6px; }
  #popup-label { font-size: 11px; }
  #popup-emoji { font-size: 16px; }
  #popup-name { font-size: 13px; }

  /* Toast */
  #toast { bottom: 80px; }
}

@media (max-width: 400px) {
  .slot { max-width: 100px; padding: 8px 6px; font-size: 12px; }
  #mix-btn { padding: 8px 16px; font-size: 13px; }
  .s-el { padding: 7px 10px; }
  #mike-bubble { max-width: 180px; }
}
