/* LEGO Themed 3D Buttons & UI Components */

/* Base 3D LEGO Button */
.lego-btn {
  background: var(--lego-blue);
  color: var(--text-white);
  border: none;
  outline: none;
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  box-shadow:
    0 5px 0 var(--lego-blue-dark),
    0 8px 15px rgba(0, 0, 0, 0.6),
    inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(0);
  letter-spacing: 0.3px;
}

.lego-btn:hover {
  background: var(--lego-blue-bright);
  box-shadow:
    0 5px 0 var(--lego-blue-dark),
    0 10px 20px rgba(0, 85, 191, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
}

.lego-btn:active {
  background: var(--lego-blue-dark);
  box-shadow:
    0 1px 0 var(--lego-blue-dark),
    0 3px 6px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: translateY(4px);
}

.lego-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 3px 0 #1e293b;
  background: #334155;
}

/* Stud Accents on larger buttons */
.lego-btn.has-studs::before,
.lego-btn.has-studs::after {
  content: '';
  position: absolute;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.4), 0 2px 3px rgba(0, 0, 0, 0.4);
}

.lego-btn.has-studs::before {
  left: 8px;
}

.lego-btn.has-studs::after {
  right: 8px;
}

/* Large Action Button */
.lego-btn-lg {
  font-size: 1.25rem;
  padding: 16px 32px;
  border-radius: var(--radius-lg);
  box-shadow:
    0 7px 0 var(--lego-blue-dark),
    0 12px 25px rgba(0, 85, 191, 0.45),
    inset 0 3px 0 rgba(255, 255, 255, 0.4);
}

.lego-btn-lg:hover {
  transform: translateY(-3px);
  box-shadow:
    0 8px 0 var(--lego-blue-dark),
    0 15px 30px rgba(0, 85, 191, 0.6),
    inset 0 3px 0 rgba(255, 255, 255, 0.6);
}

.lego-btn-lg:active {
  transform: translateY(5px);
  box-shadow:
    0 2px 0 var(--lego-blue-dark),
    0 4px 8px rgba(0, 0, 0, 0.6);
}

/* Staging Tray (Top-Left Equation Area) */
.staging-tray-container {
  background: var(--bg-card-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-xl);
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-subtle);
  position: relative;
  overflow: hidden;
}

.staging-tray-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--lego-blue), var(--accent-cyan), var(--lego-green));
}

.staging-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.staging-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.staging-equation {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

/* Glowing Staging Number Slots */
.staging-slot {
  min-width: 100px;
  height: 70px;
  background: rgba(0, 0, 0, 0.6);
  border: 2px dashed var(--accent-cyan);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 0 15px var(--accent-cyan-glow);
  transition: all 0.3s ease;
  padding: 6px 12px;
}

.staging-slot.occupied {
  border-style: solid;
  border-color: var(--accent-cyan);
  background: rgba(0, 210, 255, 0.08);
  box-shadow: 0 0 25px var(--accent-cyan-glow), inset 0 0 10px rgba(0, 210, 255, 0.15);
}

.staging-slot.glow-pulse {
  animation: slotGlowPulse 1.8s infinite alternate;
}

@keyframes slotGlowPulse {
  0% {
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.3);
    border-color: rgba(0, 210, 255, 0.6);
  }

  100% {
    box-shadow: 0 0 30px rgba(0, 210, 255, 0.8), inset 0 0 15px rgba(0, 210, 255, 0.3);
    border-color: var(--accent-cyan);
  }
}

/* Staged Number Tile (with separable digits) */
.staged-number-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 3D LEGO Brick Digit Tile Component (Used in Staging & Grid Cells) */
.digit-tile,
.lego-tile-brick {
  width: 48px;
  height: 58px;
  background: linear-gradient(180deg, #0055BF 0%, #003380 100%);
  border: 2px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  color: var(--text-white);
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  position: relative;
  box-shadow:
    0 4px 0 #002255,
    0 6px 14px rgba(0, 0, 0, 0.6),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
  touch-action: none;
  z-index: 5;
}

.digit-tile:hover {
  transform: translateY(-4px) scale(1.06);
  box-shadow:
    0 6px 0 #002255,
    0 10px 20px rgba(0, 85, 191, 0.5),
    0 0 18px var(--accent-cyan),
    inset 0 2px 0 rgba(255, 255, 255, 0.6);
  border-color: #ffffff;
}

.digit-tile:active,
.digit-tile.dragging {
  cursor: grabbing;
  opacity: 0.88;
  transform: scale(1.12);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.9), 0 0 25px var(--accent-cyan);
  z-index: 1000;
}

.digit-tile.selected {
  outline: 3px solid var(--lego-yellow);
  box-shadow: 0 0 25px rgba(255, 213, 0, 0.9);
  transform: translateY(-5px);
}

/* 3D Circular Studs on Lego Brick Tiles */
.brick-stud,
.digit-tile .stud {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.6), 0 2px 3px rgba(0, 0, 0, 0.5);
}

.brick-stud.top-left,
.digit-tile .stud.top-left {
  top: 4px;
  left: 4px;
}

.brick-stud.top-right,
.digit-tile .stud,
.digit-tile .stud.top-right {
  top: 4px;
  right: 4px;
}

/* Step-Row & Result-Row 3D Tile Variant */
.lego-tile-brick.step-brick {
  background: linear-gradient(180deg, #0077CC 0%, #004D99 100%);
  border-color: #38BDF8;
  width: 52px;
  height: 60px;
  box-shadow:
    0 4px 0 #003366,
    0 6px 12px rgba(0, 0, 0, 0.6),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

/* Golden Result 3D Brick Variant */
.lego-tile-brick.gold-brick {
  background: linear-gradient(180deg, #FFD500 0%, #E69500 100%);
  color: #000000;
  border-color: #FFFFFF;
  width: 58px;
  height: 66px;
  box-shadow:
    0 5px 0 #B37400,
    0 8px 20px rgba(255, 213, 0, 0.6),
    inset 0 3px 0 rgba(255, 255, 255, 0.7);
}

/* Flying Clone for Smooth Smooth Motion into Grid Cells */
.flying-digit-clone {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  will-change: transform;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.8), 0 0 30px var(--accent-cyan);
}

/* Mechanical Tool Operator Box */
.operator-box {
  width: 48px;
  height: 48px;
  background: var(--lego-blue);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text-white);
  box-shadow: 0 4px 0 var(--lego-blue-dark), 0 6px 12px rgba(0, 0, 0, 0.5);
  position: relative;
}

.operator-box.dropping {
  animation: toolDropIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.equals-box {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-dim);
  padding: 0 6px;
}

.question-slot {
  width: 60px;
  height: 52px;
  background: rgba(255, 255, 255, 0.04);
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--lego-yellow);
  font-weight: 800;
}

/* Companion Selection Modal / Screen */
.companion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(16px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.3s ease;
}

.companion-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.companion-card-box {
  max-width: 700px;
  width: 100%;
  background: var(--bg-card-elevated);
  border: 2px solid rgba(0, 85, 191, 0.5);
  border-radius: var(--radius-xl);
  padding: 36px 30px;
  text-align: center;
  box-shadow: 0 0 50px rgba(0, 85, 191, 0.3);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.companion-card-box h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-white);
  letter-spacing: -0.5px;
}

.companion-card-box p {
  color: var(--text-dim);
  font-size: 1.05rem;
}

/* Operation Mode Selector (+ or - or Mixed) */
.operation-select-box {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.op-select-title {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.op-toggle-group {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 520px;
  justify-content: center;
}

.op-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: var(--text-white);
  padding: 12px 14px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.op-btn .op-icon {
  font-size: 1.2rem;
}

.op-btn:hover {
  background: rgba(0, 85, 191, 0.3);
  border-color: var(--lego-blue-bright);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 85, 191, 0.3);
}

.op-btn.active {
  background: var(--lego-blue);
  border-color: var(--accent-cyan);
  box-shadow:
    0 5px 0 var(--lego-blue-dark),
    0 0 20px var(--accent-cyan-glow),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
}

.companion-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 10px;
  width: 100%;
}

.companion-card {
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 22px 16px 18px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 290px;
  height: 100%;
  transition: all 0.2s ease;
}

.companion-card:hover {
  background: rgba(0, 85, 191, 0.15);
  border-color: var(--lego-blue-bright);
  transform: translateY(-6px);
  box-shadow: 0 10px 25px rgba(0, 85, 191, 0.4);
}

.companion-card .avatar-icon {
  width: 96px;
  height: 96px;
  min-width: 96px;
  min-height: 96px;
  border-radius: 50%;
  background: rgba(0, 85, 191, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--lego-blue);
  transition: transform 0.2s ease;
  margin-bottom: 8px;
  padding: 6px;
}

.companion-card .avatar-icon svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.companion-card:hover .avatar-icon {
  transform: scale(1.1) rotate(5deg);
  border-color: var(--accent-cyan);
}

.companion-card .name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-white);
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
  width: 100%;
  margin-bottom: 2px;
}

.companion-card .tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
  width: 100%;
  margin-bottom: 12px;
}

.companion-card button {
  margin-top: auto;
  width: 100%;
  padding: 9px 12px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}