:root {
  --bg: #15120f;
  --surface: #211c17;
  --surface-2: #2c251e;
  --border: #3a3128;
  --text: #f1e9df;
  --muted: #a89a8a;
  --accent: #f0a030;
  --accent-text: #1b1206;
  --chord: #ffb547;
  --section: #7fc7a9;
  --danger: #e2574c;
  --radius: 10px;
  --cifra-font: clamp(13px, 3.6vw, 18px);
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

a {
  color: var(--accent);
}

h1,
h2 {
  margin: 0 0 0.25em;
  line-height: 1.2;
}

code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 0 4px;
  border-radius: 4px;
}

.muted {
  color: var(--muted);
}

.center {
  text-align: center;
}

.error {
  color: var(--danger);
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

[hidden] {
  display: none !important;
}

/* --- Formulários e botões ------------------------------------------------ */
input,
textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

input:focus,
textarea:focus,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.small {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 14px;
}

.btn.block {
  width: 100%;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Layout ------------------------------------------------------------- */
.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
}

.card.narrow {
  max-width: 380px;
  text-align: center;
}

.card.narrow label {
  text-align: left;
}

.logo {
  font-size: 28px;
}

.code-input {
  text-align: center;
  font-family: var(--mono);
  font-size: 28px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.footer-link {
  margin: 20px 0 0;
  font-size: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(21, 18, 15, 0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  padding: 0 6px;
}

.bar-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  padding: 0 4px;
}

.spacer {
  flex: 1;
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 14px 40vh;
}

.page.wide {
  max-width: 1400px;
  padding-bottom: 40px;
}

/* --- Lista de cifras ------------------------------------------------------ */
.search {
  margin-bottom: 12px;
}

.song-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.song-list a {
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.song-list a:hover {
  border-color: var(--accent);
}

.song-title {
  font-weight: 700;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

/* --- Cifra ---------------------------------------------------------------- */
.song-header {
  margin-bottom: 16px;
}

.song-header h1 {
  font-size: 24px;
}

.song-header p {
  margin: 0;
}

.transpose {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.transpose-label {
  font-size: 14px;
  color: var(--muted);
  margin-right: 2px;
}

.transpose .btn.small {
  min-width: 44px;
  min-height: 36px;
}

.transpose select {
  min-height: 36px;
  padding: 4px 8px;
  font: inherit;
  font-weight: 700;
  color: var(--chord);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.transpose select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.cifra {
  font-family: var(--mono);
  font-size: var(--cifra-font);
  line-height: 1.45;
  white-space: pre;
  overflow-x: auto;
}

.cifra .line {
  min-height: 1.45em;
}

.cifra .chord {
  color: var(--chord);
  font-weight: 700;
}

.cifra .section {
  color: var(--section);
  font-weight: 700;
}

.cifra .tab {
  color: var(--muted);
}

.status {
  text-align: center;
  padding: 24px 0;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.controller {
  background: var(--accent);
  color: var(--accent-text);
}

.follow {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

/* --- Painel ao vivo ------------------------------------------------------- */
.live-panel {
  position: fixed;
  z-index: 30;
  top: 64px;
  right: 10px;
  width: min(360px, calc(100vw - 20px));
  max-height: calc(100vh - 80px);
  overflow: auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.live-panel h2 {
  font-size: 18px;
  margin-bottom: 10px;
}

.live-panel .block {
  margin-top: 12px;
}

.code-box {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.code-label {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--muted);
}

.code {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  user-select: all;
}

.notice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e2574c;
  box-shadow: 0 0 0 3px rgba(226, 87, 76, 0.3);
}

/* --- Playback --------------------------------------------------------------- */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: rgba(33, 28, 23, 0.97);
  border-top: 1px solid var(--border);
}

.player .play {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  flex: none;
}

.player-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-label {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player input[type='range'] {
  width: 100%;
  margin: 0;
  padding: 0;
  height: 24px;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
}

.player-time {
  flex: none;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

.playback-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.playback-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.playback-row #audio-status {
  flex: 1;
  min-width: 180px;
  overflow-wrap: anywhere;
}

.playback-field progress {
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
}

/* --- Editor --------------------------------------------------------------- */
.editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fields {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr;
  gap: 10px;
}

.editor-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pane {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.pane-title {
  font-size: 14px;
  color: var(--muted);
}

.editor textarea {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.45;
  min-height: 65vh;
  resize: vertical;
  white-space: pre;
}

.preview {
  min-height: 65vh;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.hint {
  font-size: 14px;
  margin: 0;
}

@media (max-width: 760px) {
  .fields {
    grid-template-columns: 1fr 1fr;
  }
  .fields label:first-child {
    grid-column: 1 / -1;
  }
  .editor-panes {
    grid-template-columns: 1fr;
  }
  .editor textarea,
  .preview {
    min-height: 40vh;
  }
  .topbar .btn {
    padding: 8px 9px;
  }
}

/* --- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
