:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1f2522;
  --muted: #66706a;
  --line: #dfe3dd;
  --accent: #c8178a;      /* コース色（マゼンタ） */
  --orange: #f47a00;
  --primary: #1f6f4a;
  --primary-ink: #ffffff;
  --track: #e0362c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo {
  width: 22px; height: 22px;
  background: linear-gradient(135deg, var(--orange) 50%, #fff 50%);
  border: 1px solid #ccc;
}
.file-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  user-select: none;
}
.btn:hover { background: #f0f3ef; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.active { outline: 2px solid var(--orange); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.small-btn { font-size: 12px; padding: 4px 10px; margin-top: 8px; }

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}
.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: #e9ebe6;
  touch-action: none;
}
#canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#canvas.crosshair { cursor: crosshair; }
#canvas.dragging { cursor: grabbing; }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  pointer-events: none;
}
.empty-title { font-size: 18px; color: var(--ink); font-weight: 600; }
.stage.dragover { outline: 3px dashed var(--orange); outline-offset: -8px; }

.hint {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 37, 34, .88);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  max-width: calc(100% - 20px);
  text-align: center;
  pointer-events: none;
}

.zoom-buttons {
  position: absolute;
  right: 10px; bottom: 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.zoom-buttons button {
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 17px;
  cursor: pointer;
}

.panel {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1;
  padding: 10px 4px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}
.tabs button.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--orange); }
.tab-body { padding: 12px 14px; overflow: auto; flex: 1; }
.note { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.small { font-size: 12px; color: var(--muted); }
.status { margin: 0 0 8px; font-size: 13px; }
.status:empty { display: none; }
.status.error { color: #b42318; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
fieldset.row { border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; flex-direction: column; align-items: flex-start; }
fieldset legend { font-size: 12px; color: var(--muted); }
input[type="number"] { width: 64px; padding: 3px 6px; font: inherit; }

.pair-list, .control-list { list-style: none; padding: 0; margin: 0 0 10px; }
.pair-list li, .control-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
}
.pair-list li .grow, .control-list li .grow { flex: 1; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  padding: 1px 7px;
  font: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: #f0f3ef; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 22px; padding: 0 5px;
  border-radius: 11px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
}
.badge.pair { background: #2d6cdf; }

.tool-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.tool-buttons button {
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.tool-buttons button.active { border-color: var(--accent); background: #fbeaf5; color: var(--accent); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table.splits { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.splits th, .splits td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.splits th:first-child, .splits td:first-child { text-align: left; }
.splits th { font-size: 11px; color: var(--muted); font-weight: 500; }
.splits tbody tr { cursor: pointer; }
.splits tbody tr:hover { background: #f6f8f5; }
.splits tbody tr.selected { background: #fbeaf5; }
.splits tr.total td { font-weight: 600; cursor: default; }
.warn { color: #b54708; }
.manual { color: #2d6cdf; }

.player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.player .play {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.player input[type="range"] { flex: 1; min-width: 160px; accent-color: var(--track); }
.player .time { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; min-width: 78px; }
.player .time #raceTime { font-size: 18px; font-weight: 600; }
.player .clock { font-size: 11px; color: var(--muted); }
.player label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.player select { font: inherit; padding: 2px 4px; }
.player.disabled { opacity: .5; pointer-events: none; }

.footer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 6px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

@media (max-width: 820px) {
  body { height: auto; min-height: 100%; }
  .layout { flex-direction: column; }
  .stage { height: 62vh; flex: none; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); }
  .player { position: sticky; bottom: 0; z-index: 2; }
}
