:root {
  --bg-color: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.7);
  --text-color: #f8fafc;
  --accent-color: #ef4444;
  /* Red-500 */
  --bit-off: rgba(255, 255, 255, 0.1);
  --bit-border: rgba(255, 255, 255, 0.1);
  --input-bg: rgba(15, 23, 42, 0.6);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --panel-bg: rgba(15, 23, 42, 0.4);
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Space Grotesk', sans-serif;
  background-color: var(--bg-color);
  background-image:
    radial-gradient(at 0% 0%, rgba(239, 68, 68, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.15) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.app-container {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 2rem;
  border-radius: 24px;
  border: var(--glass-border);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  max-width: 1000px;
  width: 95%;
  height: 85vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

header h1 {
  font-weight: 700;
  font-size: 2rem;
  margin: 0 0 0.5rem 0;
  background: linear-gradient(to right, #fff, #94a3b8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

header p {
  color: #94a3b8;
  margin: 0;
  font-size: 1rem;
}

/* Main Layout */
.main-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  flex: 1;
  min-height: 0;
  align-items: start;
}

/* Input Panel */
.input-panel {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 1.5rem;
  border: var(--glass-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  height: 100%;
  box-sizing: border-box;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0px;
  height: 40px;
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1.2rem;
  margin: 0;
  color: #e2e8f0;
}

.inputs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Increased to 8px for square grid match */
  margin-top: 1rem;
}

.input-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.2);
  padding: 0 0.75rem;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  height: 32px;
  /* Matches bit height for square grid */
  box-sizing: border-box;
}

.input-group:hover {
  background: rgba(0, 0, 0, 0.4);
  border-color: rgba(255, 255, 255, 0.1);
}

.input-group:focus-within {
  border-color: var(--accent-color);
  background: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.input-group label {
  font-size: 0.85rem;
  color: #cbd5e1;
  /* Brighter label */
  font-weight: 500;
}

.decimal-input {
  background: transparent;
  border: none;
  color: white;
  font-family: 'Space Grotesk', monospace;
  font-size: 1rem;
  width: 60px;
  text-align: right;
  outline: none;
  padding: 0;
}

.decimal-input:focus {
  color: var(--accent-color);
  /* Kept text color accent */
}

/* Display Panel */
.display-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  height: 100%;
  box-sizing: border-box;
}

.patterns-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Strict match to inputs-list (8px) */
  margin-top: 1rem;
  /* Match input-list margin */
}

.bit-row {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  border-radius: 0;
  transition: background 0.2s;
  height: 32px;
  /* Match input-group height */
}

.bit-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.bits-container {
  display: flex;
  gap: 8px;
  /* 8px horizontal gap for perfect square */
}

.bit {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  background: var(--bit-off);
  border: var(--glass-border);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  cursor: pointer;
  /* Interactive */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  user-select: none;
}

.bit:hover {
  background: rgba(255, 255, 255, 0.2);
  /* Hover affordance */
  border-color: rgba(255, 255, 255, 0.3);
}

.bit::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 100%);
}

.bit.active {
  background: var(--accent-color);
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
  border-color: rgba(239, 68, 68, 0.5);
  transform: scale(1.05);
}

/* Mobile Toggle - Top Left */
.mobile-toggle {
  display: none;
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--card-bg);
  border: var(--glass-border);
  color: white;
  backdrop-filter: blur(10px);
  z-index: 100;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.mobile-toggle:active {
  transform: scale(0.95);
  background: var(--accent-color);
}

/* Secondary Button Styles */
.display-controls {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: var(--glass-border);
  color: #cbd5e1;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.secondary-btn:active {
  transform: scale(0.98);
}

.secondary-btn.active {
  background: var(--accent-color);
  color: white;
  border-color: transparent;
}

/* Hide spin buttons */
.decimal-input::-webkit-outer-spin-button,
.decimal-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Footer Styles */
.credits {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.25rem;
}

.credit-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.credit-icon.avatar {
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.credit-link {
  color: #94a3b8;
  text-decoration: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.credit-link:hover {
  color: #60a5fa;
  text-decoration: underline;
}

.close-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
}

.mobile-only {
  display: none;
}

/* Responsive & Mobile */
@media (max-width: 700px) {
  .app-container {
    height: 100vh;
    width: 100%;
    border-radius: 0;
    padding: 1rem;
    padding-top: 5rem;
  }

  .main-layout {
    grid-template-columns: 1fr;
    gap: 0;
    overflow-y: auto;
    display: block;
  }

  .patterns-list {
    margin-top: 0;
  }

  /* Input panel becomes a drawer or overlay on mobile */
  .input-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100%;
    z-index: 200;
    background: #0f172a;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 50px rgba(0, 0, 0, 0.5);
    padding-top: 5rem;
    /* Space for hidden toggle area so controls are lower? No, toggle is z-index 100, drawer 200. Drawer covers toggle? */
    /* Let's keep toggle visible or allow closing via X */
  }

  .input-panel.active {
    transform: translateX(0);
  }

  .display-panel {
    background: transparent;
    padding: 0;
    height: auto;
  }

  .mobile-toggle {
    display: flex;
  }

  .mobile-only {
    display: block;
  }

  /* On mobile, we hide the desktop "Patterns" header, 
     but the inputs panel has its own header. */
  .desktop-hidden {
    display: none;
  }

  .bits-container {
    justify-content: center;
  }
}