:root {
  color-scheme: light dark;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.08);
  --accent: #0f9d58;
  --danger: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --controls-bg-end: rgba(248, 250, 252, 0.9);
  --color-up: #10b981;
  --color-down: #ef4444;
  --color-neutral: #6b7280;
}



* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Safe-area spacer for pages that sit close to mobile status bars */
.safe-top-spacer {
  height: calc(env(safe-area-inset-top, 0px) + 12px);
}

.hero {
  padding: 2.5rem 1.5rem 1.5rem;
  background: radial-gradient(circle at top, #e0f2fe, #eff6ff 50%, #f8fafc);
}

.hero--sub {
  padding-bottom: 2.5rem;
}

.hero--compact {
  padding-bottom: 2.5rem;
}

.hero__actions {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.btn--solid {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
}

.hero__content {
  max-width: 720px;
  margin: 0 auto;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0 0 1rem;
}

.lead {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}

.app {
  margin: -1rem auto 0;
  padding: 0 1.5rem 3rem;
  max-width: 960px;
}

.analyzer-page main {
  margin: -1rem auto 0;
  padding: 0 0.5rem 3rem;
  max-width: 960px;
}

.controls {
  position: sticky;
  top: 0;
  padding: 0.5rem 0 1.5rem;
  background: linear-gradient(var(--bg), var(--controls-bg-end));
  backdrop-filter: blur(10px);
  z-index: 2;
}

input[type='search'] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 1.15rem;
  font-size: 1rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background: var(--card);
  color: var(--text);
}

input[type='search']:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 157, 88, 0.15);
}

#stats {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.terms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.chart-link {
  margin-top: auto;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.chart-link:hover {
  text-decoration: underline;
}

.term-card {
  background: var(--card);
  padding: 1.25rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.term-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.term-card .label {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 0.25rem;
  font-weight: 600;
}

.term-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.term-card .short {
  font-weight: 600;
  color: var(--accent);
}

.term-card .category {
  font-weight: 500;
}

.term-card .description {
  margin: 0;
  line-height: 1.5;
  color: var(--text);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.badge {
  background: rgba(15, 157, 88, 0.12);
  color: var(--accent);
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.badge--caution {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.empty {
  text-align: center;
  color: var(--muted);
  grid-column: 1 / -1;
}

.footer {
  margin-top: 4rem;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg) 0%, rgba(15, 157, 88, 0.03) 100%);
}

.footer__wave {
  height: 40px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 100'%3E%3Cpath fill='%230f9d58' fill-opacity='0.07' d='M0,64L48,58.7C96,53,192,43,288,48C384,53,480,75,576,74.7C672,75,768,53,864,48C960,43,1056,53,1152,58.7C1248,64,1344,64,1392,64L1440,64L1440,100L1392,100C1344,100,1248,100,1152,100C1056,100,960,100,864,100C768,100,672,100,576,100C480,100,384,100,288,100C192,100,96,100,48,100L0,100Z'%3E%3C/path%3E%3C/svg%3E") repeat-x bottom;
  background-size: 1440px 100px;
}

.footer__content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
  text-align: left;
}

.footer__section h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.footer__section p {
  margin: 0 0 0.5rem;
  line-height: 1.6;
}

.footer__section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer__section li {
  margin-bottom: 0.5rem;
}

.footer__section a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

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

.footer__section a svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.footer__bottom {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1.5rem 2rem;
  text-align: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 1.5rem;
}

.footer__bottom p {
  margin: 0;
}

.footer__heart {
  color: #ef4444;
  animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.footer__badges {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.footer__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.7rem;
  color: var(--muted);
  transition: all 0.2s;
}

.footer__badge:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.footer__badge svg {
  width: 12px;
  height: 12px;
}

.chart-cta,
.analyzer,
.guide__intro,
.guide__note {
  margin-top: 2rem;
  background: var(--card);
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.chart-cta h2,
.analyzer h2 {
  margin-top: 0;
}

.analyzer {
  padding: clamp(1.5rem, 3vw, 2.25rem);
}

.analyzer-form {
  margin-top: 1.25rem;
  /* border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 18px;
  padding: clamp(1rem, 2vw, 1.5rem);
  background: rgba(248, 250, 252, 0.6); */
}

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

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.form-field span {
  font-weight: 600;
  color: var(--muted);
}

.form-hint {
  margin: -0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.form-hint a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.form-hint a:hover {
  text-decoration: underline;
}

.form-field input,
.form-field select {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  background: var(--card);
  color: var(--text);
}

.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 157, 88, 0.12);
}

.form-field input::placeholder {
  color: var(--muted);
}

.analyzer-form .btn {
  width: 100%;
  margin-top: 0.75rem;
}

.analysis-output {
  margin-top: 1.5rem;
}

.analysis-summary {
  background: rgba(15, 157, 88, 0.08);
  border-radius: 14px;
  padding: 1rem;
  border: 1px solid rgba(15, 157, 88, 0.2);
  margin-bottom: 1rem;
}

.muted {
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.analysis-card {
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.analysis-card h4 {
  margin: 0 0 0.35rem 0;
}

.analysis-card ul {
  padding-left: 1.25rem;
  margin: 0 0 0.5rem 0;
  color: var(--muted);
}

.analysis-card .label {
  margin-top: 0.5rem;
}

.guide {
  margin: -1rem auto 0;
  padding: 0 1.5rem 3rem;
  max-width: 960px;
}

.guide-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.guide-card {
  background: var(--card);
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.guide-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.guide-tag {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.screenshot-note {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

mark.hl {
  background: rgba(255, 243, 199, 0.95);
  color: inherit;
  padding: 0 0.15rem;
  border-radius: 3px;
}

@media (min-width: 768px) {
  .controls {
    top: 1rem;
  }
}

/* --- Stock Detail Page Styles --- */
.detail-header {
  background: var(--card);
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
}

.metric-card {
  background: var(--card);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.metric-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.metric-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.back-nav {
  padding: 1rem 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.back-nav a {
  text-decoration: none;
  color: var(--accent);
  font-weight: 500;
}

/* Modal styles */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--card);
  width: 100%;
  max-width: 100%;
  height: 100%;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  padding-top: 3rem;
  position: relative;
  color: var(--text);
}

/* AI Modal fullscreen override */
#ai-modal .modal-content {
  width: 100%;
  max-width: 100%;
  height: 100%;
  border-radius: 0;
  padding: .5rem;
  padding-top: 1rem;
}

.close-modal {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1.2rem;
}

.close-modal:hover {
  background: var(--border);
}

#ai-chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Chat message styles */
.chat-msg {
  padding: 1rem;
  border-radius: 8px;
  max-width: 90%;
  line-height: 1.5;
  font-size: 0.9rem;
}

.chat-msg--user {
  background: #e0f2fe;
  align-self: flex-end;
  color: #0c4a6e;
}

.chat-msg--ai {
  background: var(--card);
  align-self: flex-start;
  border: 1px solid var(--border);
  color: var(--text);
}

.chat-msg--system {
  background: transparent;
  color: var(--muted);
  text-align: center;
  align-self: center;
  font-style: italic;
}

.chat-msg--error {
  background: #fee2e2;
  color: #991b1b;
}

.chat-msg--thinking {
  background: transparent;
  color: var(--muted);
  text-align: center;
  align-self: center;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-msg--thinking::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* AI Markdown output styling */
.chat-msg--ai h1,
.chat-msg--ai h2,
.chat-msg--ai h3 {
  margin: 0.75rem 0 0.5rem;
  font-weight: 600;
}

.chat-msg--ai h1 { font-size: 1.25rem; }
.chat-msg--ai h2 { font-size: 1.1rem; }
.chat-msg--ai h3 { font-size: 1rem; }

.chat-msg--ai p {
  margin: 0.5rem 0;
}

.chat-msg--ai ul,
.chat-msg--ai ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.chat-msg--ai li {
  margin: 0.25rem 0;
}

.chat-msg--ai code {
  background: var(--bg);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85em;
}

.chat-msg--ai pre {
  background: var(--bg);
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.chat-msg--ai pre code {
  background: none;
  padding: 0;
}

.chat-msg--ai blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.5rem 0;
  padding-left: 1rem;
  color: var(--muted);
}

.chat-msg--ai table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.chat-msg--ai th,
.chat-msg--ai td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}

.chat-msg--ai th {
  background: var(--bg);
  font-weight: 600;
}

.chat-msg--ai hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

#ai-input {
  flex: 1;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}

#ai-send-btn {
  width: auto;
  margin: 0;
  padding: 0 1.5rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-ai {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  padding: 0.875rem 1.5rem;
  font-size: 1rem;
  width: 100%;
  text-align: center;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-ai:hover {
  background: #0a7f47;
}

.btn-ai:active {
  transform: scale(0.98);
}

#stock-sector {
  display: inline-block;
  background: var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  margin-top: 0.5rem;
  color: var(--muted);
}

#chart-container {
  height: 200px;
  background: var(--bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 1rem;
  box-sizing: border-box;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    --controls-bg-end: rgba(15, 23, 42, 0.9);
  }

  .hero {
    background: radial-gradient(circle at top, #1e293b, #0f172a 80%);
  }

  .hero h1 {
    color: #f1f5f9;
  }

  .hero .eyebrow,
  .hero .lead {
    color: #cbd5e1;
  }
  
  .btn {
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  mark.hl {
    background: rgba(253, 224, 71, 0.3);
    color: #fff;
  }

  /* Dark mode modal fixes */
  .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
  }

  .modal-content {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
  }

  #ai-chat-container {
    background: var(--bg);
  }

  /* Dark mode chat messages */
  .chat-msg--user {
    background: rgba(15, 157, 88, 0.2);
    color: var(--text);
  }

  .chat-msg--ai {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
  }

  .chat-msg--error {
    background: rgba(220, 38, 38, 0.2);
    color: #fca5a5;
  }
}
