/* ========================================
   CharacterCalc.com - Design System
   Premium Dark Theme
   ======================================== */

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

/* ---------- CSS Variables ---------- */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #22263280;
  --bg-card-solid: #222632;
  --bg-sidebar: #161820;
  --bg-input: #1e2130;
  --bg-hover: #2a2e3d;

  --text-primary: #e8eaf0;
  --text-secondary: #9ca3b4;
  --text-muted: #636b80;
  --text-accent: #6c8cff;

  --accent: #6c8cff;
  --accent-light: #8fa8ff;
  --accent-dark: #4a6ae0;
  --accent-glow: rgba(108, 140, 255, 0.15);
  --accent-gradient: linear-gradient(135deg, #6c8cff, #a78bfa);

  --green: #34d399;
  --orange: #fb923c;
  --pink: #f472b6;
  --cyan: #22d3ee;
  --yellow: #fbbf24;
  --red: #f87171;

  --border: #2a2e3d;
  --border-light: #353a4d;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --sidebar-width: 260px;
  --header-height: 64px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-light);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

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

/* ---------- Header ---------- */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 2px 12px rgba(108, 140, 255, 0.3);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-nav a {
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
}

.header-nav a:hover,
.header-nav a.active {
  color: var(--text-primary);
  background: var(--accent-glow);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
}

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  padding-top: var(--header-height);
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 0;
  z-index: 900;
  transition: transform var(--transition);
}

.sidebar-section {
  padding: 0 16px;
  margin-bottom: 24px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0 12px;
  margin-bottom: 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 450;
  transition: all var(--transition);
  position: relative;
}

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

.sidebar-link.active {
  color: var(--accent);
  background: var(--accent-glow);
  font-weight: 600;
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent-gradient);
  border-radius: 0 3px 3px 0;
}

.sidebar-link-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 28px;
  min-width: 0;
  max-width: 1000px;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 24px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---------- Counter Layout ---------- */
.counter-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition);
}

.card:hover {
  border-color: var(--border-light);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 0;
}

/* ---------- Textarea ---------- */
.text-input-area {
  width: 100%;
  min-height: 420px;
  padding: 20px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  line-height: 1.7;
  resize: vertical;
  outline: none;
}

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

/* ---------- Upload Button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.btn:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-light);
  color: #fff;
  box-shadow: 0 4px 16px rgba(108, 140, 255, 0.3);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  gap: 8px;
}

.card-actions-left {
  display: flex;
  gap: 8px;
}

.card-actions-right {
  display: flex;
  gap: 8px;
}

/* ---------- Stats Panel ---------- */
.stats-panel .card-body {
  padding: 8px 0;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  transition: background var(--transition);
}

.stat-row:hover {
  background: var(--bg-hover);
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 450;
}

.stat-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.stat-icon.chars {
  background: rgba(108, 140, 255, 0.12);
  color: var(--accent);
}

.stat-icon.no-space {
  background: rgba(251, 191, 36, 0.12);
  color: var(--yellow);
}

.stat-icon.cpw {
  background: rgba(244, 114, 182, 0.12);
  color: var(--pink);
}

.stat-icon.words {
  background: rgba(52, 211, 153, 0.12);
  color: var(--green);
}

.stat-icon.unique {
  background: rgba(34, 211, 238, 0.12);
  color: var(--cyan);
}

.stat-icon.sentences {
  background: rgba(251, 146, 60, 0.12);
  color: var(--orange);
}

.stat-icon.paragraphs {
  background: rgba(167, 139, 250, 0.12);
  color: #a78bfa;
}

.stat-icon.reading {
  background: rgba(248, 113, 113, 0.12);
  color: var(--red);
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

/* ---------- Tool Page Layouts ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.tool-single {
  max-width: 800px;
}

.tool-textarea {
  width: 100%;
  min-height: 260px;
  padding: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}

.tool-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.tool-textarea::placeholder {
  color: var(--text-muted);
}

.tool-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.tool-result {
  padding: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 100px;
}

.tool-result-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.tool-result-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

/* ---------- Input Groups ---------- */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

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

.input-field {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
}

.input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select.input-field {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239ca3b4' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ---------- Diff / Compare ---------- */
.diff-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.diff-added {
  background: rgba(52, 211, 153, 0.1);
  color: var(--green);
}

.diff-removed {
  background: rgba(248, 113, 113, 0.1);
  color: var(--red);
}

/* ---------- Footer ---------- */
.footer {
  margin-left: var(--sidebar-width);
  padding: 32px 28px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 20px;
}

.footer-links a {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: color var(--transition);
}

.footer-links a:hover {
  color: var(--text-primary);
}

/* ---------- Legal Pages ---------- */
.legal-content {
  max-width: 780px;
  line-height: 1.8;
}

.legal-content h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 32px 0 12px;
  color: var(--text-primary);
}

.legal-content h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text-primary);
}

.legal-content p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-size: 0.925rem;
}

.legal-content ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

.legal-content li {
  color: var(--text-secondary);
  font-size: 0.925rem;
  margin-bottom: 6px;
}

/* ---------- Toast Notification ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  padding: 12px 20px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  color: var(--green);
}

/* ---------- Marquee / Scrolling ---------- */
.marquee-container {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  background: var(--bg-input);
}

.marquee-text {
  white-space: nowrap;
  display: inline-block;
  animation: marquee-scroll 10s linear infinite;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

@keyframes marquee-scroll {
  0% {
    transform: translateX(100%);
  }

  100% {
    transform: translateX(-100%);
  }
}

/* ---------- Font Preview ---------- */
.font-preview-card {
  padding: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  transition: border-color var(--transition);
}

.font-preview-card:hover {
  border-color: var(--accent);
}

.font-preview-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.font-preview-text {
  font-size: 1.25rem;
  color: var(--text-primary);
  line-height: 1.6;
}

/* ---------- Invisible Char ---------- */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.char-item {
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.char-item:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.char-item-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.char-item-code {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* ---------- Header Right ---------- */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Language Switcher ---------- */
.lang-switcher {
  position: relative;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.lang-btn:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

.lang-flag {
  font-size: 1rem;
}

.lang-code {
  text-transform: uppercase;
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s ease;
  z-index: 1100;
}

.lang-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: all var(--transition);
}

.lang-option:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.lang-option.active {
  background: var(--accent-glow);
  color: var(--accent);
}

/* ---------- SEO Content Section ---------- */
.seo-section {
  margin-top: 48px;
  padding: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.seo-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.seo-section>p {
  color: var(--text-secondary);
  font-size: 0.925rem;
  margin-bottom: 24px;
  max-width: 700px;
}

.seo-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.seo-feature {
  padding: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition);
}

.seo-feature:hover {
  border-color: var(--accent);
}

.seo-feature h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.seo-feature p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .counter-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content,
  .footer {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: block;
  }

  .tool-grid,
  .diff-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .main-content {
    padding: 20px 16px;
  }

  .header {
    padding: 0 16px;
  }

  .page-title {
    font-size: 1.35rem;
  }

  .card-actions {
    flex-direction: column;
  }

  .card-actions-left,
  .card-actions-right {
    width: 100%;
  }

  .card-actions-left .btn,
  .card-actions-right .btn {
    flex: 1;
    justify-content: center;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px 16px;
  }
}

/* ---------- Overlay for mobile sidebar ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 899;
}

.sidebar-overlay.show {
  display: block;
}

/* ---------- Ad Slot System ---------- */
.ad-slot {
  text-align: center;
  overflow: hidden;
}

.ad-top {
  margin-top: var(--header-height);
  min-height: 90px;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
}

.ad-bottom {
  min-height: 90px;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
  padding: 8px 24px;
  border-top: 1px solid var(--border);
}

.ad-column {
  width: 160px;
  flex-shrink: 0;
  padding: 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ad-sidebar-slot {
  min-height: 250px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Hide ad columns on smaller screens */
@media (max-width: 1200px) {
  .ad-column {
    display: none;
  }
}

@media (max-width: 768px) {

  .ad-top,
  .ad-bottom {
    min-height: 50px;
    padding: 4px 16px;
  }
}

/* Ad slot active state (when ad code is loaded) */
.ad-slot:empty {
  display: none;
}

.ad-slot:not(:empty) {
  display: block;
}

.ad-column .ad-slot:not(:empty) {
  display: flex;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

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

.animate-in {
  animation: fadeInUp 0.5s ease-out forwards;
}

.animate-delay-1 {
  animation-delay: 0.05s;
}

.animate-delay-2 {
  animation-delay: 0.1s;
}

.animate-delay-3 {
  animation-delay: 0.15s;
}