html,
body {
  height: 100%;
  overflow: hidden;
}

:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #182230;
  --muted: #5f6b7a;
  --line: #dce3eb;
  --accent: #1f77b4;
  --accent-2: #d62728;
  --success: #16a34a;
  --soft: #edf3f8;
  --soft-2: #f8fbfd;
  --warning: #b45309;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "SF Pro Text", "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.help-open {
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 20px;
}

.sidebar-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.load-block {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.load-item {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.load-item .tool-btn {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 13px;
}

.api-warning {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(180, 83, 9, 0.28);
  background: rgba(251, 191, 36, 0.12);
  color: #92400e;
  font-size: 12px;
  line-height: 1.4;
}

.api-warning[hidden] {
  display: none;
}

#langSelect {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px 8px;
  font-size: 13px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: #c4d2e0;
  color: var(--text);
}

.filters {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
}

.filters input,
.filters select,
.filters button,
.tool-btn {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}

.tool-btn {
  width: auto;
  white-space: nowrap;
  background: var(--soft-2);
}

.tool-btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.wide-btn {
  width: 100%;
}

.source-note,
.panel-source {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-note {
  cursor: default;
}

.source-note.is-copyable {
  cursor: pointer;
}

.source-note.is-copyable:hover {
  color: var(--text);
  text-decoration: underline;
}

.panel-source {
  padding: 8px 12px 0;
}

.filters-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.events-meta {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.event-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
  flex: 1;
  min-height: 0;
}

.event-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: #fff;
  cursor: pointer;
}

.event-item:hover {
  border-color: #c4d2e0;
}

.event-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(31, 119, 180, 0.2);
}

.event-item.audit-no {
  border-color: #dc2626;
  box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.14);
}

.event-item.audit-no:hover {
  border-color: #b91c1c;
}

.event-item.audit-no.active {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.28);
}

.event-title {
  font-size: 14px;
  font-weight: 600;
}

.event-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.event-fields {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.event-field {
  min-width: 0;
}

.event-field.wide {
  grid-column: 1 / -1;
}

.event-field-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.event-field-value {
  display: block;
  font-size: 12px;
  font-weight: 600;
  word-break: break-word;
}

.badges {
  margin-top: 7px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.event-context-badges {
  margin-top: 8px;
}

.badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.team-0 {
  color: var(--accent);
}

.badge.team-1 {
  color: var(--accent-2);
}

.main {
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
  height: 100vh;
  overflow: hidden;
  min-height: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: calc(100vh - 28px);
  max-height: calc(100vh - 28px);
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.panel-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tracking-panel-tools {
  gap: 10px 12px;
}

.panel-tools select,
.panel-tools button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 6px 8px;
  font-size: 13px;
}

.video-wrap {
  padding: 10px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

video {
  width: 100%;
  max-height: 56vh;
  background: #000;
  border-radius: 10px;
}

.controls {
  margin-top: 8px;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
}

.controls button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}

.offset-control {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.offset-control input {
  width: 110px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  line-height: 1.2;
  box-shadow: none;
}

.status {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.detail-block {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tracking-detail {
  margin: 10px;
  margin-top: 0;
  flex: 1;
}

.video-wrap > .detail-block {
  flex: 1;
}

.detail-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-title {
  font-size: 13px;
  font-weight: 600;
}

.tracking-header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.team-color-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tracking-panel-tools .team-color-controls {
  align-items: center;
}

.color-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.tracking-panel-tools .color-control {
  white-space: nowrap;
}

.color-control input[type="color"] {
  width: 34px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.color-control input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.color-control input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.detail-meta {
  color: var(--muted);
  font-size: 12px;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.toggle-row input {
  margin: 0;
}

.pitch-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 0 0 auto;
}

.canvas-area {
  flex: 1;
  min-height: 360px;
  padding: 10px;
  display: flex;
  position: relative;
  align-items: flex-start;
  justify-content: flex-start;
  background: #f8fafc;
}

canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 105 / 68;
  display: block;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.player-tooltip {
  position: absolute;
  z-index: 4;
  min-width: 180px;
  max-width: 260px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(17, 24, 39, 0.92);
  color: #f8fafc;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  pointer-events: none;
}

.player-tooltip[hidden] {
  display: none;
}

.player-tooltip-title {
  font-size: 13px;
  font-weight: 700;
}

.player-tooltip-sub {
  margin-top: 2px;
  color: rgba(226, 232, 240, 0.95);
}

.player-tooltip-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
}

.player-tooltip-label {
  color: rgba(148, 163, 184, 0.95);
}

.legend {
  border-top: 1px solid var(--line);
  padding: 10px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.legend-controls {
  align-items: center;
  gap: 16px;
}

.legend strong {
  color: var(--text);
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(17, 24, 39, 0.15);
  flex: 0 0 auto;
}

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

.table-scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: #eef4f8;
  z-index: 1;
  color: var(--muted);
  font-weight: 600;
  position: relative;
}

.table-sort-btn {
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}

.table-sort-btn:hover {
  color: var(--text);
}

.table-sort-btn.active {
  color: var(--text);
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 3;
}

.col-resizer::after {
  content: "";
  position: absolute;
  top: 18%;
  bottom: 18%;
  left: 3px;
  width: 2px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.55);
}

.data-table thead th:hover .col-resizer::after {
  background: rgba(100, 116, 139, 0.9);
}

.data-table th.compact-col,
.data-table td.compact-col {
  width: 92px;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: rgba(31, 119, 180, 0.05);
}

.data-table tbody tr.observed-row {
  background: rgba(253, 224, 71, 0.18);
}

.data-table tbody tr.selected-row {
  background: rgba(31, 119, 180, 0.08);
}

.mono {
  font-variant-numeric: tabular-nums;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 11px;
  color: var(--muted);
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.4);
}

.help-overlay[hidden] {
  display: none;
}

.help-sheet {
  width: min(1040px, 100%);
  max-height: min(80vh, 920px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}

.help-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.help-header h2 {
  margin: 0;
  font-size: 20px;
}

.help-body {
  padding: 18px;
  display: grid;
  gap: 18px;
}

.help-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.help-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-alt);
  color: var(--text);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
}

.help-tab.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
}

.help-panel {
  display: grid;
  gap: 18px;
}

.help-section h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.help-section ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
}

.help-section li + li {
  margin-top: 6px;
}

.help-empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 18px;
  color: var(--muted);
  background: var(--panel-alt);
}

.dictionary-summary {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  background: var(--panel-alt);
}

.dictionary-summary p,
.dictionary-group-head p,
.dictionary-field-card p,
.dictionary-zone-note,
.dictionary-source-list {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.dictionary-group {
  display: grid;
  gap: 14px;
}

.dictionary-group-head {
  display: grid;
  gap: 6px;
}

.dictionary-group-head h3,
.dictionary-field-card h4 {
  margin: 0;
}

.dictionary-field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.dictionary-field-card,
.dictionary-code-table,
.dictionary-zone-parts {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-alt);
}

.dictionary-field-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.dictionary-field-meta {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.dictionary-field-examples {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.dictionary-field-examples span {
  color: var(--muted);
}

.dictionary-code-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dictionary-code-list code,
.dictionary-zone-part code,
.dictionary-code-row code,
.dictionary-group-head code {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 6px;
  font-size: 12px;
}

.dictionary-code-table,
.dictionary-zone-parts {
  overflow: hidden;
}

.dictionary-code-row,
.dictionary-zone-part {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr;
  gap: 12px;
  padding: 12px 14px;
  align-items: start;
}

.dictionary-code-row + .dictionary-code-row,
.dictionary-zone-part + .dictionary-zone-part {
  border-top: 1px solid var(--line);
}

.dictionary-zone-note {
  padding: 0 2px;
}

.dictionary-source-list {
  padding-left: 20px;
}

.dictionary-source-list li + li {
  margin-top: 6px;
}

@media (max-width: 1200px) {
  .app {
    grid-template-columns: 300px 1fr;
  }
}

@media (max-width: 980px) {
  html,
  body {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    min-height: 420px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    height: auto;
    overflow: visible;
  }

  .main {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .panel {
    min-height: 520px;
    height: auto;
    max-height: none;
  }

  .controls {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .offset-control {
    margin-left: 0;
  }

  .help-overlay {
    padding: 12px;
    align-items: stretch;
  }

  .help-sheet {
    max-height: none;
  }

  .dictionary-field-grid {
    grid-template-columns: 1fr;
  }

  .dictionary-code-row,
  .dictionary-zone-part {
    grid-template-columns: 1fr;
  }
}
