: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; }
.share-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 span { margin-right: 4px; color: #98a2b3; }
.tab.is-active { color: var(--ink); border-bottom-color: var(--gold); }
.tab.is-active span { 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; }
.update-strip { display: flex; justify-content: space-between; gap: 12px; margin: 10px 4px 0; color: var(--muted); font-size: 10px; }
.update-strip strong { color: var(--ink); }

.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); }
.attention-panel { margin-top: 14px; padding: 20px; border-radius: var(--radius); color: white; background: linear-gradient(135deg, #172234, #111827); box-shadow: var(--shadow); }
.attention-panel .caption, .attention-panel .panel-note { color: #b9c0cc; }
.panel-note { margin: -5px 0 14px; color: var(--muted); font-size: 11px; line-height: 1.7; }
.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; }
.date-pill { padding: 7px 10px; border-radius: 999px; color: #7a5612; background: var(--gold-soft); font-size: 12px; font-weight: 800; }

.latest-grid { display: grid; gap: 8px; }
.latest-card { position: relative; display: grid; grid-template-columns: 44px minmax(0,1fr) 15px; align-items: center; gap: 11px; min-height: 61px; padding: 9px 11px 9px 9px; border: 1px solid var(--line); border-radius: 14px; background: #fbfbfc; cursor: pointer; }
.latest-card .favorite-button { position: absolute; top: 3px; left: 3px; }
.latest-number { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--green); background: var(--green-soft); font: 800 19px Georgia, serif; }
.latest-main { min-width: 0; }
.latest-main strong, .latest-main span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.latest-main strong { font-size: 13px; }
.latest-main span { margin-top: 5px; color: var(--muted); font-size: 10px; }
.chevron { color: #98a2b3; font-size: 21px; }

.favorite-button { width: 27px; height: 27px; padding: 0; border: 0; border-radius: 50%; color: #c8cdd5; background: transparent; font-size: 16px; line-height: 1; }
.favorite-button.is-favorite { color: var(--gold); }
.favorite-list { display: grid; gap: 8px; }
.favorite-card { display: grid; grid-template-columns: 43px minmax(0,1fr) 30px; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; cursor: pointer; }
.favorite-no { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; color: var(--green); background: var(--green-soft); font: 800 18px Georgia, serif; }
.favorite-card strong, .favorite-card span { display: block; }
.favorite-card div strong { overflow: hidden; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.favorite-card div span { margin-top: 4px; color: var(--muted); font-size: 10px; }

.attention-list { display: grid; gap: 6px; }
.attention-item { display: grid; grid-template-columns: 25px minmax(0,1fr) 30px; align-items: center; gap: 9px; padding: 10px 0; border-top: 1px solid rgba(255,255,255,.09); cursor: pointer; }
.attention-rank { color: var(--gold); font: 700 18px Georgia, serif; }
.attention-main { min-width: 0; }
.attention-main > div:first-child { display: flex; justify-content: space-between; gap: 10px; }
.attention-main strong { overflow: hidden; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.attention-main span { flex: 0 0 auto; color: #b9c0cc; font-size: 9px; }
.attention-panel .progress { background: rgba(255,255,255,.11); }

.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; }
.bar-label small { display: block; margin-top: 3px; color: var(--muted); font-size: 8px; font-weight: 500; }

.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; }

.tool-panel { margin-bottom: 14px; }
.filter-panel { display: grid; gap: 10px; }
.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; }
.primary-button { height: 44px; padding: 0 18px; border: 0; border-radius: 11px; color: white; background: var(--navy); font-weight: 800; }
.inline-controls { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 9px; }
.inline-controls label, .wide-select { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.wide-select { margin-bottom: 14px; }
.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: 48px minmax(0,1fr) auto 28px; align-items: center; gap: 9px; padding: 11px; border: 1px solid var(--line); border-radius: 14px; background: #fbfbfc; cursor: pointer; }
.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; }
.empty-state.compact { padding: 20px; }

.profile-hero { display: flex; align-items: center; gap: 13px; margin-top: 16px; padding: 15px; border-radius: 15px; color: white; background: var(--navy); }
.profile-hero > span { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 15px; color: var(--gold); background: rgba(255,255,255,.08); font: 800 27px Georgia, serif; }
.profile-hero p, .profile-hero h3 { margin: 0; }
.profile-hero p { color: #b9c0cc; font-size: 10px; }
.profile-hero h3 { margin-top: 5px; font-size: 16px; }
.mini-stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; margin: 9px 0; }
.mini-stat-grid div { padding: 11px 8px; border: 1px solid var(--line); border-radius: 11px; text-align: center; }
.mini-stat-grid span, .mini-stat-grid strong { display: block; }
.mini-stat-grid span { color: var(--muted); font-size: 9px; }
.mini-stat-grid strong { margin-top: 5px; font-size: 13px; }
.machine-chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 11px 0; }
.machine-chip { min-height: 34px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: white; font-size: 10px; }
.machine-chip span { color: #c8cdd5; }
.machine-chip.is-favorite span { color: var(--gold); }
.machine-chip b { color: var(--green); }
.timeline-list { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; }
.timeline-row { display: grid; grid-template-columns: 50px minmax(0,1fr) auto; gap: 9px; padding: 10px 12px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.timeline-row:last-child { border: 0; }
.timeline-row span, .timeline-row em { color: var(--muted); font-size: 10px; font-style: normal; }
.timeline-row strong { overflow: hidden; font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }

.machine-profile-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 15px; border-radius: 14px; background: var(--gold-soft); }
.machine-profile-head h3, .machine-profile-head p { margin: 0; }
.machine-profile-head h3 { font-size: 17px; }
.machine-profile-head p { margin-top: 5px; color: var(--muted); font-size: 10px; }
.machine-profile-head > strong { color: #7a5612; font-size: 12px; white-space: nowrap; }
.subheading { margin: 18px 2px 9px; font-size: 12px; }
.number-rank-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
.number-rank-grid article { position: relative; padding: 12px 7px; border: 1px solid var(--line); border-radius: 11px; text-align: center; cursor: pointer; }
.number-rank-grid .favorite-button { position: absolute; top: 1px; right: 1px; }
.number-rank-grid strong, .number-rank-grid span { display: block; }
.number-rank-grid strong { color: var(--green); font: 800 20px Georgia, serif; }
.number-rank-grid span { margin-top: 5px; color: var(--muted); font-size: 8px; }
.rotation-strip { display: flex; gap: 7px; padding-bottom: 4px; overflow-x: auto; }
.rotation-strip button { flex: 0 0 54px; padding: 9px 5px; border: 1px solid var(--line); border-radius: 10px; background: #fafafa; }
.rotation-strip strong, .rotation-strip span { display: block; }
.rotation-strip strong { color: var(--green); font: 800 17px Georgia, serif; }
.rotation-strip span { margin-top: 4px; color: var(--muted); font-size: 8px; }

.compact-filter { width: 145px; }
.compact-filter select { height: 39px; }
.matrix-help { margin: -8px 4px 12px; color: var(--muted); font-size: 11px; }
.matrix-tools { display: grid; grid-template-columns: minmax(0,95px) auto auto; align-items: end; gap: 7px; margin: -5px 0 16px; }
.matrix-tools label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 700; }
.matrix-tools input, .matrix-tools button { height: 38px; }
.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; }
.matrix-cell.heat-2 { background: #ccecdf; }
.matrix-cell.heat-3 { background: #97d8c1; color: #0c6f55; }
.matrix-cell.heat-4 { background: var(--green); color: white; }
.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; }
.cell-popover { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cell-popover[hidden] { display: none; }
.cell-popover button { padding: 7px 9px; border: 0; border-radius: 8px; color: var(--navy); background: var(--gold); font-size: 10px; font-weight: 800; white-space: nowrap; }

.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); }
  .latest-grid, .favorite-list, .attention-list { grid-template-columns: repeat(2, 1fr); }
  .number-rank-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 480px) {
  .share-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; }
  .attention-panel { padding: 17px 15px; }
  .attention-main > div:first-child { display: block; }
  .attention-main span { display: block; margin-top: 3px; }
}
