* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: #f4f5f7;
  color: #222;
}
header { padding: 12px 16px; background: #1f6f4a; color: #fff; }
header h1 { margin: 0; font-size: 18px; }
#storageWarn { display: none; padding: 10px 16px; background: #fff3cd; color: #7a5a00; font-size: 13px; }
main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}
/* PC：動画の横にコート図 */
@media (min-width: 900px) {
  main { grid-template-columns: 2fr 1fr; }
}
.card { background: #fff; border-radius: 12px; padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card h2 { margin: 0 0 8px; font-size: 15px; }
.file-btn {
  display: inline-block; padding: 10px 16px; border-radius: 8px;
  background: #1f6f4a; color: #fff; cursor: pointer; font-size: 15px;
}
.file-btn input { display: none; }
#fileName { margin-left: 8px; font-size: 13px; color: #666; }
.match-row { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 14px; color: #555; }
.add-video { display: inline-block; margin-top: 8px; font-size: 13px; color: #1f6f4a; cursor: pointer; }
.add-video input { display: none; }
.add-video[hidden] { display: none; }
/* この試合の動画の一覧 */
.video-list { margin-top: 8px; font-size: 13px; }
.video-list[hidden] { display: none; }
.video-list summary { cursor: pointer; color: #555; padding: 4px 0; }
.video-list ul { list-style: none; margin: 4px 0 0; padding: 0; }
.video-list li { display: flex; align-items: center; gap: 8px; padding: 2px 0 2px 4px; border-bottom: 1px solid #eee; }
.video-no { color: #888; min-width: 3.5em; }
.video-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-status { font-size: 11px; color: #1f6f4a; }
.video-status.off { color: #aaa; }
/* スマホでも押しやすいよう、×は 44px 四方 */
.video-del { width: 44px; height: 44px; flex-shrink: 0; border: none; border-radius: 8px;
  background: none; color: #999; font-size: 18px; cursor: pointer; }
.video-del:active { background: #fbeaea; color: #d9443b; }
.backup-row { display: flex; gap: 8px; margin-top: 8px; }
.backup-row button, .backup-row label { flex: 1; padding: 8px 0; text-align: center; font-size: 13px;
  border: 1px solid #ccc; border-radius: 8px; background: #fff; color: #333; cursor: pointer; }
.backup-row input { display: none; }
.match-row select { flex: 1; min-width: 0; padding: 8px; font-size: 14px; border: 1px solid #ccc; border-radius: 8px; background: #fff; }
video { width: 100%; margin-top: 12px; background: #000; border-radius: 8px; display: none; }
.placeholder { margin-top: 12px; padding: 40px 12px; text-align: center; color: #888; border: 2px dashed #ccc; border-radius: 8px; }
/* 両面コートは縦に長いので、画面の高さに収まるように制限する */
#court { width: 100%; max-width: 360px; height: 64vh; display: block; margin: 0 auto; touch-action: manipulation; }
/* 動画の切り替え */
.clip-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.clip-nav[hidden] { display: none; }
.clip-nav button { flex: 1; padding: 10px 0; border: 1px solid #c9d8cf; border-radius: 10px;
  background: #fff; color: #1f6f4a; font-size: 14px; font-weight: bold; cursor: pointer; }
.clip-nav button:disabled { color: #bbb; border-color: #e3e3e3; cursor: default; }
.clip-nav span { min-width: 6.5em; text-align: center; font-size: 13px; color: #555; font-variant-numeric: tabular-nums; }
.controls { display: flex; gap: 8px; }
.controls button {
  flex: 1; padding: 12px 0; border: none; border-radius: 10px;
  background: #e3ece7; color: #1f6f4a; font-size: 15px; font-weight: bold; cursor: pointer;
}
.controls #playBtn { flex: 1.4; background: #1f6f4a; color: #fff; }
.now { text-align: center; font-size: 13px; color: #666; margin: 6px 0 8px; font-variant-numeric: tabular-nums; }
.hint { font-size: 12px; color: #777; text-align: center; margin: 6px 0 0; }

/* 記録一覧 */
.list-card { grid-column: 1 / -1; }

/* タブ */
.tabs { display: flex; gap: 4px; background: #eef1f0; border-radius: 10px; padding: 4px; margin-bottom: 10px; }
.tab-btn { flex: 1; padding: 10px 0; border: none; border-radius: 8px; background: none;
  font-size: 15px; font-weight: bold; color: #666; cursor: pointer; }
.tab-btn.active { background: #fff; color: #1f6f4a; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.tab-note { margin: 0 0 4px; font-size: 12px; color: #888; }
#records { list-style: none; margin: 0; padding: 0; }
#records li {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 4px; border-bottom: 1px solid #eee; cursor: pointer;
}
#records li:hover { background: #f7faf8; }
.clip-no { display: block; font-size: 11px; font-weight: normal; color: #888; }
#records li.no-video { opacity: .55; }
.time { font-variant-numeric: tabular-nums; font-weight: bold; min-width: 52px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; color: #fff; }
.tag.point { background: #2a7de1; }
.tag.miss { background: #d9443b; }

/* 集計 */
.stats-head { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.stats-head select { padding: 6px 8px; font-size: 14px; border: 1px solid #ccc; border-radius: 8px; background: #fff; }
.stats-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stats-tile { background: #f4f5f7; border-radius: 10px; padding: 10px 12px; }
.stats-tile-label { font-size: 13px; color: #555; }
.stats-tile-label::before { content: '●'; margin-right: 4px; }
.stats-tile-label.point::before { color: #2a7de1; }
.stats-tile-label.miss::before { color: #d9443b; }
.stats-tile-value { font-size: 28px; font-weight: bold; font-variant-numeric: tabular-nums; }
.stats-section { border-top: 1px solid #eee; padding: 10px 0 4px; }
.stats-section h3 { margin: 0 0 8px; font-size: 14px; }
.stats-group { margin-bottom: 10px; }
.stats-group-label { font-size: 12px; color: #777; margin-bottom: 4px; }
.stats-row { display: grid; grid-template-columns: 8.5em 1fr 2em; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.stats-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-track { height: 10px; }
.stats-bar { display: block; height: 100%; min-width: 4px; border-radius: 0 4px 4px 0; }
.stats-bar.point { background: #2a7de1; }
.stats-bar.miss { background: #d9443b; }
.stats-count { text-align: right; font-variant-numeric: tabular-nums; color: #333; }
.rec-text { flex: 1; font-size: 14px; }
.del-btn { border: none; background: none; color: #999; font-size: 18px; cursor: pointer; padding: 4px 8px; }
.empty { color: #888; font-size: 14px; padding: 8px 4px; }

/* 記録入力ダイアログ */
dialog { border: none; border-radius: 14px; padding: 14px 12px; width: min(96vw, 380px); max-width: 96vw; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 4px; font-size: 16px; }
.dlg-time { font-size: 13px; color: #666; margin-bottom: 10px; }
.group { margin-bottom: 10px; }
.group-label { font-size: 13px; color: #555; margin-bottom: 5px; }
.group-label small { font-size: 11px; color: #999; margin-left: 4px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
/* 改行用。高さ0の行ができて行間が倍になるのを、マイナスの余白で打ち消す */
.choices .break { flex-basis: 100%; height: 0; margin-top: -6px; }
.choices button {
  padding: 8px 10px; border: 1px solid #ccc; border-radius: 8px;
  background: #fff; font-size: 14px; cursor: pointer;
}
.choices button.selected { background: #1f6f4a; border-color: #1f6f4a; color: #fff; }
/* 項目が多くても保存ボタンが常に見えるよう、入力画面の下に固定する */
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px;
  position: sticky; bottom: -14px; background: #fff; padding: 8px 0 14px; }
.dlg-actions button { padding: 10px 16px; border-radius: 8px; border: none; font-size: 15px; cursor: pointer; }
#cancelBtn { background: #eee; }
#saveBtn { background: #1f6f4a; color: #fff; }
#saveBtn.incomplete { background: #aaa; }
#dlgError { color: #d9443b; font-size: 13px; margin: 0 0 4px; min-height: 1em; }
