:root {
  /* Colors - Light Theme (Soft Mist) */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  
  --border-light: rgba(0, 0, 0, 0.08);
  --border-focus: #000000;
  
  --accent-primary: #000000;
  --accent-primary-rgb: 0, 0, 0;
  --accent-hover: #333333;
  --accent-text: #ffffff;
  
  --nav-bg: rgba(255, 255, 255, 0.8);
  --nav-border: rgba(0, 0, 0, 0.05);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.04);
  
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.03);
}

[data-theme='light'] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --border-light: rgba(0, 0, 0, 0.08);
  --border-focus: #000000;
  --accent-primary: #000000;
  --accent-primary-rgb: 0, 0, 0;
  --accent-hover: #333333;
  --accent-text: #ffffff;
  --nav-bg: rgba(255, 255, 255, 0.85);
}

[data-theme='dark'] {
  --bg-primary: #050505;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #141414;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --border-light: rgba(255, 255, 255, 0.1);
  --border-focus: #ffffff;
  --accent-primary: #ffffff;
  --accent-primary-rgb: 255, 255, 255;
  --accent-hover: #e4e4e7;
  --accent-text: #000000;
  --nav-bg: rgba(11, 17, 33, 0.85);
}

/* Regex Highlighting */
.regex-match {
  background: rgba(59, 130, 246, 0.2);
  border-bottom: 2px solid #3b82f6;
  color: var(--text-primary);
  font-weight: 700;
  padding: 0 1px;
  border-radius: 2px;
}

/* Base Reset & Typography */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* App Layout - Sidebar + Main Content */
.app-layout {
  display: grid;
  grid-template-areas: 
    "sidebar top-nav"
    "sidebar main";
  grid-template-columns: 280px 1fr;
  grid-template-rows: 72px 1fr;
  min-height: 100vh;
}

@media (max-width: 1024px) {
  .app-layout {
    display: flex;
    flex-direction: column;
  }
}

/* Prevent transitions on initial load (FOUC) */
.preload * {
  -webkit-transition: none !important;
  -moz-transition: none !important;
  -ms-transition: none !important;
  -o-transition: none !important;
  transition: none !important;
}

/* Top Navigation (Header) */
.top-nav {
  grid-area: top-nav;
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  background: var(--nav-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  transition: all 0.4s ease;
}

.nav-container {
  max-width: 1400px; /* Wider for more tools */
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 72px; /* Slightly taller for elegance */
  display: flex;
  align-items: center;
  gap: 2rem;
}

.brand {
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Dropdown Navigation */
/* Sidebar Navigation */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  z-index: 100;
}

@media (max-width: 1024px) {
  .sidebar {
    display: none;
  }
}

.sidebar-header {
  padding: 0 1.5rem 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 1.5rem;
}

.sidebar-body {
  flex-grow: 1;
  padding: 0 0.75rem;
}

.sidebar-category {
  margin-bottom: 1.5rem;
}

.sidebar-category-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0;
}

/* Custom Premium Checkbox/Radio Styling */
.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

/* Segmented Control / Card Radio Buttons */
.radio-group, .checkbox-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.radio-group label, .checkbox-group label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border: 2px solid var(--border-light);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 0;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

.radio-group input, .checkbox-group input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.radio-group label:hover, .checkbox-group label:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.radio-group input:checked + span, .checkbox-group input:checked + span {
  color: var(--accent-primary);
}

.radio-group label:has(input:checked), .checkbox-group label:has(input:checked) {
  background: rgba(var(--accent-primary-rgb), 0.1);
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.sidebar-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--accent-primary);
  color: var(--accent-text);
}

/* Hide desktop-only elements */
.nav-links {
  display: none;
}

.nav-links::-webkit-scrollbar {
  display: none; /* Hide scrollbar Chrome/Safari */
}

.nav-dropdown {
  position: relative;
  flex-shrink: 0;
}

.nav-dropdown-btn {
  white-space: nowrap;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
  border-radius: 8px;
}

.nav-dropdown-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-dropdown-content {
  position: absolute;
  top: 100%;
  left: 0;
  background: transparent; /* Changed to transparent to allow padding-top gap */
  min-width: 320px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  padding-top: 12px; /* This creates the gap but keeps the hover state */
}

/* Inner container for the actual menu */
.nav-dropdown-inner {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
  padding: 1rem;
}

/* Invisible bridge to prevent menu from closing when moving mouse */
.nav-dropdown::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 20px;
  z-index: 99;
}

.nav-dropdown:hover .nav-dropdown-content {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: block;
  padding: 0.75rem 1rem;
  text-decoration: none;
  border-radius: 12px;
  transition: all 0.2s ease;
}

.dropdown-item:hover {
  background: var(--bg-tertiary);
}

.dropdown-item-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.1rem;
}

.dropdown-item-desc {
  display: block;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  margin-left: auto;
}

.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.mobile-menu-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  width: 40px;
  height: 40px;
  display: none; /* Hidden on desktop */
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.theme-toggle:hover, .mobile-menu-toggle:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
  transform: translateY(-2px);
}

/* Main Content Area */
.main {
  flex-grow: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 5rem 1.5rem;
}

/* Header Sections */
header {
  margin-bottom: 4rem;
  text-align: center;
}

h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  line-height: 1.1;
}

.description {
  font-size: 1.25rem;
  color: var(--text-secondary);
  font-weight: 500;
  opacity: 0.8;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 32px;
  padding: 3.5rem;
  box-shadow: var(--glass-shadow);
}

/* Forms */
.form-group {
  margin-bottom: 2.5rem;
}

label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 1.25rem 1.5rem;
  background-color: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: 16px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 1rem;
  transition: all 0.2s ease;
}

textarea:focus, input:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: var(--bg-secondary);
}

/* Result Area */
.result-box {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 2rem;
  position: relative;
  min-height: 160px;
}

.result-text {
  word-break: break-all;
  white-space: pre-wrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  color: var(--text-primary);
  line-height: 1.7;
}

.copy-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.6rem 1.2rem;
  border-radius: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}

.copy-btn:hover {
  background: var(--accent-primary);
  color: var(--accent-text);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

/* Buttons */
.btn-group {
  display: flex;
  gap: 1rem;
  margin-bottom: 3rem;
}

.btn {
  padding: 1rem 2rem;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn:hover {
  background: var(--accent-primary);
  color: var(--accent-text);
  transform: translateY(-2px);
}

/* Footer */
.footer {
  padding: 5rem 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border-light);
}

.footer-content p {
  color: var(--text-tertiary);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  z-index: 1000;
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  display: none;
}

.mobile-menu-overlay.active {
  transform: translateX(0);
}

.mobile-menu-content {
  padding: 2rem 1.5rem;
  max-width: 600px;
  margin: 0 auto;
}

.mobile-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
}

.mobile-menu-close {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
}

.mobile-category {
  margin-bottom: 2.5rem;
}

.mobile-category-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 800;
  color: var(--text-tertiary);
  margin-bottom: 1rem;
  padding-left: 0.5rem;
}

.mobile-category-items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.mobile-item {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.mobile-item:active {
  transform: scale(0.97);
}

.mobile-item.active {
  border-color: var(--accent-primary);
  background: var(--bg-tertiary);
}

/* Responsive Fixes */
@media (max-width: 1024px) {
  .nav-links {
    display: none; /* Switch to mobile menu earlier */
  }
  .mobile-menu-toggle {
    display: flex;
  }
  .mobile-menu-overlay {
    display: block;
  }
}

@media (max-width: 640px) {
  .mobile-category-items {
    grid-template-columns: 1fr;
  }
  .main {
    padding: 2rem 1rem;
  }
  h1 {
    font-size: 2.25rem;
  }
}
