*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { min-height: 100%; overflow-x: hidden; overflow-y: auto; }
body { min-height: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e; color: #e0e0e0;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
}

.view-startup #practice-view { display: none; }
.view-practice #startup-view { display: none; }

#startup-view {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 32px; max-width: 480px; width: 100%;
}
#startup-view h1 { font-size: 1.8em; font-weight: 600; color: #e8b430; text-align: center; }
.btn {
  padding: 12px 28px; border: none; border-radius: 8px; font-size: 1em;
  cursor: pointer; font-weight: 500; transition: background 0.15s, opacity 0.15s;
  background: #2d2d50; color: #e0e0e0; text-align: center;
}
.btn:hover { background: #3d3d66; }
.btn:active { background: #4a4a78; }
.btn.primary { background: #e8b430; color: #1a1a2e; }
.btn.primary:hover { background: #f0c040; }
.btn.primary:active { background: #d4a020; }
.btn.danger { background: #c0392b; color: #fff; }
.btn.danger:hover { background: #e74c3c; }
#resume-btn { display: none; width: 100%; }
#folder-status { font-size: 0.9em; color: #888; }
/* ── Folder Browser ─────────────────────────────── */
#breadcrumb {
  display: none;
  width: 100%;
  font-size: 0.82em;
  color: #888;
  padding: 4px 2px;
  overflow-wrap: break-word;
}
#breadcrumb.visible { display: block; }
.bc-seg {
  cursor: pointer;
  color: #aaa;
  transition: color 0.15s;
}
.bc-seg:hover { color: #e8b430; }
.bc-sep { color: #555; margin: 0 4px; }
.bc-current { color: #e0e0e0; cursor: default; }

#folder-browser {
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
#folder-browser.visible { display: flex; }

.fb-item {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  font-size: 0.95em;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  background: #2d2d50;
  color: #e0e0e0;
}
.fb-item:hover { background: #3d3d66; }
.fb-item.fb-dir::before { content: '▶  '; font-size: 0.8em; color: #e8b430; }
.fb-item.fb-set.selected { background: #e8b430; color: #1a1a2e; }
.fb-empty {
  font-size: 0.85em;
  color: #555;
  text-align: center;
  padding: 8px 0;
}
#start-btn { display: none; width: 100%; }
#startup-error { color: #ff6b6b; font-size: 0.85em; text-align: left; display: none; user-select: text; width: 100%; }
#startup-error ul { padding-left: 1.2em; margin-top: 4px; }
#spinner { display: none; width: 24px; height: 24px; border: 3px solid #2d2d50;
  border-top-color: #e8b430; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mode Tabs ─────────────────────────────────────── */
#mode-tabs {
  display: flex; width: 100%; border-radius: 8px; overflow: hidden;
  border: 2px solid #2d2d50;
}
.mode-tab-btn {
  flex: 1; padding: 10px; border: none; cursor: pointer; font-size: 0.95em;
  font-weight: 500; background: #2d2d50; color: #aaa;
  transition: background 0.15s, color 0.15s;
}
.mode-tab-btn.active { background: #e8b430; color: #1a1a2e; }
.mode-tab-btn:first-child { border-right: 1px solid #1a1a2e; }

#local-tab, #bunny-tab {
  display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%;
}
#bunny-tab { display: none; }

/* ── Sync UI ───────────────────────────────────────── */
#select-folder-btn,
#bunny-save-btn,
#refresh-btn,
#quit-startup-btn { width: 100%; }
#sync-btn { display: none; width: 100%; }
#sync-status {
  font-size: 0.82em; color: #aaa; text-align: left; width: 100%;
  white-space: pre-wrap; display: none; user-select: text;
}
#sync-status.error { color: #ff6b6b; }
#sync-status.success { color: #6bcb77; }
#sync-confirm {
  display: none; flex-direction: column; gap: 8px; width: 100%;
}
#sync-confirm-msg { font-size: 0.85em; color: #e0e0e0; user-select: text; white-space: pre-wrap; }
#sync-confirm-btns { display: flex; gap: 8px; }
#sync-confirm-btns .btn { flex: 1; padding: 9px 12px; font-size: 0.88em; }

/* ── Bunny config form ─────────────────────────────── */
#bunny-config-form {
  display: flex; flex-direction: column; gap: 10px; width: 100%;
}
#bunny-config-form label { font-size: 0.85em; color: #aaa; }
#bunny-url-input {
  padding: 10px 14px; border-radius: 8px; border: 2px solid #2d2d50;
  background: #1a1a2e; color: #e0e0e0; font-size: 0.95em; width: 100%; outline: none;
}
#bunny-url-input:focus { border-color: #e8b430; }
#bunny-url-hint { font-size: 0.78em; color: #666; }
#bunny-configured {
  display: none; flex-direction: column; gap: 8px; width: 100%;
}
#bunny-cdn-display {
  font-size: 0.85em; color: #888; display: flex; justify-content: space-between;
  align-items: center; gap: 8px;
}
#bunny-cdn-display span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bunny-edit-btn {
  padding: 4px 10px; font-size: 0.8em; background: transparent;
  border: 1px solid #2d2d50; border-radius: 6px; color: #888; cursor: pointer;
  flex-shrink: 0;
}
#bunny-edit-btn:hover { color: #e0e0e0; border-color: #e0e0e0; }

#practice-view {
  display: flex; flex-direction: row; width: 100%; min-height: 100vh;
}
#right-panel {
  flex: 0 0 90px; background: #14142a; border-left: 2px solid #2d2d50;
  padding: 12px 8px; display: flex; flex-direction: column; overflow-y: auto;
}
#controls-col {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 6px; width: 100%; height: 100%;
}
#controls-col .btn {
  padding: 8px 14px; font-size: 0.9em; width: 100%; text-align: center;
}
#controls-col .btn .key { color: #e8b430; font-weight: 700; }
.btn.disabled, .btn:disabled {
  opacity: 0.35; cursor: not-allowed; pointer-events: none;
}
#speed-group {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  width: 100%;
}
#speed-display {
  display: block; width: 100%; text-align: center;
  font-weight: 600; font-size: 0.95em; padding: 4px 0;
}
.progress-display {
  pointer-events: none; cursor: default;
  background: #1e1e38; color: #888; font-size: 0.85em;
  margin-top: auto;
}
#image-canvas {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: #0d0d18; position: relative;
}
#image-canvas img {
  max-width: 100%; max-height: 100%; object-fit: contain;
}
#play-prompt {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  color: #666; font-size: 1.6em; letter-spacing: 0.03em;
  background: #0d0d18;
}
#play-prompt.visible { display: flex; }

/* ── Quiz Mode Layout ──────────────────────────────── */
#image-canvas.quiz-mode {
  flex-direction: column;
  align-items: stretch;
}
#image-canvas.quiz-mode #lick-image {
  flex: 0 0 66.666%;
  width: 100%;
  height: 66.666%;
  max-height: 66.666%;
  object-fit: contain;
}
#image-canvas.quiz-mode #play-prompt { display: none !important; }

/* Quiz answer area: hidden by default, flex column when active */
#quiz-answer-area {
  display: none;
  flex: 0 0 33.333%;
  width: 100%;
  height: 33.333%;
  padding: 4px;
}
#image-canvas.quiz-mode #quiz-answer-area { display: flex; }

/* Each button panel: hidden by default, grid when active */
.quiz-buttons {
  display: none;
  width: 100%;
  height: 100%;
  gap: 4px;
  grid-template-rows: 1fr 1fr;
}
.quiz-buttons.active { display: grid; }
#piano-buttons.active,
#interval-buttons.active    { grid-template-columns: repeat(14, 1fr); }
#fretNumber-buttons.active  { grid-template-columns: repeat(12, 1fr); grid-template-rows: 1fr; }

/* Quiz button base style */
.quiz-btn {
  background: #2d2d50;
  color: #e0e0e0;
  border: none;
  border-radius: 6px;
  font-size: clamp(1.1rem, 7vh, 2.2rem);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background 0.1s;
  touch-action: manipulation;
  user-select: none;
}
.quiz-btn:hover { background: #3d3d66; }
.quiz-btn:active { background: #4a4a78; }

/* Sharps / upper-row buttons: slightly darker tint */
.sharp-btn { background: #222240; }
.sharp-btn:hover { background: #2e2e58; }
.sharp-btn:active { background: #3a3a6a; }

/* Dot frets: slightly brighter to hint they're the "special" row */
.dot-btn { background: #363660; }
.dot-btn:hover { background: #424280; }

/* fretNumber non-dot frets (top-row origin) — light background */
#fretNumber-buttons .quiz-btn:not(.dot-btn)          { background: #ffffff; color: #1a1a1a; }
#fretNumber-buttons .quiz-btn:not(.dot-btn):hover     { background: #f0f0f0; }
#fretNumber-buttons .quiz-btn:not(.dot-btn):active    { background: #e0e0e0; }
#fretNumber-buttons .quiz-btn:not(.dot-btn) .key-hint { color: #7a5500; }

/* Piano natural keys (bottom row) — white, like a real piano */
#piano-buttons .quiz-btn:not(.sharp-btn)          { background: #ffffff; color: #1a1a1a; }
#piano-buttons .quiz-btn:not(.sharp-btn):hover     { background: #f0f0f0; }
#piano-buttons .quiz-btn:not(.sharp-btn):active    { background: #e0e0e0; }
#piano-buttons .quiz-btn:not(.sharp-btn) .key-hint { color: #7a5500; }

/* Interval major/perfect keys (bottom row) — white */
#interval-buttons .quiz-btn:not(.sharp-btn)          { background: #ffffff; color: #1a1a1a; }
#interval-buttons .quiz-btn:not(.sharp-btn):hover     { background: #f0f0f0; }
#interval-buttons .quiz-btn:not(.sharp-btn):active    { background: #e0e0e0; }
#interval-buttons .quiz-btn:not(.sharp-btn) .key-hint { color: #7a5500; }

/* Wrong answer highlight */
.quiz-btn.wrong-answer {
  background: #7a1a1a !important;
  color: #ffaaaa;
}

/* Keyboard hint label inside each button */
.key-hint {
  display: block;
  font-size: clamp(0.75rem, 2.8vh, 1.2rem);
  font-weight: 400;
  color: #e8b430;
  line-height: 1;
}

/* ── Utilities ─────────────────────────────────────────────── */
.accent { color: #e8b430; }

/* ── Lock scrolling in native fullscreen ───────────────────── */
html.view-practice:fullscreen,
html.view-practice:-webkit-full-screen {
  height: 100%;        /* Fix height chain so #practice-view fills the screen */
  overflow: hidden;
}

/* ── Hide fullscreen controls in PWA modes ──────────────────── */
.pwa-mode #screen-btn { display: none; }
.pwa-mode #startup-screen-btn { display: none; }
.pwa-mode #fullscreen-banner { display: none !important; }

/* ── Startup screen button ──────────────────────────────────── */
#startup-screen-btn { width: 100%; }

/* ── Fullscreen banner ──────────────────────────────────────── */
#fullscreen-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: #2d2d50;
  border-radius: 8px;
  font-size: 0.85em;
  color: #aaa;
}
#fullscreen-banner span { flex: 1; }
#fullscreen-skip-btn {
  padding: 4px 10px;
  font-size: 0.8em;
  background: transparent;
  border: 1px solid #555;
  border-radius: 6px;
  color: #888;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Install banner ─────────────────────────────────────────── */
#install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: #2d2d50;
  border-radius: 8px;
  font-size: 0.85em;
  color: #aaa;
}
#install-banner span { flex: 1; }
#install-dismiss-btn {
  padding: 4px 10px;
  font-size: 0.8em;
  background: transparent;
  border: 1px solid #555;
  border-radius: 6px;
  color: #888;
  cursor: pointer;
  flex-shrink: 0;
}
html.view-practice:fullscreen body,
html.view-practice:-webkit-full-screen body {
  overflow: hidden;
  height: 100%;
}
html.view-practice:fullscreen #practice-view,
html.view-practice:-webkit-full-screen #practice-view {
  min-height: 0;
  height: 100%;
}
