:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --pass: #22c55e;
  --fail: #ef4444;
  --warn: #f59e0b;
  --accent: #38bdf8;
  --border: #334155;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.app-header {
  padding: 24px 16px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.home-logo {
  position: absolute;
  top: 12px;
  left: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
}

.home-logo img {
  width: 32px;
  height: 32px;
  display: block;
  opacity: 0.9;
  transition: opacity 0.15s;
}

.home-logo:hover img { opacity: 1; }

.home-logo-label {
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--muted);
  transition: color 0.15s;
  white-space: nowrap;
}

.home-logo:hover .home-logo-label { color: var(--accent); }

.app-header h1 { margin: 0; font-size: 1.5rem; padding: 0 52px; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.notice {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--text);
}
.notice strong { color: var(--accent); }

.limitations {
  margin-top: 20px;
}
.limitations details {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.limitations summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  color: var(--warn);
}
.limitations p { color: var(--muted); font-size: 0.88rem; }
.limitations ul { padding-left: 20px; margin: 8px 0; }
.limitations li { color: var(--muted); font-size: 0.88rem; margin: 6px 0; }
.limitations li strong { color: var(--text); }
.limitations-footer { margin-top: 10px; font-style: italic; }

.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--card);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.search-bar input[type="text"],
.search-bar input[type="password"] {
  flex: 1 1 180px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
}
.hint { color: var(--muted); font-size: 0.8rem; margin: 8px 4px 0; }
.hint a { color: var(--accent); }

.market-hint {
  margin: 6px 4px 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.market-hint summary {
  cursor: pointer;
  color: var(--accent);
  list-style: none;
  display: inline-block;
  padding: 2px 0;
}
.market-hint summary::-webkit-details-marker { display: none; }
.market-hint summary::before { content: "▸ "; font-size: 0.7rem; }
.market-hint[open] summary::before { content: "▾ "; }
.market-hint ul { margin: 6px 0 0; padding-left: 18px; }
.market-hint li { margin: 4px 0; }
.market-hint code {
  background: var(--card-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
  color: var(--text);
}
.market-hint strong { color: var(--text); }
.asx-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  user-select: none;
}
.asx-toggle[hidden] { display: none; }
.search-bar button {
  padding: 10px 20px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.search-bar button:hover { filter: brightness(1.1); }
.search-bar button:disabled { opacity: 0.6; cursor: not-allowed; }
.search-row { display: contents; }
.go-btn { display: none; }

.status {
  margin-top: 16px;
  padding: 12px;
  background: var(--card);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
}
.status.error { color: var(--fail); border: 1px solid var(--fail); }

.recent {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.recent .recent-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip-green { border-color: var(--pass); color: var(--pass); }
.chip-amber { border-color: #f59e0b; color: #f59e0b; }
.chip-red   { border-color: var(--fail); color: var(--fail); }
.chip .x {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 2px;
}
.chip .x:hover { color: var(--fail); }

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--card-2) 0%, #334155 50%, var(--card-2) 100%);
  background-size: 400px 100%;
  animation: shimmer 1.2s infinite linear;
  border-radius: 6px;
  color: transparent;
}
.summary .stat.skeleton .stat-label,
.summary .stat.skeleton .stat-value { visibility: hidden; }
.card.skeleton { min-height: 140px; }

.summary {
  margin-top: 16px;
  padding: 16px;
  background: var(--card);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.summary h2 { margin: 0 0 4px; font-size: 1.2rem; }
.summary .symbol { color: var(--muted); font-size: 0.9rem; }
.summary .sector { color: var(--muted); font-size: 0.85rem; margin-bottom: 4px; }
.summary .stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.summary .stat { background: var(--card-2); padding: 10px; border-radius: 6px; }
.summary .stat-label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.summary .stat-value { font-size: 1.05rem; margin-top: 2px; font-weight: 600; }
.summary .stat-note { font-size: 0.72rem; color: var(--muted); margin-top: 3px; }
.stat-up { color: var(--pass); }
.stat-down { color: var(--fail); }

/* ── Combined Score Gauge ── */
.gauge-section { padding: 4px 0; }
.gauge-wrap { max-width: 520px; margin: 0 auto; padding: 0 20px; }
.gauge-bar-area {
  position: relative;
  padding-top: 44px;
}
.gauge-zones {
  display: flex;
  height: 12px;
  gap: 3px;
}
.gauge-z { height: 100%; border-radius: 3px; }
.gauge-z.bad  { flex: 40; background: rgba(239,68,68,0.55); }
.gauge-z.ok   { flex: 25; background: rgba(245,158,11,0.55); }
.gauge-z.good { flex: 35; background: rgba(34,197,94,0.55); }
.gauge-marker-area {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
  pointer-events: none;
}
.gauge-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
  margin-bottom: 6px;
}
.gauge-marker-area.good .gauge-pill { background: rgba(34,197,94,0.22); color: var(--pass); border: 1px solid rgba(34,197,94,0.55); }
.gauge-marker-area.ok   .gauge-pill { background: rgba(245,158,11,0.22); color: var(--warn); border: 1px solid rgba(245,158,11,0.55); }
.gauge-marker-area.bad  .gauge-pill { background: rgba(239,68,68,0.22);  color: var(--fail); border: 1px solid rgba(239,68,68,0.55); }
.gauge-stem {
  width: 2px;
  flex: 1;
  min-height: 14px;
  border-radius: 1px;
}
.gauge-marker-area.good .gauge-stem { background: var(--pass); }
.gauge-marker-area.ok   .gauge-stem { background: var(--warn); }
.gauge-marker-area.bad  .gauge-stem { background: var(--fail); }
.gauge-sub {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 10px;
}

.cards {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.card h3 { margin: 0; font-size: 1rem; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.card .score {
  font-size: 2.4rem;
  font-weight: 700;
  margin: 8px 0 4px;
}
.card .verdict {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.card.good .score { color: var(--pass); }
.card.good .verdict { background: rgba(34,197,94,0.15); color: var(--pass); }
.card.ok .score { color: var(--warn); }
.card.ok .verdict { background: rgba(245,158,11,0.15); color: var(--warn); }
.card.bad .score { color: var(--fail); }
.card.bad .verdict { background: rgba(239,68,68,0.15); color: var(--fail); }

.breakdown {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 860px) {
  .breakdown { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  /* Prevent iOS Safari auto-zoom on input focus (requires font-size >= 16px) */
  input, select, textarea { font-size: 16px; }
  /* Header: proper 3-column flex layout — logo | center | toggle, no overlap */
  .app-header { display: flex; align-items: flex-start; gap: 8px; padding: 12px 16px 8px; }
  .home-logo { position: static; flex: 0 0 auto; order: 1; padding-top: 6px; }
  .app-header-center { flex: 1; min-width: 0; order: 2; text-align: center; }
  .theme-toggle { position: static; flex: 0 0 auto; order: 3; width: 44px; height: 44px; }
  .app-header h1 { font-size: 1.1rem; padding: 0; }
  /* Larger touch targets */
  .search-bar button { min-height: 44px; }
  .chip { min-height: 36px; padding: 6px 10px; }
  /* Go button: inline with the input on mobile; Analyse button hidden */
  #analyse-btn { display: none; }
  .search-row {
    display: flex; flex: 0 0 100%; gap: 8px; align-items: center;
  }
  .search-row .ac-wrapper { flex: 1; }
  .go-btn {
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    padding: 0 16px; height: 44px;
    background: var(--accent); color: var(--bg);
    border: none; border-radius: 6px; font-size: 1rem; font-weight: 600;
    cursor: pointer; white-space: nowrap;
  }
  .go-btn:disabled { opacity: 0.6; cursor: not-allowed; }
}

.breakdown details {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.breakdown summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 1.05rem;
}
.criterion {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.criterion:first-of-type { border-top: none; margin-top: 8px; }
.criterion .icon { flex-shrink: 0; display: flex; align-items: center; }
.criterion .name { font-weight: 500; }
.criterion .note { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.criterion .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.criterion.pass .value { color: var(--pass); }
.criterion.fail .value { color: var(--fail); }
.criterion.skipped { opacity: 0.65; }
.criterion.skipped .value { color: var(--muted); }

footer {
  text-align: center;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ── Theme toggle button ── */
.theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  background: var(--card-2);
  border-color: var(--accent);
  color: var(--text);
}

/* ── Light mode overrides ── */
html:not(.dark) {
  --bg:     #edf2f7;
  --card:   #d4dce8;
  --card-2: #c5cfe0;
  --text:   #0f172a;
  --muted:  #475569;
  --border: #e2e8f0;
}

/* ── Tool info & FAQ ── */
.tool-info {
  max-width: 900px;
  margin: 48px auto 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
@media (max-width: 680px) { .tool-info { grid-template-columns: 1fr; } }
.tool-info h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.tool-about p { font-size: 0.9rem; color: var(--muted); line-height: 1.6; margin-bottom: 8px; }
.faq-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.faq-item summary {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  padding-right: 20px;
  position: relative;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; position: absolute; right: 0; color: var(--muted); }
.faq-item[open] summary::after { content: '−'; }
.faq-item p { font-size: 0.85rem; color: var(--muted); line-height: 1.6; margin-top: 8px; }

/* ── Android promo banner ── */
#kv-promo-banner {
  background: var(--accent);
  text-align: center;
  padding: 9px 16px;
}
#kv-promo-banner a {
  color: #0f172a;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
}
#kv-promo-banner strong { font-weight: 700; }

/* ── Play Store badge (web only) ── */
#kv-play-badge {
  text-align: center;
  padding: 12px 16px 4px;
}
#kv-play-badge img { display: inline-block; }

/* ── Autocomplete dropdown ── */
.ac-wrapper {
  position: relative;
  flex: 1 1 280px;
  min-width: 0;
}
#autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.ac-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  gap: 8px;
}
.ac-item:hover,
.ac-item:focus { background: var(--bg); outline: none; }
.ac-name {
  font-size: 0.9rem;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ac-meta {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Tool navigation bar ── */
.kv-tool-nav{display:flex;justify-content:center;overflow-x:auto;border-bottom:1px solid var(--border);background:var(--bg);padding:0 16px;scrollbar-width:none;}
.kv-tool-nav::-webkit-scrollbar{display:none;}
.kv-tool-nav a{flex-shrink:0;padding:10px 14px;font-size:0.82rem;font-weight:500;color:var(--muted);text-decoration:none;border-bottom:2px solid transparent;white-space:nowrap;transition:color 0.15s;}
.kv-tool-nav a:hover{color:var(--text);}
.kv-tool-nav a.kv-nav-active{color:var(--accent);border-bottom-color:var(--accent);}
html:not(.dark) .kv-tool-nav{background:#edf2f7;border-color:#e2e8f0;}
html:not(.dark) .kv-tool-nav a{color:#475569;}
html:not(.dark) .kv-tool-nav a:hover{color:#0f172a;}
html:not(.dark) .kv-tool-nav a.kv-nav-active{color:#0ea5e9;border-bottom-color:#0ea5e9;}
@media(max-width:800px){.kv-tool-nav{justify-content:flex-start;}}
