:root {
  color-scheme: dark;
  --ink: #f3f6fb;
  --muted: #9aa7b8;
  --line: #2a3442;
  --panel: #151b23;
  --soft: #1b2430;
  --accent: #5ba7ff;
  --accent-strong: #8fc2ff;
  --gold: #f5c400;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #151b23;
  color: var(--ink);
  font-family:
    Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic UI",
    sans-serif;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 18px 14px;
}

.app-header,
.app-shell {
  width: 100%;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  min-width: min(430px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary-strip,
.import-panel {
  display: none;
}

.summary-strip div {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.summary-strip div:last-child {
  border-right: 0;
}

.summary-strip span {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
}

.summary-strip small,
.metric-row small,
.detail-panel small {
  color: var(--muted);
  font-size: 0.78rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(230px, 270px) minmax(0, 1fr);
  gap: 14px;
  padding: 0 18px 18px;
}

.controls,
.workspace,
.detail-panel,
.metric-row article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: none;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 13px;
  align-self: start;
  padding: 18px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  overflow-x: hidden;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.checkbox-field input {
  width: 17px;
  min-height: 17px;
  margin: 0;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segment {
  min-height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.date-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.import-panel {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.panel-heading,
.toolbar,
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h2 {
  font-size: 1rem;
}

.panel-heading button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

textarea {
  min-height: 104px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.82rem;
}

.controls > *,
.workspace > * {
  min-width: 0;
}

summary {
  color: var(--accent-strong);
  font-weight: 800;
  cursor: pointer;
}

.file-button,
.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 7px;
  font-weight: 800;
}

.file-button {
  border: 1px dashed var(--accent);
  background: rgba(91, 167, 255, 0.08);
  color: var(--accent-strong);
}

.file-button input {
  display: none;
}

.primary-button {
  border: 0;
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent-strong);
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.toolbar {
  margin-bottom: 16px;
}

.toolbar h2 {
  font-size: 1.35rem;
}

#viewSubtitle,
#detailMeta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.compact {
  min-width: 180px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.metric-row article {
  padding: 15px;
  box-shadow: none;
}

.metric-row strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.1rem, 2vw, 1.55rem);
  line-height: 1.2;
}

.table-wrap {
  position: relative;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  background: var(--panel);
  table-layout: auto;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.78rem;
  user-select: none;
}

th[data-sort] {
  cursor: pointer;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3) {
  text-align: left;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: rgba(91, 167, 255, 0.1);
}

.player-cell {
  display: grid;
  gap: 2px;
}

.player-cell small {
  color: var(--muted);
}

.positive {
  color: var(--accent-strong);
  font-weight: 800;
}

.warning {
  color: var(--gold);
  font-weight: 800;
}

.empty-state {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.mobile-results {
  display: none;
}

.mobile-player-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 12px;
  text-align: left;
}

.mobile-player-card.selected {
  border-color: var(--accent);
  background: rgba(91, 167, 255, 0.1);
}

.mobile-player-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.mobile-player-card__head strong {
  display: block;
  font-size: 1rem;
}

.mobile-player-card__head small,
.mobile-stat-grid small {
  color: var(--muted);
  font-size: 0.76rem;
}

.mobile-player-card__pa {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.mobile-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.mobile-stat-grid span {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.mobile-stat-grid strong {
  font-size: 0.95rem;
}

.detail-panel {
  margin-top: 16px;
  padding: 18px;
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stat-pills span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  font-weight: 800;
}

#trendChart {
  width: 100%;
  height: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
  margin-top: 14px;
}

#recentGames {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding-left: 20px;
}

#recentGames li {
  line-height: 1.45;
}

.breakdown {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

@media (max-width: 980px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  body {
    background: #151b23;
  }

  .app-header {
    gap: 14px;
    padding: 18px 12px 12px;
  }

  h1 {
    font-size: 1.8rem;
  }

  .app-shell {
    gap: 12px;
    padding: 0 10px 24px;
  }

  .controls,
  .workspace,
  .detail-panel {
    border-radius: 8px;
    box-shadow: none;
  }

  .controls,
  .workspace {
    padding: 12px;
  }

  .summary-strip,
  .metric-row,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    min-width: 0;
  }

  .summary-strip div {
    padding: 10px 12px;
  }

  .metric-row {
    gap: 8px;
  }

  .metric-row article {
    padding: 12px;
  }

  .toolbar,
  .panel-heading,
  .detail-head {
    align-items: stretch;
    flex-direction: column;
  }

  .compact {
    min-width: 0;
  }

  .date-grid,
  .button-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    display: none;
  }

  .mobile-results {
    display: grid;
    gap: 10px;
  }

  .stat-pills {
    justify-content: flex-start;
  }

  #trendChart {
    min-height: 180px;
  }

  #recentGames {
    padding-left: 18px;
  }
}

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