@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;700&display=swap');

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* --- Design Tokens --- */
:root {
  /* Background */
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  --bg-primary: #0f172a;
  --bg-secondary: #764ba2;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-edit: #141e2e;
  --bg-focus: rgba(99, 102, 241, 0.1);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.2);
  --border-highlight: #3b4f74;
  --box-shadow: rgba(99, 102, 241, 0.3);

  /* Text */
  --text-primary: #e8ecf4;
  --text-secondary: #8895ad;
  --text-muted: #94a3b8;

  /* Accents */
  --accent: #667eea;

  --bg-bit-off: #334155;
  --text-bit-off: #94a3b8;

  --bg-bit-active: rgba(59, 130, 246, 0.5);
  --text-bit-active: #ffffff;
  --text-int-bit-active: #ffffff;
  --border-int-bit: 1px solid #0c4a6e;

  --bg-sign: #450a0a;
  --text-sign: #ef4444;
  --border-sign: rgba(239, 68, 68, 0.5);

  --bg-exp: #052e16;
  --text-exp: #22c55e;
  --border-exp: rgba(34, 197, 94, 0.5);

  --bg-mant: #172554;
  --text-mant: #3b82f6;
  --border-mant: rgba(59, 130, 246, 0.5);

  --hex: #38bdf8;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  /* Header Controls */
  --control-height: 2.4rem;
  --control-height-sm: 1.78rem;
  --control-height-xs: 1.64rem;

  /* Shadows */
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
  --shadow-glow: 0 0 30px rgba(59, 130, 246, 0.08);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;

  /* Transitions */
  --transition: 0.2s ease;
}

/* ===== Light Theme Overrides ===== */
.light-theme {
  --bg-primary: #f1f5f9;
  --bg-secondary: #c7d2fe;
  --bg-card: rgba(255, 255, 255, 0.7);
  --bg-edit: white;
  --border-subtle: rgba(148, 163, 184, 0.5);
  --border-highlight: #9ca3af;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #60738f;

  --bg-bit-off: #e3e4ff;
  --text-bit-off: #94a3b8;
  --text-int-bit-active: #94a3b8;
  --border-int-bit: 1px solid rgb(179, 200, 224);

  --shadow-card: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 25px rgba(59, 130, 246, 0.1);

  background-image:
    radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(168, 85, 247, 0.1) 0%, transparent 50%);
}

body {
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(168, 85, 247, 0.15) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  overflow-x: hidden;
}

body::selection {
  background: var(--bg-secondary);
  color: white;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  width: 100%;
  max-width: 960px;
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title {
  font-family: 'Outfit', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  margin: 0 1rem 0.5rem;
  background: var(--gradient-primary);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.subtitle {
  font-size: 0.9rem;
  text-align: center;
  color: var(--text-muted);
  margin: 0 1rem 1rem;
}

.title-icon {
  height: 2rem;
  width: auto;
  vertical-align: middle;
  margin-right: 1rem;
  filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
  transition: transform 0.3s ease;
  animation: float 3s ease-in-out infinite;
}

.title:hover .title-icon {
  transform: scale(1.1) rotate(15deg);
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

/* ============================================
   THEME AND LANGUAGE SWITCHER
   ============================================ */
.theme-lang-switcher {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  display: flex;
  gap: 0.5rem;
  z-index: 100;
}

/* ===== THEME TOGGLE ===== */
.theme-toggle-group {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.theme-toggle-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: 1px solid var(--border-subtle);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transform: translateY(0) scale(0.94);
  opacity: 0.5;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
}

.theme-toggle-btn:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  opacity: 0.95;
}

.theme-toggle-btn:hover svg {
  transform: translateY(-1px);
}

.theme-toggle-btn:active {
  transform: scale(0.95);
}

.theme-toggle-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35), 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.theme-toggle-btn.is-active {
  opacity: 1;
  transform: translateY(-1px) scale(1);
}

.light-theme .theme-toggle-btn {
  box-shadow: 0 8px 22px rgba(59, 130, 246, 0.24);
}

.version-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 2px 10px;
  border-radius: 100px;
}

/* ===== LANGUAGE SELECTOR ===== */
.lang-select {
  box-sizing: border-box;
  background: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  height: var(--control-height);
  padding: 0 2.5rem 0 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.3s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 14px 14px;
  outline: none;
}

.lang-select:hover {
  border-color: var(--border-highlight);
  color: var(--text-primary);
  transform_: translateY(-2px);
}

.lang-select:focus {
  box-shadow: 0 0 0 2px var(--shadow-glow);
}

.lang-select option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  padding: 10px;
}

.light-theme .lang-select {
  box-shadow: 0 1px 1px rgba(59, 130, 246, 0.06);
}

select,
input {
  background: var(--bg-edit);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.2rem 2.5rem 0.2rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

select:hover,
input:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

select:hover {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667eea' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

select:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--box-shadow);
}

input:focus {
  background: var(--bg-focus);
}

select option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  padding: 10px;
}

/* ============================================
   MAIN
   ============================================ */
#app-main {
  width: 100%;
  max-width: 1600px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  margin-bottom: 1.5rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  gap: 1rem;
  display: flex;
  flex-direction: column;
  flex: 1 1 300px;
  opacity: 0;
}

.is-ready .glass-card {
  animation: fadeIn 0.8s ease-out forwards;
}

.glass-card:hover {
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.section-header {
  color: var(--accent);
}

label {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Text Input */
.text-input {
  padding: 0.75rem 1rem;

  font-family: var(--font-mono);
  font-size: 1.25rem;

}

.visualizations {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.card-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.badge {
  background: var(--bg-primary);
  color: var(--text-secondary);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border-subtle);
}

.info-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-item:first-child {
  flex: 1 1 100%;
}

.info-item .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.value {
  font-family: var(--font-mono);
  font-size: 1rem;
}

.hex-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--hex);
  max-width: 340px;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-md);
  cursor: text;
  box-shadow: none;
  transition: all 0.2s;
}

.hex-input:hover {

  border-color: var(--border-subtle);
  color: var(--hex);
}

.hex-input:focus {
  background: var(--bg-primary);
  border-color: var(--hex);
  outline: none;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.bits-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-family: var(--font-mono);
}

.bit-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.group-label {
  font-size: 0.75rem;
  font-weight: 500;
}

.sign .group-label {
  color: var(--text-sign);
}

.exponent .group-label {
  color: var(--text-exp);
}

.mantissa .group-label {
  color: var(--text-mant);
}

.bits {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.bit {
  width: 24px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-bit-off);
  color: var(--text-bit-off);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: all 0.1s;
  font-size: 0.9rem;
}

.bit:hover {
  filter: brightness(1.2);
  transform: translateY(-2px);
}

.bit.active {
  background: var(--bg-bit-active);
  color: var(--text-bit-active);
  font-weight: bold;
}

.sign .bit {
  border: 1px solid var(--border-sign);
}


.sign .bit.active {
  background: var(--text-sign);
}

.exponent .bit {
  border: 1px solid var(--border-exp);
}

.exponent .bit.active {
  background: var(--text-exp);
}

.mantissa .bit {
  border: 1px solid var(--border-mant);
}

.mantissa .bit.active {
  background: var(--text-mant);
}

.integer-bits .bit {
  border: var(--border-int-bit);
}

.integer-bits .bit.active {
  border-width: 1px;
}

.integer-bits .bit:not(.active) {
  border: var(--border-int-bit);
  /* darker accent */
}

/* Nibble Alternating Colors */
.integer-bits .bit.nibble-odd {
  background: var(--bg-card);
  border: var(--border-int-bit);
}

.integer-bits .bit.nibble-odd.active {

  color: var(--text-int-bit-active);
  /* distinct from normal active */
}

.bit-byte-end {
  margin-right: 0.75rem;
  /* Space between bytes */
}

.equation-display {
  margin-top: auto;
  background: var(--bg-primary);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================
   FOOTER
   ============================================ */
.app-footer {
  width: 100%;
  max-width: 1100px;
  margin: auto auto 0;
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: center;
  position: relative;
}

.footer-content {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 0 1rem;
  color: var(--text-muted);
}

.footer-title {
  font-weight: 500;
  font-size: 0.85rem;
}

.footer-separator {
  color: var(--border-subtle);
  user-select: none;
}

.footer-content a {
  color: #a78bfa;
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.footer-content a:hover {
  color: #764ba2;
  filter: brightness(1.2);
}

/* ============================================
   SCROLL-TO-TOP BUTTON
   ============================================ */
.scroll-top-btn {
  position: fixed;
  right: 2rem;
  bottom: 2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: 1px solid var(--border-subtle);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
}

.scroll-top-btn.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top-btn svg {
  transition: transform 0.3s ease;
}

.scroll-top-btn:hover {
  transform: translateY(-5px) scale(1.1);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.scroll-top-btn:hover svg {
  transform: translateY(-2px);
}

.scroll-top-btn:active {
  transform: scale(0.95);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1100px) {
  .theme-lang-switcher {
    top: 0.55rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    gap: 0.4rem;
  }

  .header {
    padding-top: 3.1rem;
  }

  .title {
    font-size: 1.8rem;
    line-height: 1.2;
  }
}

@media (max-width: 800px) {
  .theme-lang-switcher {
    top: 0.5rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    gap: 0.35rem;
  }

  .theme-toggle-group {
    height: var(--control-height-sm);
    padding: 0 0.16rem;
    gap: 0.22rem;
  }

  .theme-toggle-btn {
    width: 1.72rem;
    height: 1.72rem;
  }

  .theme-toggle-btn svg {
    width: 13px;
    height: 13px;
  }

  .lang-select {
    height: var(--control-height-sm);
    font-size: 0.82rem;
    padding: 0 2.2rem 0 0.7rem;
    background-position: right 0.6rem center;
  }
}

@media (max-width: 600px) {
  .footer-content {
    gap: 0.75rem;
  }

  .scroll-top-btn {
    right: 1.5rem;
    bottom: 1.5rem;
  }

  .bits-container {
    flex-direction: column;
    gap: 1.5rem;
  }

  .input-section {
    padding: 1rem;
  }

  .card {
    padding: 1rem;
  }
}

@media (max-width: 380px) {
  .theme-lang-switcher {
    top: 0.45rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .theme-toggle-btn {
    width: 1.58rem;
    height: 1.58rem;
  }

  .lang-select {
    height: var(--control-height-xs);
    max-width: 7.9rem;
    font-size: 0.78rem;
  }

  .theme-toggle-group {
    height: var(--control-height-xs);
  }
}

