* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: radial-gradient(circle at top left, rgba(58,84,120,0.35), transparent 28%), linear-gradient(180deg, #101726 0%, #0b1220 100%); color: #d7dfec; font-family: "Segoe UI", "Hiragino Sans", sans-serif; height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
#header { border-bottom: 1px solid rgba(128, 156, 194, 0.24); background: rgba(8, 13, 24, 0.9); display: flex; flex-direction: column; gap: 0; flex-shrink: 0; }
.header-main { min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 8px 14px; flex-wrap: wrap; }
#header h1 { font-size: 14px; letter-spacing: 0.08em; color: #a8c7ff; white-space: nowrap; }
.header-stats { display: flex; align-items: stretch; gap: 8px; min-width: 0; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
#header .spacer { flex: 1; }
#header button, .search-row button, .sidebar-tab, .metric-card { cursor: pointer; }
#header button { height: 28px; padding: 0 12px; border: 1px solid #41608a; background: #182742; color: #d8e6ff; border-radius: 7px; font-size: 11px; }
#header button:hover, .search-row button:hover { background: #22395e; }
.nav-link { height: 28px; padding: 0 12px; border: 1px solid #41608a; background: #182742; color: #d8e6ff; border-radius: 7px; font-size: 11px; text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }
.nav-link:hover { background: #22395e; }
.nav-link.active { background: #35598c; border-color: #8cb9ff; color: #f7fbff; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14); }
.mobile-toggle { display: none; }
#layout { flex: 1; display: flex; min-height: 0; }
#sidebar { width: 300px; min-width: 300px; border-right: 1px solid rgba(128, 156, 194, 0.18); background: rgba(10, 17, 30, 0.86); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#ranking h2, #sectors h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: #6f819e; margin: 0 0 8px; white-space: nowrap; }
.sidebar-tabs { display: flex; gap: 8px; padding: 12px 14px 0; }
.sidebar-tab { flex: 1; height: 30px; border: 1px solid rgba(116, 147, 192, 0.14); background: rgba(19, 30, 50, 0.75); color: #a8bddf; border-radius: 9px; font-size: 11px; }
.sidebar-tab.active, .metric-card.active { border-color: rgba(113, 171, 255, 0.55); box-shadow: inset 0 0 0 1px rgba(113, 171, 255, 0.18); background: rgba(25, 43, 75, 0.94); color: #eef5ff; }
.sidebar-panel { display: none; min-height: 0; }
.sidebar-panel.active { display: flex; flex-direction: column; flex: 1; }
.stat-grid { display: flex; align-items: stretch; gap: 8px; flex: 1; overflow-x: auto; overflow-y: hidden; }
.stat-card, .selection-card, .metric-card, .sector-row, .ranking-list { background: rgba(19, 30, 50, 0.75); border: 1px solid rgba(116, 147, 192, 0.14); border-radius: 10px; }
.stat-card { padding: 7px 10px; min-width: 98px; flex: 0 0 auto; }
.stat-card.wide { min-width: 148px; }
.time-card { padding: 7px 10px; min-width: 118px; flex: 0 0 auto; background: rgba(19, 30, 50, 0.82); border: 1px solid rgba(116, 147, 192, 0.18); border-radius: 10px; }
.stat-card .label, .metric-card .label { font-size: 10px; color: #6e86ab; margin-bottom: 4px; }
.stat-card .value, .metric-card .value { font-size: 13px; color: #eef5ff; font-weight: 700; }
.time-card .label { font-size: 10px; color: #6e86ab; margin-bottom: 4px; }
.time-card .value { font-size: 13px; color: #eef5ff; font-weight: 700; }
.selection-card { padding: 8px 10px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selection-card.empty { color: #7c8fae; font-size: 12px; }
.selection-card .inline { display: flex; align-items: center; gap: 10px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selection-card .symbol { font-size: 11px; color: #84a8e7; }
.selection-card .name { font-size: 13px; color: #eef5ff; font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selection-card .meta { font-size: 11px; color: #9eb4d6; }
.selection-card .price { font-size: 11px; color: #dfeaff; }
.search-row { display: flex; gap: 6px; margin: 0; width: 220px; flex: 0 0 auto; }
.header-search { width: min(320px, 100%); }
.search-row input { flex: 1; min-width: 0; height: 30px; border: 1px solid rgba(116, 147, 192, 0.22); background: rgba(12, 20, 34, 0.86); color: #eaf1ff; border-radius: 8px; padding: 0 10px; font-size: 12px; }
.search-row button { height: 30px; padding: 0 10px; border: 1px solid #41608a; background: #182742; color: #d8e6ff; border-radius: 8px; font-size: 11px; }
#insights { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#sectors, #ranking { padding: 12px 14px 14px; }
#sector-list, #ranking-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
#sidebar, #sector-list, #ranking-list {
  scrollbar-color: rgba(10, 17, 30, 0.96) rgba(10, 17, 30, 0.96);
  scrollbar-width: thin;
}
#sidebar::-webkit-scrollbar,
#sector-list::-webkit-scrollbar,
#ranking-list::-webkit-scrollbar {
  width: 10px;
}
#sidebar::-webkit-scrollbar-track,
#sector-list::-webkit-scrollbar-track,
#ranking-list::-webkit-scrollbar-track,
#sidebar::-webkit-scrollbar-thumb,
#sector-list::-webkit-scrollbar-thumb,
#ranking-list::-webkit-scrollbar-thumb {
  background: rgba(10, 17, 30, 0.96);
  border-radius: 999px;
}
.sector-row { padding: 8px 10px; margin-bottom: 8px; }
.sector-row .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.sector-row .code { font-size: 10px; color: #84a8e7; min-width: 42px; }
.sector-row .name { flex: 1; font-size: 12px; color: #e7efff; }
.sector-row .count { font-size: 11px; color: #9eb4d6; }
.sector-row .cap { font-size: 10px; color: #6f819e; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.metric-grid-four { grid-template-columns: repeat(4, 1fr); }
.metric-card { padding: 8px 9px; color: #dce7fb; text-align: left; }
.metric-card .hint { font-size: 10px; color: #6f819e; margin-top: 4px; }
.ranking-item { width: 100%; border: 0; border-bottom: 1px solid rgba(116, 147, 192, 0.08); background: transparent; color: inherit; text-align: left; padding: 8px 10px; cursor: pointer; }
.ranking-item:last-child { border-bottom: 0; }
.ranking-item:hover { background: rgba(27, 42, 68, 0.62); }
.ranking-item .top { display: flex; align-items: baseline; gap: 8px; }
.ranking-item .rank { min-width: 26px; font-size: 10px; color: #6f819e; }
.ranking-item .symbol { font-size: 11px; color: #84a8e7; }
.ranking-item .metric { margin-left: auto; font-size: 11px; color: #f4f8ff; font-weight: 700; }
.ranking-item .name { font-size: 12px; color: #e7efff; margin-top: 2px; }
.ranking-item .meta { font-size: 10px; color: #7d93b4; margin-top: 2px; }
#canvas-wrap { flex: 1; position: relative; overflow: hidden; background: radial-gradient(circle at 18% 12%, rgba(255, 208, 112, 0.12), transparent 24%), linear-gradient(180deg, #86bfff 0%, #d7ecff 38%, #89a5cb 100%); transition: background 720ms linear; }
#pixi-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
#pixi-canvas.dragging { cursor: grabbing; }
#snapshot-overlay { position: absolute; inset: 0; z-index: 0; opacity: 0; transition: opacity 180ms ease; pointer-events: none; }
#snapshot-overlay.visible { opacity: 1; }
#snapshot-overlay img { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(1.02) contrast(1.01); }
#loading { position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; background: rgba(7, 10, 18, 0.72); color: #d6e4ff; font-size: 14px; letter-spacing: 0.05em; padding: 20px; text-align: center; }
.loading-panel { min-width: min(92vw, 380px); display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 24px; border: 1px solid rgba(126, 158, 206, 0.24); border-radius: 18px; background: rgba(10, 16, 28, 0.88); box-shadow: 0 20px 48px rgba(0, 0, 0, 0.34); backdrop-filter: blur(10px); }
.loading-spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(132, 168, 231, 0.18); border-top-color: #f6d68c; border-right-color: #84a8e7; animation: kabu-spin 0.9s linear infinite; }
.loading-title { font-size: 15px; font-weight: 700; color: #eef5ff; letter-spacing: 0.02em; }
.loading-note { font-size: 12px; line-height: 1.7; color: #8ea3c6; white-space: pre-line; }
.loading-panel.is-error .loading-spinner { display: none; }
.loading-panel.is-error .loading-title { color: #ffd4b8; }
@keyframes kabu-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
#statusbar { min-height: 52px; border-top: 1px solid rgba(128, 156, 194, 0.18); background: rgba(8, 13, 24, 0.92); display: flex; align-items: center; gap: 12px; padding: 8px 12px; font-size: 11px; color: #7c8fae; flex-shrink: 0; }
#statusbar strong { color: #e8f1ff; font-weight: 600; }
#site-footer { min-height: 34px; border-top: 1px solid rgba(128, 156, 194, 0.12); background: rgba(7, 12, 22, 0.96); display: flex; align-items: center; justify-content: center; padding: 8px 12px; font-size: 11px; color: #8fa5c6; flex-shrink: 0; }
#site-footer a { color: #cfe0ff; text-decoration: none; }
#site-footer a:hover { text-decoration: underline; }
.status-tabs { display: none; }
.status-panel { display: contents; }
.status-tab { appearance: none; border: 1px solid rgba(116, 147, 192, 0.16); background: rgba(13, 22, 38, 0.84); color: #9cb0cf; border-radius: 10px; min-height: 36px; padding: 0 12px; font-weight: 700; }
.status-tab.active { background: rgba(50, 98, 176, 0.3); border-color: rgba(111, 167, 255, 0.44); color: #eef5ff; }
.status-chip { display: flex; align-items: center; padding: 0 10px; border: 1px solid rgba(116, 147, 192, 0.12); background: rgba(13, 22, 38, 0.84); border-radius: 10px; white-space: nowrap; min-height: 46px; }
.layer-controls { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.layer-label { color: #90a4c4; font-weight: 700; white-space: nowrap; }
.layer-toggle { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 8px; border: 1px solid rgba(116, 147, 192, 0.12); background: rgba(13, 22, 38, 0.84); border-radius: 9px; color: #dce8ff; white-space: nowrap; }
.layer-toggle-wide { padding-right: 10px; }
.layer-toggle input { accent-color: #6fa7ff; }

.ranking-page-body {
  overflow: auto;
}

.ranking-page-layout {
  flex: 1;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.ranking-page-panel {
  max-width: 1180px;
  margin: 0 auto;
  background: rgba(10, 17, 30, 0.86);
  border: 1px solid rgba(116, 147, 192, 0.14);
  border-radius: 14px;
  padding: 14px;
}

.ranking-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.ranking-page-title {
  font-size: 18px;
  font-weight: 700;
  color: #eef5ff;
}

.ranking-page-subtitle {
  font-size: 12px;
  color: #7d93b4;
}

.ranking-page-list {
  overflow: hidden;
}

.ranking-page-item {
  width: 100%;
  display: grid;
  grid-template-columns: 64px 92px minmax(180px, 1.6fr) minmax(120px, 1fr) 110px 120px 140px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(116, 147, 192, 0.08);
}

.ranking-page-item:last-child {
  border-bottom: 0;
}

.ranking-page-item.header {
  font-size: 11px;
  color: #7d93b4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(18, 28, 46, 0.92);
}

.ranking-page-item:not(.header):hover {
  background: rgba(27, 42, 68, 0.62);
}

.ranking-page-item .rank {
  color: #84a8e7;
  font-weight: 700;
}

.ranking-page-item .symbol {
  color: #9ebdff;
  font-weight: 700;
}

.ranking-page-item .name {
  color: #eef5ff;
  min-width: 0;
}

.ranking-page-item .sector {
  color: #9eb4d6;
}

.ranking-page-item .ratio {
  color: #f6d68c;
  font-weight: 700;
}

.ranking-page-item .volume,
.ranking-page-item .turnover {
  color: #dce8ff;
  text-align: right;
}

.ranking-empty {
  padding: 24px 12px;
  color: #7d93b4;
  text-align: center;
}

@media (max-width: 1180px) {
  #layout {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    min-width: 0;
    max-height: min(42vh, 430px);
    border-right: 0;
    border-bottom: 1px solid rgba(128, 156, 194, 0.18);
  }

  #canvas-wrap {
    min-height: 58vh;
  }

  .ranking-page-item {
    grid-template-columns: 54px 82px minmax(140px, 1.4fr) minmax(100px, 1fr) 94px 110px 124px;
    gap: 8px;
  }

}

@media (max-width: 780px) {
  body {
    overflow: hidden;
  }

  .header-main {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
  }

  #header h1 {
    width: 100%;
    font-size: 12px;
    letter-spacing: 0.06em;
  }

  #header .spacer {
    display: none;
  }

  #header button {
    min-width: 0;
    height: 34px;
    padding: 0 10px;
  }

  .mobile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-toggle.active {
    background: #29466f;
    border-color: #6f9cff;
    color: #f2f7ff;
  }

  #sidebar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: auto;
    width: auto;
    max-height: 42vh;
    border: 1px solid rgba(128, 156, 194, 0.2);
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 180ms ease, transform 180ms ease;
    z-index: 30;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  body.mobile-sidebar-open #sidebar {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .sidebar-tabs {
    flex-direction: row;
  }

  .sidebar-tab {
    width: 100%;
    min-height: 44px;
  }

  .header-stats,
  .header-search,
  .time-card {
    width: auto;
  }

  .header-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
    width: 100%;
  }

  .header-stats .stat-card {
    min-width: 0;
    padding: 6px 8px;
  }

  .header-stats .stat-card .label {
    font-size: 9px;
    margin-bottom: 2px;
  }

  .header-stats .stat-card .value {
    font-size: 12px;
  }

  .header-search {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    flex: 0 1 180px;
    min-width: 0;
  }

  .time-card {
    min-width: 112px;
  }

  .header-search input {
    min-width: 0;
    width: auto;
    flex: 1 1 auto;
    min-height: 38px;
  }

  .header-search button {
    width: auto;
    flex: 0 0 auto;
    min-height: 38px;
    white-space: nowrap;
  }

  #toggle-sidebar,
  #toggle-status,
  #reset-view {
    width: auto;
    flex: 0 0 auto;
    min-width: 0;
    min-height: 38px;
    white-space: nowrap;
  }

  .sector-row .top,
  .ranking-item .top {
    flex-wrap: wrap;
  }

  .sector-row .count,
  .ranking-item .metric {
    margin-left: 0;
  }

  #canvas-wrap {
    min-height: 0;
  }

  #statusbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 52px;
    min-height: 0;
    max-height: 42vh;
    border: 1px solid rgba(128, 156, 194, 0.2);
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 180ms ease, transform 180ms ease;
    z-index: 35;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .status-tabs { display: flex; gap: 8px; }
  .status-tab { flex: 1 1 0; }
  .status-panel { display: none; }
  #statusbar[data-status-tab="info"] .status-panel-info { display: grid; gap: 8px; }
  #statusbar[data-status-tab="layers"] .status-panel-layers { display: block; }
  .status-chip { width: 100%; }
  .status-panel-layers .layer-controls { margin-left: 0; width: 100%; justify-content: flex-start; }

  body.mobile-status-open #statusbar {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  #site-footer {
    min-height: 42px;
    font-size: 10px;
    padding: 8px 10px;
  }

  .ranking-page-layout {
    padding: 10px;
  }

  .ranking-page-panel {
    padding: 10px;
  }

  .ranking-page-item {
    grid-template-columns: 48px 74px 1.4fr 92px 80px;
    gap: 8px;
    padding: 10px;
  }

  .ranking-page-item .sector,
  .ranking-page-item .turnover {
    display: none;
  }
}

@media (max-width: 520px) {
  .header-main {
    padding: 8px;
  }

  .stat-card .value,
  .metric-card .value,
  .selection-card .name {
    font-size: 13px;
  }

  .selection-card .price,
  .selection-card .meta,
  .ranking-item .name,
  .sector-row .name {
    line-height: 1.5;
  }

  #canvas-wrap {
    min-height: 0;
  }
}
