:root {
  color-scheme: dark;
  --bg: #06111f;
  --panel: rgba(8, 26, 48, .88);
  --line: rgba(133, 201, 238, .28);
  --line-soft: rgba(133, 201, 238, .14);
  --text: #f7fbff;
  --muted: #a8bfd3;
  --accent: #22d3ee;
  --green: #22c55e;
  --gold: #e5b853;
  --danger: #ef4444;
  --shadow: 0 22px 64px rgba(0, 0, 0, .32);
  font-family: "Noto Sans JP", "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 0%, rgba(34, 211, 238, .16), transparent 28%),
    linear-gradient(180deg, #06111f 0%, #071a2d 44%, #04101d 100%);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
a { color: #9ee8ff; text-decoration: none; }
code { font-family: Consolas, "SFMono-Regular", monospace; font-size: 12px; color: #c9e9ff; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: rgba(4, 14, 28, .9);
  backdrop-filter: blur(16px);
}
.app-header h1, .app-header p, .panel h2 { margin: 0; }
.app-header h1 { font-size: clamp(26px, 3.8vw, 42px); line-height: 1.04; }
.app-header p:last-child { margin-top: 6px; color: var(--muted); font-size: 13px; }

.eyebrow {
  margin: 0 0 4px;
  color: #89a8bf;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.home-link, .primary-btn, .ghost-btn {
  min-height: 34px;
  border: 1px solid rgba(168, 223, 255, .24);
  border-radius: 999px;
  padding: 7px 14px;
  background: rgba(11, 34, 57, .82);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn { border-color: rgba(103, 232, 249, .42); background: linear-gradient(135deg, #1fc7e7, #116f9d); }
.ghost-btn.small { min-height: 26px; padding: 3px 10px; font-size: 11px; margin-left: 8px; vertical-align: middle; }
.ghost-btn.danger { color: #fecaca; border-color: rgba(239, 68, 68, .35); }
.link-btn { border: 0; background: none; color: #9ee8ff; font-size: 12px; cursor: pointer; text-decoration: underline; }

.app-shell {
  width: min(1440px, calc(100% - 24px));
  margin: 14px auto 28px;
  display: grid;
  gap: 14px;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: linear-gradient(155deg, var(--panel), rgba(4, 14, 28, .9));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--green));
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin: 4px 0 12px;
  flex-wrap: wrap;
}
.panel h2 { font-size: 18px; }
.sub-head { margin: 22px 0 8px; font-size: 15px; }

.field { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field input, .field select, .input-table input, .input-table select {
  min-height: 34px;
  border: 1px solid rgba(168, 223, 255, .22);
  border-radius: 8px;
  padding: 6px 9px;
  background: rgba(3, 13, 26, .78);
  color: var(--text);
}
.field.wide { grid-column: span 2; }

.load-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.load-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.base-field input { min-width: 160px; }
.load-status { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.load-status.ok { color: #86efac; }
.load-status.warn { color: var(--gold); }
.load-status.error { color: #fca5a5; }
.fallback-box { margin-top: 10px; display: grid; gap: 6px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }
.fallback-box small { color: var(--muted); }
.howto { margin-top: 10px; font-size: 12px; color: var(--muted); }
.howto summary { cursor: pointer; font-weight: 700; }
.howto ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 4px; }

.data-only { display: none; }
body.has-data .data-only { display: grid; gap: 14px; }

.hero { display: grid; grid-template-columns: 1.6fr repeat(3, 1fr); gap: 12px; }
.hero > article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: linear-gradient(155deg, rgba(8, 37, 62, .92), rgba(4, 14, 28, .92));
  display: grid;
  gap: 4px;
  align-content: start;
}
.hero-main { border-color: rgba(103, 232, 249, .5) !important; }
.hero-label { color: var(--muted); font-size: 13px; font-weight: 800; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.hero-label small { font-weight: 600; }
.hero-main strong { font-size: clamp(34px, 5vw, 56px); line-height: 1.05; letter-spacing: -.01em; }
.hero-qty { font-size: 18px; font-weight: 800; color: #9ee8ff; }
.hero-sub span { color: var(--muted); font-size: 12px; font-weight: 800; }
.hero-sub strong { font-size: 24px; }
.hero-sub .small-strong { font-size: 15px; line-height: 1.4; }
.hero-sub small { color: var(--muted); font-size: 12px; }
.hero-sub.ok strong { color: #86efac; }
.hero-sub.warn strong { color: var(--gold); }
.hero-notes { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; display: grid; gap: 2px; }

.status-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.status-tile { border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; background: rgba(6, 22, 40, .8); display: grid; gap: 2px; }
.status-tile span { font-size: 12px; color: var(--muted); font-weight: 800; }
.status-tile strong { font-size: 20px; }
.status-tile small { font-size: 12px; color: var(--muted); }
.tile-hand { border-left: 4px solid #60a5fa; }
.tile-vault { border-left: 4px solid var(--accent); }
.tile-grading { border-left: 4px solid var(--gold); }
.tile-unknown { border-left: 4px solid #f87171; }
.tile-sold { border-left: 4px solid var(--green); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn {
  border: 1px solid rgba(168, 223, 255, .2);
  border-radius: 999px;
  padding: 7px 14px;
  background: rgba(8, 26, 48, .8);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.tab-btn.active { color: var(--text); border-color: rgba(103, 232, 249, .5); background: linear-gradient(135deg, rgba(31, 199, 231, .35), rgba(17, 111, 157, .5)); }
.tab-count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: rgba(239, 68, 68, .7); color: #fff; font-size: 11px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
body:not(.has-data) .manual-panel { display: none !important; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
.data-table thead th { position: sticky; top: 0; background: rgba(5, 20, 38, .96); color: var(--muted); font-size: 12px; white-space: nowrap; }
.data-table tbody tr:hover { background: rgba(34, 211, 238, .05); }
.data-table tfoot th, .data-table tfoot td { border-top: 2px solid var(--line); background: rgba(5, 20, 38, .7); }
.data-table .num { text-align: right; white-space: nowrap; }
.data-table small, .data-table em { display: block; color: var(--muted); font-size: 11px; font-style: normal; margin-top: 2px; }
.data-table td.num em { color: var(--gold); }
.data-table th[scope=row] small { font-weight: 500; }
.data-table td.total b { color: #9ee8ff; }
.data-table td.basis { min-width: 180px; }
.data-table tr.excluded { opacity: .45; }
.data-table .empty { text-align: center; color: var(--muted); padding: 18px; }
.muted { color: var(--muted); }
.warn-text { color: var(--gold) !important; }
.ok-text { color: #86efac; }
.neg { color: #fca5a5; }
.pos { color: #86efac; }

.pill { display: inline-block; white-space: nowrap; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; border: 1px solid var(--line); }
.pill.state-done { color: #86efac; border-color: rgba(34, 197, 94, .45); }
.pill.state-wait { color: var(--gold); border-color: rgba(229, 184, 83, .45); }
.pill.st-hand { color: #93c5fd; }
.pill.st-vault { color: var(--accent); }
.pill.st-grading { color: var(--gold); }
.pill.st-unknown { color: #fca5a5; }
.pill.st-sold { color: #86efac; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip, .count-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; color: var(--muted); }

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

.issue-list { display: grid; gap: 8px; }
.issue { border: 1px solid var(--line-soft); border-left-width: 4px; border-radius: 10px; padding: 10px 12px; background: rgba(6, 22, 40, .8); }
.issue header { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.issue .level { font-weight: 800; }
.issue h3 { margin: 4px 0 2px; font-size: 14px; }
.issue p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.issue .action { color: var(--text); }
.issue .action b { display: inline-block; margin-right: 8px; padding: 0 6px; border-radius: 4px; background: rgba(34, 211, 238, .2); color: #9ee8ff; font-size: 11px; }
.issue-error { border-left-color: var(--danger); }
.issue-error .level { color: #fca5a5; }
.issue-warn { border-left-color: var(--gold); }
.issue-warn .level { color: var(--gold); }
.issue-info { border-left-color: #64748b; }

.filter-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.more-btn { margin-top: 10px; }

.source-summary { margin: 0 0 12px; padding-left: 18px; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }

.manual-actions { display: flex; gap: 8px; }
.manual-state { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.input-table input, .input-table select { width: 100%; min-width: 90px; }
.input-table td { padding: 6px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--text); }
.check input { width: auto; min-width: 0; min-height: 0; }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .hero-main { grid-column: span 2; }
  .hero > article:last-child { grid-column: span 2; }
  .status-tiles { grid-template-columns: repeat(3, 1fr); }
  .filter-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .app-header { align-items: flex-start; }
  .app-header p:last-child { display: none; }
  .hero { grid-template-columns: 1fr; }
  .hero-main, .hero > article:last-child { grid-column: auto; }
  .status-tiles { grid-template-columns: 1fr 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
}

/* カード台帳へのリンク（10/6） */
.header-links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
