:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel2: #f8fafc;
  --stroke: #e2e8f0;
  --stroke-dark: #cbd5e1;
  --text: #18181b;
  --text-muted: #64748b;
  --item-bg: #ffffff;
  --item-border: #d4d4d8;
  --item-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --item-hover: #f1f5f9;
}

.dark-theme {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #161b22;
  --panel2: #1e2530;
  --stroke: #2d333b;
  --stroke-dark: #444c56;
  --text: #f0f6fc;
  --text-muted: #8b949e;
  --item-bg: #1c2128;
  --item-border: #373e47;
  --item-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --item-hover: #262c36;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button, input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

/* App container layout */
.app {
  height: 100dvh;
  width: 100vw;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  background: var(--bg);
  overflow: hidden;
}

.board-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
}

/* Top Header Bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px 8px;
  background: transparent;
  z-index: 20;
  flex-shrink: 0;
  pointer-events: none;
}

.site-logo {
  pointer-events: auto;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.5px;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.neal-ic-logo {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ic-bracket {
  font-family: monospace, sans-serif;
  font-size: 36px;
  font-weight: 300;
  line-height: 1;
  color: var(--text);
  transform: translateY(-2px);
}

.ic-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.ic-line1 {
  font-family: Georgia, serif;
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.2px;
}

.ic-line2 {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

/* Canvas Area */
.canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background: var(--bg);
}

.stars-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* Floating Bottom Controls right above bottom drawer */
.canvas-floating-bar {
  position: absolute;
  bottom: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 25;
  pointer-events: none;
}

.canvas-bar-left, .canvas-bar-right {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.neal-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--item-border);
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: background 0.15s, border-color 0.15s;
}

.neal-menu-btn:hover {
  background: var(--item-hover);
  border-color: var(--stroke-dark);
}

.menu-icon {
  font-size: 16px;
}

.corner-icon {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  border: 1px solid var(--item-border);
  background: var(--panel);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: background 0.15s, transform 0.1s;
}

.corner-icon:active {
  transform: scale(0.95);
}

.corner-icon:hover {
  background: var(--item-hover);
}

/* Elements on Canvas */
.piece, .board-item {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 6px;
  background: var(--item-bg);
  border: 1px solid var(--item-border);
  color: var(--text);
  box-shadow: var(--item-shadow);
  font-size: 15px;
  font-weight: 500;
  cursor: grab;
  touch-action: none;
  z-index: 10;
  white-space: nowrap;
}

.piece:active, .board-item:active {
  cursor: grabbing;
}

.piece.dragging, .board-item.dragging {
  z-index: 100;
  opacity: 0.95;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transform: scale(1.04);
}

.piece.combine-target, .board-item.combine-target {
  box-shadow: 0 0 0 3px #3b82f6, 0 8px 24px rgba(59, 130, 246, 0.3);
  transform: scale(1.06);
}

.piece.selected-piece {
  border-color: #3b82f6 !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.45), 0 4px 14px rgba(59, 130, 246, 0.25) !important;
  transform: scale(1.05);
}

.merge-particle {
  position: absolute;
  pointer-events: none;
  font-size: 16px;
  line-height: 1;
  z-index: 999;
  user-select: none;
  animation: particleBurst 0.48s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes particleBurst {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0.35); opacity: 0; }
}

.piece.first-discovery, .board-item.first-discovery {
  border-color: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
}

@keyframes popIn {
  0% { transform: scale(0.35); opacity: 0; }
  65% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

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

.piece.new {
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.piece.shake {
  animation: shake 0.35s ease-in-out;
}

/* Toast notifications floating unobtrusively at the top */
.toast-region {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 50;
}

.toast {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--item-border);
  padding: 6px 14px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-size: 13.5px;
  font-weight: 500;
  pointer-events: none;
  white-space: nowrap;
}

/* Sidebar / Bottom Tray */
.inventory {
  border-left: 1px solid var(--stroke);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 30;
  overflow: hidden;
}

/* Single-row Action Controls */
.sidebar-controls {
  padding: 8px 10px;
  border-bottom: 1px solid var(--stroke);
  background: var(--panel);
  flex-shrink: 0;
}

.sidebar-tabs-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.tray-icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--item-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background 0.15s;
}

.tray-icon-btn:hover {
  background: var(--item-hover);
}

.tray-icon-btn[aria-pressed="true"] {
  background: #fef3c7;
  border-color: #f59e0b;
}

.dark-theme .tray-icon-btn[aria-pressed="true"] {
  background: #78350f;
  border-color: #f59e0b;
}

.tray-btn {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--item-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13.5px;
  font-weight: 500;
  flex-shrink: 0;
  transition: background 0.15s;
}

.tray-btn:hover {
  background: var(--item-hover);
}

.search-wrap {
  flex: 1;
  min-width: 0;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--item-border);
  border-radius: 6px;
  background: var(--panel2);
  padding: 0 10px;
}

.search-svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-wrap input {
  width: 100%;
  border: none;
  background: none;
  color: var(--text);
  outline: 0;
  font-size: 13.5px;
}

.search-wrap input::placeholder {
  color: var(--text-muted);
}

/* Discovered items list */
.items {
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 7px;
  padding: 10px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.items::-webkit-scrollbar {
  width: 5px;
}

.items::-webkit-scrollbar-thumb {
  background: var(--stroke-dark);
  border-radius: 5px;
}

.item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  min-height: 34px;
  border-radius: 6px;
  background: var(--item-bg);
  border: 1px solid var(--item-border);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.15;
  box-shadow: var(--item-shadow);
  transition: background 0.1s, border-color 0.1s, transform 0.08s;
  user-select: none;
  touch-action: pan-y;
  white-space: nowrap;
}

.item:hover {
  background: var(--item-hover);
  border-color: var(--stroke-dark);
}

.item:active {
  transform: scale(0.96);
}

.item.first-discovery {
  border-color: #f59e0b;
}

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

.item .name {
  white-space: nowrap;
}

/* Drag ghost for touch */
.touch-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  padding: 7px 12px;
  border-radius: 6px;
  background: var(--item-bg);
  border: 1px solid var(--item-border);
  color: var(--text);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  font-size: 15px;
  font-weight: 500;
  transform: translate(-50%, -50%);
}

/* Modal dialog */
dialog {
  padding: 0;
  border: 1px solid var(--stroke-dark);
  border-radius: 12px;
  max-width: 400px;
  width: calc(100% - 32px);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
}

.dialog-inner {
  padding: 20px;
}

.dialog-close {
  float: right;
  border: none;
  background: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #3b82f6;
  font-weight: 700;
}

h2 {
  font-size: 20px;
  margin: 6px 0 14px;
}

button.primary {
  background: #18181b;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
}

.dark-theme button.primary {
  background: #f0f6fc;
  color: #18181b;
}

.menu-list-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin: 6px 0;
  border-radius: 6px;
  border: 1px solid var(--item-border);
  background: var(--panel2);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s;
}

.menu-list-btn:hover {
  background: var(--item-hover);
}

/* MOBILE ADAPTATION (Exactly matching Neal.fun mobile screenshot) */
@media (max-width: 850px) {
  .app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100vw;
  }

  .topbar {
    padding: 10px 14px 4px;
  }

  .site-logo {
    font-size: 22px;
  }

  .ic-bracket {
    font-size: 32px;
  }

  .ic-line1 {
    font-size: 17px;
  }

  .ic-line2 {
    font-size: 19px;
  }

  .board-shell {
    flex: 1;
    min-height: 0;
  }

  .canvas {
    flex: 1;
    min-height: 0;
  }

  /* Pinned bottom drawer (Always visible!) */
  .inventory {
    height: clamp(190px, 35vh, 270px);
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--stroke);
    flex-shrink: 0;
  }

  .sidebar-controls {
    padding: 6px 8px;
  }

  .sidebar-tabs-row {
    gap: 5px;
  }

  .tray-icon-btn, .tray-btn, .search-wrap {
    height: 34px;
  }

  .tray-btn {
    padding: 0 8px;
    font-size: 12.5px;
  }

  .items {
    padding: 8px;
    gap: 6px;
  }

  .item {
    font-size: 14px;
    padding: 6px 10px;
    min-height: 32px;
  }
}


/* Unified Wonderworld Games Brand Pill */
.ww-home-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
  color: inherit;
  transition: all 0.18s ease;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}
.ww-home-pill:hover {
  background: color-mix(in srgb, currentColor 14%, transparent);
  border-color: color-mix(in srgb, currentColor 32%, transparent);
  transform: translateY(-1px);
  color: inherit;
}
.ww-home-pill .ww-logo-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}
.ww-home-pill .ww-text-short {
  display: none;
}
@media (max-width: 600px) {
  .ww-home-pill {
    padding: 5px 9px 5px 5px;
    gap: 5px;
    font-size: 12.5px;
  }
  .ww-home-pill .ww-text-full {
    display: none;
  }
  .ww-home-pill .ww-text-short {
    display: inline;
  }
}
