:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: #d2d2d7;
  --blue: #0071e3;
}

* { box-sizing: border-box; }

html, body, h1, h2, p, ul, li { margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Inter, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ranges button:focus-visible,
.status button:focus-visible,
.poke:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

#app { padding: 28px 36px 48px; }

.top-nav {
  max-width: 1180px;
  margin: 0 auto 14px;
}

.top-nav .back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 500;
  color: var(--blue);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  padding: 4px 2px;
}

.top-nav .back:hover { text-decoration: underline; }
.top-nav .back:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Portfolio */

.top-nav, header, .status, .stage, .note {
  max-width: 1180px;
  margin-left: auto;
  margin-right: auto;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

header h1 {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

header .total {
  font-size: 15px;
  color: var(--muted);
  font-weight: 500;
}

header .total strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status {
  font-size: 14px;
  color: var(--muted);
  padding: 8px 0 12px;
}

.status button {
  appearance: none;
  margin-left: 8px;
  border: 0;
  background: #e8e8ed;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  border-radius: 980px;
  padding: 6px 12px;
  cursor: pointer;
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.grid-panel, .chart-panel {
  background: var(--panel);
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.finder {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.finder input {
  flex: 1;
  min-width: 0;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: var(--bg);
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
}

.finder input::placeholder { color: var(--muted); }

.finder input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.28);
}

.search-count {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px 14px;
}

.slab {
  aspect-ratio: 2 / 3.15;
  border-radius: 10px;
  background: linear-gradient(160deg, #e8e8ed 0%, #f0f0f2 45%, #dedee3 100%);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}

.slab::before {
  content: "";
  position: absolute;
  left: 14%;
  top: 16%;
  width: 72%;
  height: 58%;
  border-radius: 4px;
  background: linear-gradient(135deg, #c7c7cc 0%, #a1a1a6 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.slab img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  z-index: 1;
}

.slab.has-photo img { opacity: 1; }

.slab.has-photo::before { display: none; }

.slab .grade {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(210, 210, 215, 0.95);
  border-radius: 4px;
  padding: 2px 6px;
  line-height: 1.3;
}

.cap {
  margin: 8px 2px 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.poke {
  display: block;
  width: 100%;
  margin: 1px 0 0;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.poke:hover { color: var(--text); }

.grid-empty {
  margin: 8px 0 4px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  padding: 28px 8px;
  text-align: center;
}

.chart-panel {
  position: sticky;
  top: 20px;
  align-self: start;
  display: flex;
  flex-direction: column;
  height: min(760px, calc(100vh - 96px));
  min-height: 460px;
}

.chart-panel h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.chart-panel .value {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.chart-panel .delta {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 16px;
  min-height: 1.2em;
}

.ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.ranges button {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 980px;
  cursor: pointer;
}

.ranges button:hover { background: #f0f0f2; }

.ranges button.on {
  background: #e8e8ed;
  color: var(--text);
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
}

svg.chart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 12px;
}

.tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--text);
  color: #fff;
  font-size: 12px;
  line-height: 1.3;
  padding: 6px 8px;
  border-radius: 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.axis {
  position: relative;
  height: 18px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.axis span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.axis span.is-start { transform: none; }

.axis span.is-end { transform: translateX(-100%); }

.note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 860px) {
  #app { padding: 20px 16px 36px; }

  .stage { grid-template-columns: 1fr; }

  .grid-panel, .chart-panel { padding: 14px; }

  .chart-panel {
    position: static;
    height: auto;
    min-height: 0;
  }

  .chart-wrap {
    height: 240px;
    flex: none;
  }

  .chart-panel .value { font-size: 28px; }

  .grid { gap: 14px 10px; }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .slab img { transition: none; }
}
