/* ============================================================
   Token Counter - SinapseTech
   V.1.0.0
   ============================================================ */

/* --- Design Tokens --- */
:root {
  --deep: #080b16;
  --surface-0: #0d1117;
  --surface-1: rgba(255,255,255,0.03);
  --surface-2: rgba(255,255,255,0.06);
  --surface-3: rgba(255,255,255,0.09);
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);

  --indigo: #6366f1;
  --indigo-light: #818cf8;
  --indigo-dim: rgba(99,102,241,0.12);
  --cyan: #06b6d4;
  --cyan-light: #22d3ee;
  --cyan-dim: rgba(6,182,212,0.12);
  --emerald: #10b981;
  --emerald-light: #34d399;
  --emerald-dim: rgba(16,185,129,0.12);
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --amber-dim: rgba(245,158,11,0.12);
  --rose: #f43f5e;
  --rose-light: #fb7185;
  --rose-dim: rgba(244,63,94,0.12);

  --text-1: #f1f5f9;
  --text-2: rgba(241,245,249,0.65);
  --text-3: rgba(241,245,249,0.4);

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--deep);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* --- Background --- */
.bg-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-scene::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #0f0c29 0%, #1a1145 35%, #0d1f3c 65%, #0a0e1a 100%);
  background-size: 400% 400%;
  animation: bgShift 25s ease infinite;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.2;
  will-change: transform;
}

.bg-orb--1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(99,102,241,0.5), transparent 70%);
  top: -5%; left: -10%;
  animation: orb1 28s ease-in-out infinite;
}

.bg-orb--2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(6,182,212,0.4), transparent 70%);
  bottom: 10%; right: -8%;
  animation: orb2 32s ease-in-out infinite;
}

@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes orb1 {
  0%, 100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(60px,40px) scale(1.1); }
}

@keyframes orb2 {
  0%, 100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(-50px,-30px) scale(1.08); }
}

/* --- Layout --- */
.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 0;
  background: rgba(8,11,22,0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: opacity 0.2s;
}

.logo-link:hover { opacity: 0.8; }

.logo-img {
  height: 30px;
  width: auto;
  filter: drop-shadow(0 2px 8px rgba(99,102,241,0.25));
}

.header-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 9999px;
  background: var(--indigo-dim);
  border: 1px solid rgba(99,102,241,0.2);
  color: var(--indigo-light);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.header-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  transition: color 0.2s;
}

.header-back:hover { color: var(--text-2); }

/* --- Hero --- */
.hero {
  text-align: center;
  padding: 48px 24px 32px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 9999px;
  background: var(--surface-2);
  border: 1px solid var(--border-hover);
  color: var(--cyan-light);
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 20px;
  animation: slideUp 0.6s var(--ease) both;
}

.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 14px;
  letter-spacing: -0.02em;
  animation: slideUp 0.6s 0.08s var(--ease) both;
}

.hero h1 .grad {
  background: linear-gradient(135deg, #e0e7ff, #ffffff 40%, #a5f3fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero p {
  font-size: clamp(0.92rem, 1.5vw, 1.05rem);
  color: var(--text-2);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.7;
  animation: slideUp 0.6s 0.16s var(--ease) both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Main --- */
.main-area {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px 48px;
  flex: 1;
  width: 100%;
}

/* --- Input Section --- */
.input-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 20px;
  animation: slideUp 0.6s 0.24s var(--ease) both;
}

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

.input-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-label i {
  color: var(--indigo-light);
  font-size: 0.85rem;
}

.input-actions {
  display: flex;
  gap: 6px;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}

.btn-sm:hover {
  background: var(--surface-3);
  border-color: var(--border-hover);
  color: var(--text-1);
}

.btn-sm--danger:hover {
  background: var(--rose-dim);
  border-color: rgba(244,63,94,0.3);
  color: var(--rose-light);
}

.input-textarea {
  width: 100%;
  min-height: 200px;
  max-height: 500px;
  padding: 20px;
  background: transparent;
  border: none;
  color: var(--text-1);
  font-family: var(--font);
  font-size: 0.92rem;
  line-height: 1.7;
  resize: vertical;
  outline: none;
}

.input-textarea::placeholder {
  color: var(--text-3);
}

.input-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.char-count {
  font-size: 0.72rem;
  color: var(--text-3);
  font-family: var(--font-mono);
}

/* --- Stats Grid --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
  animation: slideUp 0.6s 0.32s var(--ease) both;
}

.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color 0.3s var(--ease);
}

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

.stat-card--primary {
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(6,182,212,0.04));
  border-color: rgba(99,102,241,0.15);
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--indigo-dim);
  color: var(--indigo-light);
}

.stat-icon--cyan {
  background: var(--cyan-dim);
  color: var(--cyan-light);
}

.stat-icon--amber {
  background: var(--amber-dim);
  color: var(--amber-light);
}

.stat-icon--emerald {
  background: var(--emerald-dim);
  color: var(--emerald-light);
}

.stat-body {
  min-width: 0;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text-1);
  font-family: var(--font-mono);
}

.stat-card--primary .stat-value {
  background: linear-gradient(135deg, var(--indigo-light), var(--cyan-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Ratio Section --- */
.ratio-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
}

.ratio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.ratio-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ratio-title i {
  color: var(--indigo-light);
}

.ratio-value {
  font-size: 0.9rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--indigo-light);
}

.ratio-bar {
  height: 8px;
  border-radius: 9999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-bottom: 12px;
}

.ratio-fill {
  height: 100%;
  border-radius: 9999px;
  background: linear-gradient(90deg, var(--indigo), var(--cyan));
  transition: width 0.6s var(--ease);
}

.ratio-legend {
  display: flex;
  gap: 20px;
}

.ratio-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-3);
}

.ratio-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.ratio-dot--tokens {
  background: var(--indigo);
}

.ratio-dot--words {
  background: var(--surface-3);
}

.ratio-legend-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-2);
}

/* --- Context Window Section --- */
.context-section {
  margin-bottom: 24px;
}

.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-divider-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  white-space: nowrap;
}

.section-divider-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.context-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ctx-bar-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ctx-model {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  min-width: 100px;
  white-space: nowrap;
}

.ctx-track {
  flex: 1;
  height: 10px;
  border-radius: 9999px;
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}

.ctx-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.6s var(--ease);
  min-width: 2px;
}

.ctx-fill--indigo { background: linear-gradient(90deg, var(--indigo), var(--indigo-light)); }
.ctx-fill--cyan { background: linear-gradient(90deg, var(--cyan), var(--cyan-light)); }
.ctx-fill--emerald { background: linear-gradient(90deg, var(--emerald), var(--emerald-light)); }
.ctx-fill--amber { background: linear-gradient(90deg, var(--amber), var(--amber-light)); }

.ctx-pct {
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-3);
  min-width: 48px;
  text-align: right;
}

/* --- Visualization Section --- */
.viz-section {
  margin-bottom: 24px;
}

.viz-header {
  margin-bottom: 12px;
}

.viz-hint {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 8px;
}

.viz-container {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  line-height: 2;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  max-height: 400px;
  overflow-y: auto;
  word-break: break-word;
}

/* Token color palette (12 alternating colors for visual distinction) */
.tk { 
  border-radius: 3px;
  padding: 1px 0;
  cursor: default;
  transition: outline 0.15s ease, background 0.15s ease;
  position: relative;
  display: inline;
  white-space: pre-wrap;
}

.tk:hover {
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 1px;
  z-index: 1;
}

.tk-0  { background: rgba(99,102,241,0.25); }
.tk-1  { background: rgba(6,182,212,0.25); }
.tk-2  { background: rgba(245,158,11,0.25); }
.tk-3  { background: rgba(16,185,129,0.25); }
.tk-4  { background: rgba(244,63,94,0.25); }
.tk-5  { background: rgba(139,92,246,0.25); }
.tk-6  { background: rgba(236,72,153,0.25); }
.tk-7  { background: rgba(14,165,233,0.25); }
.tk-8  { background: rgba(234,179,8,0.22); }
.tk-9  { background: rgba(52,211,153,0.22); }
.tk-10 { background: rgba(251,113,133,0.22); }
.tk-11 { background: rgba(167,139,250,0.22); }

/* Token tooltip */
.tk-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-0);
  border: 1px solid var(--border-hover);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.7rem;
  color: var(--text-2);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.tk:hover .tk-tip {
  opacity: 1;
}

.tk-tip-label {
  color: var(--text-3);
}

.tk-tip-value {
  font-weight: 600;
  color: var(--text-1);
  margin-left: 4px;
}

/* --- Info Card --- */
.info-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-top: 24px;
}

.info-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--indigo-dim);
  color: var(--indigo-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.info-content h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 6px;
}

.info-content p {
  font-size: 0.84rem;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 8px;
}

.info-content p:last-child {
  margin-bottom: 0;
}

.info-content strong {
  color: var(--text-1);
}

/* --- Footer --- */
.site-footer {
  margin-top: auto;
  padding: 24px;
  border-top: 1px solid var(--border);
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-copy {
  font-size: 0.75rem;
  color: var(--text-3);
}

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

.footer-link {
  font-size: 0.75rem;
  color: var(--text-3);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-link:hover { color: var(--text-2); }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface-0);
  border: 1px solid var(--border-hover);
  border-radius: 12px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-1);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  z-index: 200;
  opacity: 0;
  transition: all 0.4s var(--ease);
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- CTA Cortex --- */
.cta-cortex {
  margin-top: 32px;
  position: relative;
}

.cta-cortex-link {
  display: block;
  text-decoration: none;
  color: inherit;
  position: relative;
  background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(6,182,212,0.04));
  border: 1px solid rgba(99,102,241,0.15);
  border-radius: 16px;
  padding: 36px 32px;
  overflow: hidden;
  transition: border-color 0.4s var(--ease), box-shadow 0.4s var(--ease);
}

.cta-cortex-link:hover {
  border-color: rgba(99,102,241,0.3);
  box-shadow: 0 0 60px -20px rgba(99,102,241,0.15);
}

.cta-cortex-glow {
  position: absolute;
  top: -40%;
  right: -10%;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(99,102,241,0.12), transparent 70%);
  border-radius: 50%;
  filter: blur(40px);
  pointer-events: none;
  transition: opacity 0.4s var(--ease);
  opacity: 0.5;
}

.cta-cortex-link:hover .cta-cortex-glow {
  opacity: 1;
}

.cta-cortex-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 28px;
}

.cta-cortex-logo {
  width: 72px;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(99,102,241,0.2));
  transition: transform 0.4s var(--ease);
}

.cta-cortex-link:hover .cta-cortex-logo {
  transform: scale(1.06);
}

.cta-cortex-text {
  flex: 1;
  min-width: 0;
}

.cta-cortex-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--indigo-light);
  margin-bottom: 8px;
}

.cta-cortex-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 6px;
  line-height: 1.3;
}

.cta-cortex-desc {
  font-size: 0.85rem;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 16px;
}

.cta-cortex-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--indigo), var(--cyan));
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(99,102,241,0.25);
  transition: all 0.3s var(--ease);
}

.cta-cortex-btn i {
  font-size: 0.7rem;
  transition: transform 0.3s var(--ease);
}

.cta-cortex-link:hover .cta-cortex-btn {
  box-shadow: 0 8px 24px rgba(99,102,241,0.35);
  filter: brightness(1.08);
}

.cta-cortex-link:hover .cta-cortex-btn i {
  transform: translateX(3px);
}

@media (max-width: 640px) {
  .cta-cortex-content {
    flex-direction: column;
    text-align: center;
    gap: 20px;
  }

  .cta-cortex-link {
    padding: 28px 24px;
  }

  .cta-cortex-logo {
    width: 60px;
  }

  .cta-cortex-title {
    font-size: 1.05rem;
  }

  .cta-cortex-desc {
    font-size: 0.82rem;
  }
}

/* --- Version --- */
.version-number {
  position: fixed;
  bottom: 10px;
  left: 10px;
  color: var(--text-3);
  font-size: 0.65rem;
  z-index: 101;
  font-family: var(--font-mono);
}

/* --- Focus --- */
.btn-sm:focus-visible,
.logo-link:focus-visible,
.header-back:focus-visible,
.footer-link:focus-visible,
.cta-cortex-link:focus-visible,
.input-textarea:focus-visible {
  outline: 2px solid var(--indigo-light);
  outline-offset: 2px;
  border-radius: 8px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 14px 12px;
    gap: 10px;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .hero {
    padding: 36px 20px 24px;
  }

  .hero h1 {
    font-size: 1.6rem;
  }

  .input-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .ctx-model {
    min-width: 70px;
    font-size: 0.7rem;
  }

  .footer-inner {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }

  .viz-container {
    font-size: 0.78rem;
    padding: 14px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .hero h1 {
    font-size: 1.4rem;
  }

  .hero p {
    font-size: 0.88rem;
  }

  .input-textarea {
    min-height: 150px;
    font-size: 0.85rem;
  }

  .btn-sm span.btn-text-mobile {
    display: none;
  }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Print --- */
@media print {
  .bg-scene, .toast, .version-number, .header { display: none; }
  body { background: white; color: black; }
  .input-section, .stat-card, .viz-container, .info-card, .ratio-section {
    border: 1px solid #ccc;
    background: white;
  }
  .stat-value, .stat-label, .ratio-title, .info-content p, .info-content h3 {
    color: black !important;
    -webkit-text-fill-color: black !important;
  }
  .tk { border: 1px solid #999; }
}
