:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #b5442e;
  --border: #ddd;
  --cell-bg: #f4f4f4;
  --cell-active: #ffe8b3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --fg: #eee;
    --muted: #999;
    --accent: #e07a5f;
    --border: #333;
    --cell-bg: #22252a;
    --cell-active: #5a4a1e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

header h1 { margin-bottom: 0.2rem; }
.subtitle { color: var(--muted); margin-top: 0; }

#header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

#user-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
#user-box img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
#user-box button {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  background: var(--cell-bg);
  color: var(--fg);
}

#history-panel {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
#history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
#history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.history-open {
  flex: 1;
  text-align: left;
  background: var(--cell-bg);
  color: var(--fg);
}
.history-delete {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

#analyze-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

#analyze-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#analyze-form input[type="url"],
#analyze-form input[type="file"] {
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

.or-divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

button {
  cursor: pointer;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
}
button:disabled { opacity: 0.6; cursor: default; }

#status {
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--cell-bg);
}
#status.error { color: var(--accent); }
.hidden { display: none !important; }

#result-section { margin-top: 2rem; }

#summary {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

#controls {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
}
#controls label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}
#controls select {
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
}

#video-toggle-wrap { margin-bottom: 0.5rem; }
#video-toggle {
  background: var(--cell-bg);
  color: var(--fg);
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
}
#preview-video {
  width: 100%;
  max-width: 480px;
  display: block;
  margin: 0 auto 1rem;
  border-radius: 8px;
  background: black;
}

audio { width: 100%; margin-bottom: 1rem; }

#legend-wrap { margin-bottom: 1.25rem; }
#legend-wrap h3 { margin-bottom: 0.5rem; font-size: 0.95rem; color: var(--muted); }
#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}
.legend-item .chord-diagram { width: 60px; height: 72px; }
.legend-label { font-size: 0.8rem; font-weight: 600; }

#now-playing {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.chord-diagram {
  width: 90px;
  height: 108px;
  color: var(--fg);
}
.chord-diagram-fretlabel, .chord-diagram-mute, .chord-diagram-empty {
  font-size: 10px;
  fill: var(--fg);
}
#current-chord-name {
  font-size: 2.5rem;
  font-weight: 700;
}

#grid-wrap {
  max-height: 70vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
}

#grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 2px;
  row-gap: 10px;
}

.beat-cell {
  width: 44px;
  height: 56px;
  background: var(--cell-bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
}
.beat-cell:hover { filter: brightness(1.08); }
.beat-cell.bar-start {
  border-left: 2px solid var(--border);
  margin-left: 4px;
}
.beat-cell.active {
  background: var(--cell-active);
  outline: 2px solid var(--accent);
}
.chord-label { font-weight: 600; }
