/* ========== CSS Variables (Themes) ========== */
:root {
  /* Default theme: Normal (Dark) */
  --color-text: #e5e7eb;
  --color-text-muted: #94a3b8;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
  --color-bg-page: linear-gradient(180deg, #0b1220 0%, #0f1629 100%);
  --color-bg-page-solid: #0b1220;
  --color-bg-card: #0f172a;
  --color-bg-card-hover: #0d1526;
  --color-bg-badge: #0b1220;
  --color-bg-tag: #0b1220;
  --color-bg-button: transparent;
  --color-bg-button-hover: #0f172a;
  --color-border-card: #1f2937;
  --color-border-card-hover: #313948;
  --color-border-badge: #1f2937;
  --color-border-tag: #1f2937;
  --color-border-button: #334155;
  --color-arrow: #7c8796;
  --color-arrow-hover: #7c8796;
  --color-section-divider-start: #243041;
  --color-shadow-card: rgba(0, 0, 0, 0.25);
  --color-shadow-card-hover: rgba(0, 0, 0, 0.35);
  --color-focus-ring: #60a5fa;

}

/* ========== DARK THEMES ========== */

/* Theme: Normal (Dark - Default) */
[data-theme="normal"] {
  --color-text: #e5e7eb;
  --color-text-muted: #94a3b8;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
  --color-bg-page: linear-gradient(180deg, #0b1220 0%, #0f1629 100%);
  --color-bg-page-solid: #0b1220;
  --color-bg-card: #0f172a;
  --color-bg-card-hover: #0d1526;
  --color-bg-badge: #0b1220;
  --color-bg-tag: #0b1220;
  --color-bg-button: transparent;
  --color-bg-button-hover: #0f172a;
  --color-border-card: #1f2937;
  --color-border-card-hover: #313948;
  --color-border-badge: #1f2937;
  --color-border-tag: #1f2937;
  --color-border-button: #334155;
  --color-arrow: #7c8796;
  --color-arrow-hover: #7c8796;
  --color-section-divider-start: #243041;
  --color-shadow-card: rgba(0, 0, 0, 0.25);
  --color-shadow-card-hover: rgba(0, 0, 0, 0.35);
  --color-focus-ring: #60a5fa;
}

/* Theme: Midnight (Dark - Deep blue/purple) */
[data-theme="midnight"] {
  --color-text: #e0e7ff;
  --color-text-muted: #a5b4fc;
  --color-text-secondary: #818cf8;
  --color-text-tertiary: #6366f1;
  --color-bg-page: linear-gradient(180deg, #0f0a1e 0%, #1a0f2e 100%);
  --color-bg-page-solid: #0f0a1e;
  --color-bg-card: #1e1b3c;
  --color-bg-card-hover: #252142;
  --color-bg-badge: #1a1732;
  --color-bg-tag: #1a1732;
  --color-bg-button: transparent;
  --color-bg-button-hover: #1e1b3c;
  --color-border-card: #312e54;
  --color-border-card-hover: #3f3c68;
  --color-border-badge: #312e54;
  --color-border-tag: #312e54;
  --color-border-button: #4338ca;
  --color-arrow: #818cf8;
  --color-arrow-hover: #a5b4fc;
  --color-section-divider-start: #4338ca;
  --color-shadow-card: rgba(0, 0, 0, 0.4);
  --color-shadow-card-hover: rgba(0, 0, 0, 0.5);
  --color-focus-ring: #6366f1;
}

/* Theme: Cyber (Dark - Neon cyan/magenta cyberpunk) */
[data-theme="cyber"] {
  --color-text: #00f5ff;
  --color-text-muted: #00d9ff;
  --color-text-secondary: #ff00ff;
  --color-text-tertiary: #b300ff;
  --color-bg-page: linear-gradient(180deg, #0a0015 0%, #150a1f 100%);
  --color-bg-page-solid: #0a0015;
  --color-bg-card: #1a0f2e;
  --color-bg-card-hover: #251a3f;
  --color-bg-badge: #2d1b4e;
  --color-bg-tag: #1f0a33;
  --color-bg-button: transparent;
  --color-bg-button-hover: #1a0f2e;
  --color-border-card: #7c00ff;
  --color-border-card-hover: #b300ff;
  --color-border-badge: #00d9ff;
  --color-border-tag: #ff00ff;
  --color-border-button: #00f5ff;
  --color-arrow: #ff00ff;
  --color-arrow-hover: #00f5ff;
  --color-section-divider-start: #7c00ff;
  --color-shadow-card: rgba(124, 0, 255, 0.3);
  --color-shadow-card-hover: rgba(0, 245, 255, 0.4);
  --color-focus-ring: #00f5ff;
}

/* Theme: Matrix (Dark - Green code + electric blue + neon accent) */
[data-theme="matrix"] {
  --color-text: #00ff41;
  --color-text-muted: #00cc33;
  --color-text-secondary: #0099ff;
  --color-text-tertiary: #ff00aa;
  --color-bg-page: linear-gradient(180deg, #000000 0%, #0a0a15 100%);
  --color-bg-page-solid: #000000;
  --color-bg-card: #0d0d1a;
  --color-bg-card-hover: #15152a;
  --color-bg-badge: #1a2d1a;
  --color-bg-tag: #1a1a3d;
  --color-bg-button: transparent;
  --color-bg-button-hover: #0d0d1a;
  --color-border-card: #00ff41;
  --color-border-card-hover: #33ff66;
  --color-border-badge: #0099ff;
  --color-border-tag: #6600ff;
  --color-border-button: #00ccff;
  --color-arrow: #ff00aa;
  --color-arrow-hover: #00ff41;
  --color-section-divider-start: #0099ff;
  --color-shadow-card: rgba(0, 255, 65, 0.15);
  --color-shadow-card-hover: rgba(0, 153, 255, 0.25);
  --color-focus-ring: #00ff41;
}

/* ========== LIGHT THEMES ========== */

/* Theme: Pearl (Light - Soft gray/white) */
[data-theme="pearl"] {
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-text-secondary: #64748b;
  --color-text-tertiary: #94a3b8;
  --color-bg-page: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  --color-bg-page-solid: #0f172a;
  --color-bg-card: #fff;
  --color-bg-card-hover: #fbfdff;
  --color-bg-badge: #f8fafc;
  --color-bg-tag: #f8fafc;
  --color-bg-button: transparent;
  --color-bg-button-hover: #f8fafc;
  --color-border-card: #e5e7eb;
  --color-border-card-hover: #cfd3da;
  --color-border-badge: #e5e7eb;
  --color-border-tag: #cbd5e1;
  --color-border-button: #cbd5e1;
  --color-arrow: #9aa4b2;
  --color-arrow-hover: #64748b;
  --color-section-divider-start: #c7ced8;
  --color-shadow-card: rgba(15, 23, 42, 0.04);
  --color-shadow-card-hover: rgba(15, 23, 42, 0.08);
  --color-focus-ring: #60a5fa;
}

/* Theme: Mint (Light - Mint/teal/coral vibrant mix) */
[data-theme="mint"] {
  --color-text: #134e4a;
  --color-text-muted: #0f766e;
  --color-text-secondary: #ff6b6b;
  --color-text-tertiary: #ff8787;
  --color-bg-page: linear-gradient(180deg, #f0fdfa 0%, #ccfbf1 100%);
  --color-bg-page-solid: #134e4a;
  --color-bg-card: #f5fffd;
  --color-bg-card-hover: #e6fffa;
  --color-bg-badge: #99f6e4;
  --color-bg-tag: #ffb3ba;
  --color-bg-button: transparent;
  --color-bg-button-hover: #ccfbf1;
  --color-border-card: #5eead4;
  --color-border-card-hover: #2dd4bf;
  --color-border-badge: #14b8a6;
  --color-border-tag: #ff6b6b;
  --color-border-button: #0d9488;
  --color-arrow: #ff6b6b;
  --color-arrow-hover: #14b8a6;
  --color-section-divider-start: #5eead4;
  --color-shadow-card: rgba(20, 184, 166, 0.1);
  --color-shadow-card-hover: rgba(255, 107, 107, 0.15);
  --color-focus-ring: #14b8a6;
}

/* ========== Base Styles ========== */
* {
  box-sizing: border-box;
}

html {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--color-bg-page-solid);
}

body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "YuGothic", Meiryo, sans-serif;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg-page);
}

.reduce-motion * {
  transition: none !important;
}

/* ========== Index Page Components ========== */

/* Container */
.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px;
}

/* Branding */
.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0 16px 0;
}

.sub {
  margin: 0 0 24px 0;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* Tag */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--color-border-tag);
  background: var(--color-bg-tag);
  color: var(--color-text-secondary);
  font-size: 11px;
  margin-left: 8px;
}

/* Section Title */
.sectionTitle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.sectionTitle:after {
  content: "";
  height: 1px;
  background: linear-gradient(90deg, var(--color-section-divider-start), transparent);
  flex: 1;
}

/* Grid Layout */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

/* Card */
.card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  text-decoration: none;
  color: inherit;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-card);
  border-radius: 12px;
  padding: 14px 16px;
  min-height: 68px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
  box-shadow: 0 1px 2px var(--color-shadow-card);
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px var(--color-shadow-card-hover);
  border-color: var(--color-border-card-hover);
  background: var(--color-bg-card-hover);
}

.card:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.title {
  display: block;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.arrow {
  color: var(--color-arrow);
  transition: transform 0.18s ease, color 0.18s ease;
  font-size: 22px;
  transform: scaleY(1.6);
  font-weight: 300;
  align-self: center;
}

.card:hover .arrow {
  transform: translateX(3px) scaleY(1.6);
  color: var(--color-arrow-hover);
}

/* Meta & Badges */
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-width: 50px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--color-border-badge);
  background: var(--color-bg-badge);
  color: var(--color-text-muted);
  font-size: 11px;
}

.metaGrid-3x2 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.metaGrid-2x1 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.metaGrid-2x2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.metaGrid-1x1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.metaGrid-3x2 .badge,
.metaGrid-2x1 .badge,
.metaGrid-2x2 .badge,
.metaGrid-1x1 .badge {
  justify-content: center;
}

/* Actions & Buttons */
.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  margin: -6px 0 10px 0;
}

.ghost-btn {
  appearance: none;
  background: var(--color-bg-button);
  border: 1px solid var(--color-border-button);
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.ghost-btn:hover {
  background: var(--color-bg-button-hover);
}

/* Timeframe Quick Menu */
.tf-menu {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: #0f172a;
  border: 1px solid #1f2937;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.tf-option {
  cursor: pointer;
  padding: 2px 8px;
  border: 1px solid #334155;
  border-radius: 999px;
  font-size: 11px;
  color: #e5e7eb;
  background: #0b1220;
}

.tf-option:hover {
  background: #111a2e;
}

/* Theme Selector */
.theme-selector {
  position: relative;
  display: flex;
  align-items: center;
}

.theme-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-card);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--color-shadow-card-hover);
  min-width: 120px;
}

.theme-menu.hidden {
  display: none;
}

.theme-option {
  appearance: none;
  background: transparent;
  border: 1px solid var(--color-border-button);
  color: var(--color-text-muted);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.theme-option:hover {
  background: var(--color-bg-button-hover);
  border-color: var(--color-border-card-hover);
}

.theme-option.active {
  background: var(--color-bg-badge);
  border-color: var(--color-border-badge);
  font-weight: 600;
}

/* Footer */
footer {
  margin-top: 28px;
  color: var(--color-text-tertiary);
  font-size: 12px;
}

/* ========== Charts Page Components ========== */

/* Charts page uses existing theme variables */
body:has(#grid) {
  background: var(--color-bg-page);
  color: var(--color-text);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border-card);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  background: var(--color-bg-card);
  backdrop-filter: blur(6px);
  transform: translateY(0);
  transition: transform 0.2s ease;
  z-index: 20;
}

.header.hidden {
  transform: translateY(-100%);
}

.small {
  font-size: 12px;
  color: var(--color-text-muted);
}

body:has(#grid) .grid {
  display: grid;
  height: 100%;
  gap: 0;
}

.grid iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.btn {
  font-size: 12px;
  color: var(--color-text-muted);
  text-decoration: none;
  border: 1px solid var(--color-border-button);
  padding: 4px 8px;
  border-radius: 8px;
}

/* Transparent hotspot to detect entry over iframes */
.edgeHotspot {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  z-index: 2147483647;
  pointer-events: auto;
  background: transparent;
}
