/* ==================================================
   EMOTIQ AI — DESIGN SYSTEM
   ================================================== */

:root {
  /* Surfaces */
  --bg: #0a0d13;
  --bg-elevated: #10141c;
  --surface: #12161f;
  --surface-2: #171c27;
  --surface-3: #1d2330;
  --border: #232a38;
  --border-soft: #1a202c;

  /* Text */
  --text-primary: #edeff4;
  --text-secondary: #9199ad;
  --text-tertiary: #5d6478;

  /* Accent */
  --accent: #6c8cff;
  --accent-soft: rgba(108, 140, 255, 0.14);
  --accent-line: rgba(108, 140, 255, 0.35);
  --online: #3ddc97;

  /* Emotion palette — desaturated, editorial, not rainbow-bright */
  --e-sadness: #6c8cff;
  --e-anger: #e2604c;
  --e-love: #e8779a;
  --e-surprise: #45c2d6;
  --e-fear: #9d7ee8;
  --e-joy: #e0ac48;

  /* Type */
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  /* Scale */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 20px 50px -25px rgba(0,0,0,0.6);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(108,140,255,0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(224,172,72,0.06), transparent 55%),
    var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Focus visibility */
a:focus-visible,
button:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ==================================================
   AMBIENT SIGNAL FIELD (background texture)
   ================================================== */

.signal-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(circle at 50% 0%, black 0%, transparent 65%);
}

/* ==================================================
   HEADER
   ================================================== */

.site-header {
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(10, 13, 19, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

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

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

.brand-mark {
  display: flex;
  color: var(--accent);
  opacity: 0.9;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-name-accent { color: var(--accent); font-style: italic; }

.brand-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 10px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(61,220,151,0.15);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(61,220,151,0.15); }
  50% { box-shadow: 0 0 0 6px rgba(61,220,151,0.08); }
}

/* ==================================================
   HERO
   ================================================== */

main { position: relative; z-index: 1; }

.hero {
  padding: 84px 32px 56px;
  border-bottom: 1px solid var(--border-soft);
}

.hero-inner {
  max-width: 780px;
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  padding: 5px 12px;
  border-radius: 100px;
  margin-bottom: 22px;
}

.hero-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(32px, 5vw, 50px);
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 18px;
  color: var(--text-primary);
}

.hero-sub {
  font-size: 16.5px;
  color: var(--text-secondary);
  max-width: 540px;
  margin: 0 auto 40px;
  line-height: 1.65;
}

/* Signature element: the emotion spectrum signal bar */
.spectrum-bar {
  display: flex;
  gap: 3px;
  height: 5px;
  max-width: 460px;
  margin: 0 auto 10px;
  border-radius: 4px;
  overflow: hidden;
}

.spectrum-seg {
  flex: 1;
  border-radius: 3px;
  animation: signal-breathe 4.5s ease-in-out infinite;
}

.spectrum-seg[data-emotion="sadness"] { background: var(--e-sadness); animation-delay: 0s; }
.spectrum-seg[data-emotion="anger"] { background: var(--e-anger); animation-delay: 0.3s; }
.spectrum-seg[data-emotion="love"] { background: var(--e-love); animation-delay: 0.6s; }
.spectrum-seg[data-emotion="surprise"] { background: var(--e-surprise); animation-delay: 0.9s; }
.spectrum-seg[data-emotion="fear"] { background: var(--e-fear); animation-delay: 1.2s; }
.spectrum-seg[data-emotion="joy"] { background: var(--e-joy); animation-delay: 1.5s; }

@keyframes signal-breathe {
  0%, 100% { opacity: 0.55; transform: scaleY(1); }
  50% { opacity: 1; transform: scaleY(1.6); }
}

.spectrum-legend {
  display: flex;
  justify-content: space-between;
  max-width: 460px;
  margin: 0 auto;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--text-tertiary);
}

/* ==================================================
   WORKSPACE
   ================================================== */

.workspace { padding: 56px 32px 40px; }

.workspace-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: stretch;
}

.panel {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px;
  display: flex;
  flex-direction: column;
}

.panel-head h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.panel-head p {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 26px;
  line-height: 1.55;
}

/* ---- Input form ---- */

#analyzeForm { display: flex; flex-direction: column; flex: 1; }

.field { margin-bottom: 22px; }

textarea {
  width: 100%;
  resize: vertical;
  min-height: 150px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  padding: 16px 18px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

textarea::placeholder { color: var(--text-tertiary); }

textarea:hover { border-color: #2b3345; }

textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

textarea[aria-invalid="true"] {
  border-color: var(--e-anger);
  box-shadow: 0 0 0 4px rgba(226, 96, 76, 0.12);
}

.field-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  min-height: 18px;
}

.char-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
  margin-left: auto;
}

.input-error {
  font-size: 12.5px;
  color: var(--e-anger);
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

.input-error.visible { opacity: 1; transform: translateY(0); }

/* ---- Examples ---- */

.examples { margin-bottom: 26px; }

.examples-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease), background 0.18s var(--ease), transform 0.15s var(--ease);
}

.chip:hover {
  border-color: var(--accent-line);
  color: var(--text-primary);
  background: var(--accent-soft);
}

.chip:active { transform: scale(0.97); }

/* ---- Primary button ---- */

.btn-primary {
  margin-top: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #0a0d13;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  padding: 15px 20px;
  cursor: pointer;
  transition: filter 0.18s var(--ease), transform 0.15s var(--ease), box-shadow 0.18s var(--ease);
  box-shadow: 0 8px 24px -10px rgba(108, 140, 255, 0.55);
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }

.btn-primary:disabled {
  cursor: progress;
  filter: grayscale(0.15) brightness(0.85);
}

.btn-spinner {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(10,13,19,0.25);
  border-top-color: #0a0d13;
  display: none;
}

.btn-primary.is-loading .btn-spinner { display: inline-block; animation: spin 0.7s linear infinite; }
.btn-primary.is-loading .btn-label { opacity: 0.75; }

@keyframes spin { to { transform: rotate(360deg); } }

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 20px;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease);
}

.btn-secondary:hover { border-color: var(--accent-line); background: var(--accent-soft); }

/* ==================================================
   RESULT PANEL / STATES
   ================================================== */

.result-panel { position: relative; min-height: 420px; }

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: auto;
  animation: state-in 0.35s var(--ease);
}

/* Fix: .state{display:flex} was a class selector, which beats the
   browser's default [hidden]{display:none} rule on specificity.
   This makes [hidden] always win, regardless of any other rule. */
.state[hidden] {
  display: none !important;
}

@keyframes state-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Idle */
.state-idle { justify-content: center; flex: 1; color: var(--text-secondary); }
.idle-glyph { color: var(--text-tertiary); margin-bottom: 18px; opacity: 0.8; }
.state-idle h3 { font-family: var(--font-display); font-weight: 500; font-size: 19px; color: var(--text-primary); margin: 0 0 8px; }
.state-idle p { font-size: 13.5px; margin: 0; max-width: 240px; }

/* Loading */
.state-loading { justify-content: center; flex: 1; color: var(--text-secondary); }

.loading-rings { position: relative; width: 46px; height: 46px; margin-bottom: 20px; }
.loading-rings span {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  animation: ring-spin 1.1s linear infinite;
}
.loading-rings span:nth-child(2) { inset: 7px; border-top-color: var(--e-surprise); animation-duration: 1.5s; animation-direction: reverse; opacity: 0.7; }
.loading-rings span:nth-child(3) { inset: 14px; border-top-color: var(--e-joy); animation-duration: 0.9s; opacity: 0.5; }

@keyframes ring-spin { to { transform: rotate(360deg); } }

.state-loading h3 { font-family: var(--font-display); font-weight: 500; font-size: 19px; color: var(--text-primary); margin: 0 0 8px; }
.state-loading p { font-size: 13.5px; margin: 0; }

/* Error */
.state-error { justify-content: center; flex: 1; color: var(--text-secondary); }
.error-glyph { color: var(--e-anger); margin-bottom: 16px; }
.state-error h3 { font-family: var(--font-display); font-weight: 500; font-size: 19px; color: var(--text-primary); margin: 0 0 8px; }
.state-error p { font-size: 13.5px; margin: 0 0 22px; max-width: 300px; }

/* Success */
.state-success { align-items: stretch; text-align: left; width: 100%; }

.result-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 20px;
}

.result-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.result-emotion { display: flex; align-items: center; gap: 12px; }

.emotion-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--current-emotion-color, var(--accent));
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--current-emotion-color, var(--accent)) 18%, transparent);
  flex-shrink: 0;
}

.emotion-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 34px;
  letter-spacing: -0.01em;
  color: var(--current-emotion-color, var(--text-primary));
  text-transform: uppercase;
}

.confidence-block { margin-bottom: 24px; }

.confidence-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 9px;
}

.confidence-value {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text-primary);
  font-weight: 500;
}

.confidence-track {
  height: 8px;
  border-radius: 100px;
  background: var(--surface-3);
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  width: 0%;
  border-radius: 100px;
  background: var(--current-emotion-color, var(--accent));
  transition: width 0.9s var(--ease);
}

.distribution-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 14px;
}

.distribution-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.distribution-item {
  display: grid;
  grid-template-columns: 76px 1fr 44px;
  align-items: center;
  gap: 12px;
}

.distribution-name {
  font-size: 12.5px;
  color: var(--text-secondary);
  text-transform: capitalize;
}

.distribution-track {
  height: 6px;
  border-radius: 100px;
  background: var(--surface-3);
  overflow: hidden;
}

.distribution-fill {
  height: 100%;
  width: 0%;
  border-radius: 100px;
  transition: width 0.9s var(--ease), opacity 0.9s var(--ease);
}

.distribution-pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
}

.distribution-item.is-top .distribution-name,
.distribution-item.is-top .distribution-pct {
  color: var(--text-primary);
  font-weight: 500;
}

.analyzed-text {
  font-size: 13px;
  color: var(--text-tertiary);
  font-style: italic;
  border-top: 1px solid var(--border-soft);
  padding-top: 16px;
  margin: auto 0 0;
  line-height: 1.6;
}

/* ==================================================
   FOOTER
   ================================================== */

.site-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 32px 60px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-soft);
}

/* ==================================================
   RESPONSIVE
   ================================================== */

@media (max-width: 980px) {
  .workspace-inner { grid-template-columns: 1fr; }
  .result-panel { min-height: 340px; }
}

@media (max-width: 640px) {
  .header-inner { padding: 14px 20px; }
  .hero { padding: 56px 20px 40px; }
  .hero-title { font-size: 28px; }
  .workspace { padding: 8px 20px 20px; }
  .panel { padding: 24px 20px; }
  .site-footer { flex-direction: column; gap: 6px; padding: 24px 20px 48px; }
  .distribution-item { grid-template-columns: 62px 1fr 38px; gap: 8px; }
  .brand-badge { display: none; }
}

@media (max-width: 380px) {
  .chip { font-size: 12px; padding: 7px 12px; }
  .emotion-name { font-size: 28px; }
}

/* ==================================================
   REDUCED MOTION
   ================================================== */

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