:root {
  --color-bg: #f4f4f6;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #555555;
  --color-accent: #2b5fad;
  --color-accent-soft: rgba(43, 95, 173, 0.12);
  --color-border: #e2e2e6;
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14161c;
    --color-surface: #1e2129;
    --color-text: #edeef2;
    --color-text-muted: #a3a7b3;
    --color-accent: #6fa0e6;
    --color-accent-soft: rgba(111, 160, 230, 0.16);
    --color-border: #3a3f4c;
    --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.5);
  }

  .treemap-logo,
  .detail-panel-logo,
  .treemap-peek-tile {
    background: #fff;
    border-radius: 4px;
    padding: 2px;
  }
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.treemap-stage {
  position: relative;
  margin: 24px auto;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.treemap-box {
  position: absolute;
  box-sizing: border-box;
  overflow: hidden;
  border: 1px solid var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.treemap-category {
  background: var(--color-accent-soft);
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4px 6px;
  cursor: pointer;
}

.treemap-leaf {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  cursor: pointer;
  padding: 4px;
}

.treemap-label {
  font-size: 12px;
  color: var(--color-text);
}

.treemap-logo {
  max-width: 60%;
  max-height: 50%;
  object-fit: contain;
  margin-bottom: 4px;
}

.treemap-logo-fallback {
  font-size: 20px;
  font-weight: bold;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.treemap-breadcrumb {
  max-width: 1000px;
  margin: 12px auto 0;
  font-size: 14px;
}

.treemap-crumb {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  font: inherit;
  padding: 2px 4px;
}

.treemap-crumb:disabled {
  color: var(--color-text);
  cursor: default;
  font-weight: 600;
}

.treemap-crumb-sep {
  color: var(--color-text-muted);
}

.treemap-mode-bar {
  max-width: 1000px;
  margin: 12px auto 0;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.treemap-mode-button,
.treemap-window-button {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--color-text);
  font: inherit;
}

.treemap-mode-button-active,
.treemap-window-button-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.treemap-window-group {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.treemap-box-insufficient-history {
  background-image: repeating-linear-gradient(
    45deg,
    var(--color-border),
    var(--color-border) 4px,
    transparent 4px,
    transparent 8px
  );
  opacity: 0.6;
}

.treemap-others {
  background-image: repeating-linear-gradient(
    45deg,
    var(--color-border),
    var(--color-border) 4px,
    transparent 4px,
    transparent 8px
  );
  border: 1px dashed var(--color-border);
  cursor: pointer;
  padding: 4px 6px;
  align-items: flex-start;
  justify-content: flex-start;
}

.treemap-peek-grid {
  position: relative;
  margin-top: 4px;
}

.treemap-peek-tile {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-surface);
  background: var(--color-surface);
  padding: 2px;
  overflow: hidden;
  cursor: pointer;
}

.treemap-peek-tile img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.treemap-collage {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 1px;
  width: 100%;
  height: 100%;
}

.treemap-collage img {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
}

.treemap-peek-tile .treemap-logo-fallback {
  font-size: 10px;
  margin-bottom: 0;
}

.treemap-peek-tile-others {
  background-image: repeating-linear-gradient(
    45deg,
    var(--color-border),
    var(--color-border) 3px,
    transparent 3px,
    transparent 6px
  );
  color: var(--color-text-muted);
  font-size: 9px;
  cursor: default;
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  padding: 20px;
  box-sizing: border-box;
  transform: translateX(100%);
  transition: transform 0.2s ease-out;
  overflow-y: auto;
}

.detail-panel-open {
  transform: translateX(0);
}

.detail-panel-close {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 22px;
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
}

.detail-panel-logo {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  display: block;
  margin: 12px auto;
}

.detail-panel-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--color-accent);
}

.detail-panel-growth {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 8px 0;
}

.detail-panel-stars {
  display: block;
  margin-top: 12px;
  font-weight: 600;
  color: var(--color-accent);
}

.detail-panel-star-chart {
  margin-top: 8px;
}

.detail-panel-star-chart-svg path {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.detail-panel-star-chart-caption {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 4px 0 0;
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 72px 24px 56px;
  text-align: center;
  background: linear-gradient(180deg, var(--color-accent-soft), transparent);
}

.hero-motif {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.hero-rect {
  position: absolute;
  border-radius: 12px;
  background: var(--color-accent);
  opacity: 0.08;
}

.hero-rect-1 {
  width: 220px;
  height: 140px;
  top: -30px;
  left: 8%;
  transform: rotate(-6deg);
}

.hero-rect-2 {
  width: 160px;
  height: 160px;
  top: 40px;
  right: 10%;
  opacity: 0.12;
  transform: rotate(10deg);
}

.hero-rect-3 {
  width: 120px;
  height: 90px;
  bottom: -20px;
  left: 22%;
  opacity: 0.1;
  transform: rotate(4deg);
}

.hero-rect-4 {
  width: 90px;
  height: 90px;
  bottom: 10px;
  right: 22%;
  opacity: 0.14;
  transform: rotate(-12deg);
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.hero-tagline {
  margin: 16px 0 0;
  font-size: 1.05rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.map-index {
  box-sizing: border-box;
  max-width: 960px;
  margin: 40px auto 64px;
  padding: 0 24px;
  text-align: center;
}

.map-index-heading {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 16px;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  text-align: left;
}

.map-card {
  display: block;
  padding: 16px;
  border-radius: 10px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

.map-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.map-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--color-accent);
}

.map-card p {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

.back-link {
  max-width: 1000px;
  margin: 12px auto 8px;
  font-size: 14px;
}

.back-link a {
  color: var(--color-accent);
  text-decoration: none;
}
