:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #e4e7ec;
  --navy: #111827;
  --gold: #d6a84b;
  --gold-soft: #fff4d8;
  --green: #158467;
  --green-soft: #e8f7f1;
  --red-soft: #fff0ed;
  --shadow: 0 12px 32px rgba(17, 24, 39, .07);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--ink); font-family: "Yu Gothic UI", "Hiragino Sans", sans-serif; }
body { margin: 0; min-height: 100vh; }
button, select, input { font: inherit; }
button { cursor: pointer; }

.app-header { min-height: 78px; padding: 14px max(18px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--navy); color: white; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid rgba(255,255,255,.28); border-radius: 13px; color: var(--gold); font: 800 23px/1 Georgia, serif; }
.brand h1 { margin: 2px 0 0; font-size: clamp(16px, 4vw, 21px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eyebrow { margin: 0; color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.private-badge { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #5ee6b0; box-shadow: 0 0 0 4px rgba(94,230,176,.12); }

.tab-bar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.tab { min-height: 50px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.tab.is-active { color: var(--ink); border-bottom-color: var(--gold); }

main { width: min(1120px, 100%); margin: 0 auto; padding: 18px 14px 60px; }
.view { display: none; }
.view.is-active { display: block; animation: appear .18s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } }

.hero-card { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 25px; border-radius: 24px; background: linear-gradient(135deg, #182235 0%, #111827 65%, #29354a 100%); color: white; box-shadow: var(--shadow); }
.hero-card h2 { margin: 8px 0; font-size: clamp(24px, 6vw, 38px); letter-spacing: -.03em; }
.hero-copy { max-width: 550px; margin: 0; color: #c6cbd4; font-size: 13px; line-height: 1.7; }
.hero-number { text-align: right; flex: 0 0 auto; }
.hero-number strong { display: block; color: var(--gold); font: 700 clamp(42px, 10vw, 68px)/.85 Georgia, serif; }
.hero-number span { color: #c6cbd4; font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0; }
.stat-card { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat-card span { color: var(--muted); font-size: 11px; }
.stat-card strong { display: block; margin-top: 6px; font-size: 23px; }

.panel, .insight-panel { margin-top: 14px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 5px 20px rgba(17,24,39,.035); }
.section-heading, .page-heading, .matrix-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.section-heading h2, .page-heading h2, .insight-panel h2 { margin: 4px 0 0; font-size: 20px; }
.page-heading { align-items: flex-start; margin: 8px 4px 20px; }
.page-heading p:not(.eyebrow) { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.caption { color: var(--muted); font-size: 11px; }

.ranking-item { display: grid; grid-template-columns: 31px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.ranking-item:last-child { border: 0; }
.rank { color: var(--gold); font: 700 19px Georgia, serif; }
.rank-main { min-width: 0; }
.rank-label { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 700; }
.rank-label span:last-child { color: var(--muted); font-size: 11px; font-weight: 500; }
.progress { height: 5px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: #eef0f3; }
.progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #efcd7d); }
.rank-count { min-width: 39px; text-align: right; font-size: 12px; font-weight: 800; }

.bar-chart { display: grid; grid-template-columns: repeat(10, 1fr); align-items: end; gap: 5px; min-height: 190px; padding-top: 8px; }
.bar-item { display: grid; grid-template-rows: 24px 125px 25px; align-items: end; text-align: center; }
.bar-value { color: var(--muted); font-size: 10px; }
.bar-track { height: 125px; display: flex; align-items: flex-end; justify-content: center; }
.bar-fill { width: min(28px, 80%); min-height: 8px; border-radius: 7px 7px 2px 2px; background: #ccd2dc; }
.bar-item.hot .bar-fill { background: linear-gradient(180deg, #e0bd6b, var(--gold)); }
.bar-label { font-size: 11px; font-weight: 700; }

.pair-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pair-card { padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #fafafa; }
.pair-card strong { display: block; overflow: hidden; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.pair-meta { display: flex; align-items: baseline; justify-content: space-between; margin-top: 8px; }
.pair-number { color: var(--green); font: 800 21px Georgia, serif; }
.pair-count { color: var(--muted); font-size: 10px; }

.insight-panel { color: white; background: var(--navy); border-color: var(--navy); }
.insight-list { display: grid; gap: 10px; margin-top: 16px; }
.insight { padding: 14px; border-left: 3px solid var(--gold); border-radius: 0 10px 10px 0; background: rgba(255,255,255,.06); }
.insight strong { display: block; margin-bottom: 4px; font-size: 13px; }
.insight p { margin: 0; color: #cdd2db; font-size: 12px; line-height: 1.65; }

.filter-panel { display: grid; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.filter-panel label, .compact-filter { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
select, input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid #d7dbe2; border-radius: 11px; background: white; color: var(--ink); outline: 0; }
select:focus, input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(214,168,75,.15); }
.secondary-button { height: 42px; border: 1px solid var(--line); border-radius: 11px; background: #f7f8fa; color: var(--ink); font-weight: 700; }
.result-count { margin: 18px 3px 10px; color: var(--muted); font-size: 12px; }
.result-list { display: grid; gap: 8px; }
.result-card { display: grid; grid-template-columns: 58px minmax(0,1fr) auto; align-items: center; gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.result-date { color: var(--muted); font-size: 11px; }
.result-machine { overflow: hidden; font-size: 13px; font-weight: 800; white-space: nowrap; text-overflow: ellipsis; }
.result-number { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: var(--green); background: var(--green-soft); font: 800 18px Georgia, serif; }
.empty-state { padding: 35px 20px; border: 1px dashed #cfd4dc; border-radius: var(--radius); color: var(--muted); text-align: center; }

.compact-filter { width: 145px; }
.compact-filter select { height: 39px; }
.matrix-help { margin: -8px 4px 12px; color: var(--muted); font-size: 11px; }
.matrix-wrap { max-height: calc(100vh - 235px); overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: white; overscroll-behavior: contain; }
.matrix-table { border-collapse: separate; border-spacing: 0; font-size: 10px; }
.matrix-table th, .matrix-table td { min-width: 42px; height: 35px; padding: 3px; border-right: 1px solid #edf0f3; border-bottom: 1px solid #edf0f3; text-align: center; }
.matrix-table thead th { position: sticky; top: 0; z-index: 3; height: 42px; background: var(--navy); color: white; font-weight: 700; }
.matrix-table th:first-child, .matrix-table td:first-child { position: sticky; left: 0; z-index: 2; min-width: 54px; background: #f4f5f7; color: var(--ink); font-weight: 800; }
.matrix-table thead th:first-child { z-index: 4; background: var(--navy); color: white; }
.matrix-cell { border: 0; width: 100%; height: 27px; border-radius: 6px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 900; }
.missing-date { background: #fff0ed !important; color: #b5473e !important; }
.cell-popover { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 30; width: min(360px, calc(100% - 28px)); padding: 14px 16px; border-radius: 14px; background: var(--navy); color: white; box-shadow: 0 16px 40px rgba(0,0,0,.25); transform: translateX(-50%); font-size: 12px; }

.info-stack { display: grid; gap: 10px; }
.info-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.info-card h3 { margin: 0 0 8px; font-size: 15px; }
.info-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.75; }
code { padding: 2px 5px; border-radius: 5px; background: #eef0f3; color: var(--ink); }
footer { padding: 20px; color: #98a2b3; font-size: 9px; font-weight: 800; letter-spacing: .17em; text-align: center; }

@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .filter-panel { grid-template-columns: repeat(3, 1fr) auto; align-items: end; }
  .pair-grid { grid-template-columns: repeat(5, 1fr); }
  .insight-list, .info-stack { grid-template-columns: repeat(2, 1fr); }
  .result-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .private-badge { padding: 6px 8px; font-size: 10px; }
  .hero-card { align-items: center; padding: 21px 18px; }
  .hero-copy { display: none; }
  .panel, .insight-panel { padding: 17px 15px; }
  .pair-card { padding: 11px; }
  .matrix-heading { align-items: end; }
}
