:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e5eaf2;
  --text: #111827;
  --muted: #64748b;
  --navy: #0f172a;
  --navy-2: #1e293b;
  --green: #0a8f55;
  --green-soft: #e8f8f0;
  --red: #d93025;
  --red-soft: #fff0ee;
  --amber: #b7791f;
  --amber-soft: #fff8e8;
  --blue: #2563eb;
  --shadow: 0 5px 24px rgba(15, 23, 42, .06);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, .96);
  backdrop-filter: blur(10px);
  color: #fff;
}
.header-inner {
  max-width: 1320px;
  min-height: 66px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, #22c55e, #0f9f60);
  font-weight: 900;
}
.brand strong { display: block; font-size: 17px; letter-spacing: .02em; white-space: nowrap; }
.brand small { display: block; color: #94a3b8; font-size: 10px; letter-spacing: .14em; margin-top: 2px; }
.demo-badge {
  padding: 4px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.2);
  color: #cbd5e1;
  font-size: 9px;
  letter-spacing: .08em;
  white-space: nowrap;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.mode-switch {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.08);
}
.mode-btn {
  border: 0;
  color: #cbd5e1;
  background: transparent;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
}
.mode-btn.is-active { background: #fff; color: var(--navy); }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  background: rgba(255,255,255,.08);
  font-size: 20px;
}
.icon-btn.is-spinning { animation: spin .6s ease; }
@keyframes spin { to { transform: rotate(360deg); } }

.category-nav {
  position: sticky;
  top: 66px;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.nav-scroller {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 18px;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-scroller::-webkit-scrollbar { display: none; }
.category-link {
  position: relative;
  flex: 0 0 auto;
  padding: 13px 14px 12px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  border: 0;
  background: transparent;
}
.category-link:hover { color: var(--navy); }
.category-link.is-active { color: var(--navy); }
.category-link.is-active::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: 0;
  height: 3px;
  background: #16a34a;
  border-radius: 3px 3px 0 0;
}

main { max-width: 1320px; margin: 0 auto; padding: 24px 18px 48px; }
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 24px 26px;
  background: linear-gradient(115deg, #0f172a, #172554 68%, #164e3b);
  color: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.eyebrow, .section-kicker {
  margin: 0 0 5px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .16em;
  color: #16a34a;
}
.hero .eyebrow { color: #86efac; }
.hero h1 { margin: 0; font-size: clamp(24px, 3.2vw, 38px); letter-spacing: -.03em; }
.hero-copy { margin: 8px 0 0; color: #cbd5e1; font-size: 14px; }
.update-panel {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 3px 10px;
  min-width: 205px;
  padding: 13px 14px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 14px;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 5px rgba(34,197,94,.12); }
.update-panel small { display: block; color: #94a3b8; font-size: 10px; }
.update-panel strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.auto-refresh { grid-column: 1 / -1; margin-top: 5px; display: flex; align-items: center; gap: 7px; color: #cbd5e1; font-size: 11px; }
.auto-refresh input { accent-color: #22c55e; }
.refresh-interval, .chart-interval { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; color: #cbd5e1; font-size: 11px; }
.refresh-interval select, .chart-interval select { min-width: 78px; padding: 5px 25px 5px 8px; border: 1px solid rgba(255,255,255,.16); border-radius: 8px; background: rgba(15,23,42,.72); color: #fff; font: inherit; cursor: pointer; }
.refresh-interval select:focus, .chart-interval select:focus { outline: 2px solid rgba(134,239,172,.55); outline-offset: 1px; }

.market-sentiment, .favorite-section, .market-section { margin-top: 27px; }
.section-heading { margin-bottom: 12px; }
.inline-heading { display: flex; justify-content: space-between; align-items: end; gap: 14px; }
.section-heading h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.section-heading > p, .inline-heading > p { margin: 0; color: var(--muted); font-size: 12px; }
.text-btn { border: 0; background: transparent; color: var(--blue); font-size: 12px; font-weight: 700; }

.sentiment-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.sentiment-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.sentiment-item span:first-child { color: #334155; font-size: 12px; font-weight: 700; }
.sentiment-state { font-size: 11px; font-weight: 900; padding: 4px 7px; border-radius: 999px; white-space: nowrap; }
.sentiment-state.up { color: var(--green); background: var(--green-soft); }
.sentiment-state.down { color: var(--red); background: var(--red-soft); }
.sentiment-state.flat { color: #64748b; background: #f1f5f9; }

.market-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.market-card {
  position: relative;
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(15,23,42,.035);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.market-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #d6deea; }
.favorite-btn {
  position: absolute;
  top: 10px; right: 10px;
  width: 30px; height: 30px;
  border: 0;
  border-radius: 8px;
  color: #94a3b8;
  background: transparent;
  font-size: 19px;
  line-height: 1;
}
.favorite-btn:hover { background: #f8fafc; color: #f59e0b; }
.favorite-btn.is-active { color: #f59e0b; }
.market-card-head { display: flex; justify-content: space-between; gap: 8px; padding-right: 30px; }
.market-name-wrap { display: flex; align-items: center; gap: 9px; min-width: 0; }
.flag { font-size: 20px; line-height: 1; }
.market-name { margin: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.market-code { display: block; margin-top: 2px; color: #94a3b8; font-size: 9px; font-weight: 700; letter-spacing: .04em; }
.market-state { display: none; }
.market-value-row { display: flex; align-items: baseline; gap: 5px; margin-top: 15px; }
.market-value { font-size: clamp(22px, 2vw, 29px); line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.market-unit { color: #94a3b8; font-size: 10px; }
.market-change-row { margin-top: 7px; display: flex; gap: 9px; align-items: baseline; font-variant-numeric: tabular-nums; }
.market-change { font-size: 17px; }
.market-change-value { font-size: 11px; color: var(--muted); }
.market-card.up .market-change { color: var(--green); }
.market-card.down .market-change { color: var(--red); }
.market-card.flat .market-change { color: #64748b; }
.sparkline-wrap { height: 78px; margin: 7px -4px 0; overflow: hidden; }
.sparkline { display: block; width: 100%; height: 100%; }
.market-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  padding-top: 9px;
  border-top: 1px solid #f0f3f7;
  color: #94a3b8;
  font-size: 9px;
}

.market-section-anchor { scroll-margin-top: 128px; }
.is-hidden { display: none !important; }

.site-footer {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 26px 18px;
  text-align: center;
  color: #94a3b8;
  font-size: 10px;
}
.site-footer p { margin: 4px 0; }

@media (max-width: 1080px) {
  .market-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sentiment-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .header-inner { min-height: 62px; padding: 9px 12px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand strong { font-size: 14px; }
  .brand small, .demo-badge { display: none; }
  .mode-btn { padding: 6px 8px; font-size: 11px; }
  .icon-btn { width: 34px; height: 34px; }
  .category-nav { top: 62px; }
  .nav-scroller { padding: 0 8px; }
  .category-link { padding: 11px 10px 10px; font-size: 12px; }
  main { padding: 14px 10px 36px; }
  .hero { grid-template-columns: 1fr; padding: 19px; border-radius: 16px; gap: 16px; }
  .hero-copy { font-size: 12px; line-height: 1.6; }
  .update-panel { min-width: 0; grid-template-columns: auto 1fr auto; }
  .auto-refresh { grid-column: auto; margin-top: 0; justify-self: end; }
  .refresh-interval, .chart-interval { grid-column: 1 / -1; margin-top: 6px; }
  .market-sentiment, .favorite-section, .market-section { margin-top: 22px; }
  .section-heading h2 { font-size: 18px; }
  .inline-heading { align-items: center; }
  .inline-heading > p { display: none; }
  .sentiment-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .sentiment-item { padding: 10px; }
  .market-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .market-card { padding: 11px; border-radius: 13px; }
  .market-name { font-size: 12px; }
  .market-code { font-size: 8px; }
  .flag { font-size: 17px; }
  .market-value-row { margin-top: 13px; }
  .market-value { font-size: clamp(20px, 7vw, 27px); }
  .market-change { font-size: 15px; }
  .sparkline-wrap { height: 62px; }
  .market-meta { font-size: 8px; }
}

@media (max-width: 390px) {
  .brand strong { font-size: 13px; }
  .mode-switch { display: none; }
  .hero h1 { font-size: 24px; }
  .market-grid { grid-template-columns: 1fr 1fr; }
}

/* Ver0.4: overview drawer + chart-first layout */
.overview-toolbar { margin-bottom: 10px; }
.overview-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(15,23,42,.025);
}
.overview-toggle:hover { border-color: #d3dbe7; background: #fbfcfe; }
.overview-toggle-title { font-size: 12px; font-weight: 800; }
.overview-toggle-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.overview-toggle-meta strong { color: #334155; font-size: 11px; }
.overview-chevron { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; background: #f1f5f9; color: #475569; font-size: 16px; line-height: 1; transition: transform .18s ease; }
.overview-toggle[aria-expanded="true"] .overview-chevron { transform: rotate(180deg); }
.overview-content { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .22s ease, opacity .18s ease; opacity: 1; }
.overview-content.is-collapsed { grid-template-rows: 0fr; opacity: 0; }
.overview-content-inner { min-height: 0; overflow: hidden; }
.overview-content:not(.is-collapsed) { margin-bottom: 8px; }

/* Charts get more visual priority in standard mode */
body:not([data-mode="compact"]) .sparkline-wrap { height: 112px; margin-top: 10px; }
body:not([data-mode="compact"]) .market-card { padding-bottom: 12px; }
body:not([data-mode="compact"]) .market-section { margin-top: 20px; }
body:not([data-mode="compact"]) .favorite-section { margin-top: 20px; }

@media (max-width: 760px) {
  .overview-toolbar { margin-bottom: 8px; }
  .overview-toggle { padding: 9px 10px; border-radius: 10px; }
  .overview-toggle-title { font-size: 11px; }
  .overview-toggle-meta { font-size: 9px; }
  body:not([data-mode="compact"]) .sparkline-wrap { height: 84px; }
  body:not([data-mode="compact"]) .market-section,
  body:not([data-mode="compact"]) .favorite-section { margin-top: 16px; }
}

/* Ver4.4 free-source compact mode */
#compactSection .quote-card.is-unavailable{background:#fff!important;border-color:#e5e7eb!important}
#compactSection .quote-unavailable{font-size:11px;font-weight:700;color:#94a3b8}
#compactSection .quote-status{margin-top:2px;font-size:8px;color:#94a3b8}
#compactSection .compact-source{margin-top:4px;font-size:9px;color:#94a3b8}
#compactSection .compact-source a{color:#64748b;text-decoration:underline}
