/* Mobile-first, golf course inspired */
:root {
  --bg: #f5f7f5;
  --card: #ffffff;
  --primary: #1f7a1f;
  --primary-dark: #155515;
  --accent: #f0c040;
  --text: #222;
  --muted: #777;
  --danger: #c0392b;
  --ok: #2ecc71;
  --watch: #f39c12;
  --ng: #e74c3c;
  --border: #e0e0e0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 1.3em;
  font-weight: 600;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

h2 {
  margin: 24px 0 12px;
  font-size: 1.15em;
  border-left: 4px solid var(--primary);
  padding-left: 10px;
}

h3 {
  margin: 0 0 10px;
  font-size: 1em;
  color: #444;
}

.view { display: none; }
.view.active { display: block; }

.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.hint { font-size: 0.85em; color: var(--muted); margin-top: 8px; }

.upload-card {
  background: var(--card);
  padding: 24px 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  text-align: center;
  margin-bottom: 8px;
}

.btn {
  display: inline-block;
  padding: 14px 24px;
  border-radius: 10px;
  font-size: 1em;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  border: none;
  transition: background 0.2s, transform 0.1s;
  width: 100%;
  max-width: 320px;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
  background: var(--accent);
  color: #333;
}

.btn-back {
  background: transparent;
  color: var(--primary);
  text-align: left;
  padding: 8px 0;
  width: auto;
  font-weight: normal;
}

.card {
  background: var(--card);
  padding: 16px;
  border-radius: 10px;
  margin: 12px 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.job-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job-item {
  background: var(--card);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.job-item:active { background: #fafafa; }

.job-item .info { flex: 1; min-width: 0; }
.job-item .info .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.job-item .info .meta { font-size: 0.85em; color: var(--muted); }

.status-badge {
  font-size: 0.75em;
  padding: 3px 10px;
  border-radius: 12px;
  color: white;
  margin-left: 10px;
  white-space: nowrap;
}
.status-queued { background: #999; }
.status-processing { background: var(--accent); color: #333; }
.status-done { background: var(--ok); }
.status-error { background: var(--danger); }

.progress-bar {
  width: 100%;
  height: 12px;
  background: #e8e8e8;
  border-radius: 6px;
  overflow: hidden;
  margin: 16px 0 8px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--primary);
  transition: width 0.2s;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e0e0e0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 24px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.advise {
  white-space: pre-wrap;
  font-size: 0.95em;
  background: #fff8e1;
  padding: 14px;
  border-radius: 8px;
  border-left: 4px solid var(--accent);
}
.advise h3, .advise strong { color: var(--text); }

.tag-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.92em;
}
.tag-row:last-child { border-bottom: none; }

.tag-bar {
  display: inline-flex;
  width: 140px;
  height: 16px;
  border: 1px solid #ddd;
  border-radius: 3px;
  overflow: hidden;
  margin-left: 8px;
  vertical-align: middle;
}
.tag-bar > div {
  height: 100%;
  display: inline-block;
  text-align: center;
  color: white;
  font-size: 0.75em;
  line-height: 16px;
}
.bar-ok { background: var(--ok); }
.bar-watch { background: var(--watch); }
.bar-ng { background: var(--ng); }

.metric-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.92em;
}
.metric-row .label { color: var(--muted); }
.metric-row .value { font-family: monospace; font-weight: 600; }

video {
  width: 100%;
  border-radius: 8px;
  background: #000;
}

.error {
  background: #ffe5e5;
  color: var(--danger);
  padding: 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 0.85em;
  font-family: monospace;
  overflow-x: auto;
}

/* ============ Improvement cards (改善TOP3) ============ */
.improvement-card {
  border-left: 4px solid var(--accent);
  background: #fffdf5;
}
.improvement-card h3 {
  margin: 0 0 6px;
  font-size: 1.05em;
}
.imp-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.imp-badge {
  font-size: 0.78em;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}
.imp-badge.imp-ng    { background: var(--ng);    color: white; }
.imp-badge.imp-watch { background: var(--watch); color: white; }

.video-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.video-link {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  align-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.video-link:active {
  background: #fafafa;
  border-color: var(--primary);
}
.video-icon {
  grid-row: span 2;
  background: #c4302b;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85em;
}
.video-title {
  font-weight: 600;
  font-size: 0.92em;
  line-height: 1.35;
}
.video-note {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.82em;
  line-height: 1.3;
}

/* ============ Swing cards ============ */
.swing-card {
  border-left: 4px solid var(--primary);
}
.swing-card h3 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.frame-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 12px 0;
}
.frame-thumb {
  margin: 0;
  position: relative;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 9 / 16;
}
.frame-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.frame-thumb figcaption {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.65);
  color: white;
  padding: 3px 6px;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.frame-thumb .phase-name {
  font-size: 0.72em;
  font-weight: 600;
}
.frame-thumb .phase-sub {
  font-size: 0.62em;
  opacity: 0.85;
}

details {
  margin-top: 10px;
  padding: 8px 10px;
  background: #f9f9f9;
  border-radius: 6px;
}
details > summary {
  cursor: pointer;
  font-size: 0.92em;
  font-weight: 600;
  color: #444;
  list-style: none;
  padding: 4px 0;
}
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }

.trajectory-img {
  width: 100%;
  max-width: 320px;
  display: block;
  margin: 8px auto 0;
  border-radius: 4px;
}

/* ============ Gauges ============ */
.gauges {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}
.gauge {
  font-size: 0.9em;
}
.gauge-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.gauge-value {
  font-family: monospace;
  font-weight: 700;
}
.gauge-track {
  position: relative;
  height: 12px;
  background: #eee;
  border-radius: 6px;
  overflow: hidden;
}
.gauge-ideal {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(46, 204, 113, 0.3);
  border-left: 2px solid rgba(46, 204, 113, 0.6);
  border-right: 2px solid rgba(46, 204, 113, 0.6);
}
.gauge-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}
.gauge-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.72em;
  color: var(--muted);
  margin-top: 4px;
}
