/* Vinyl Groove – estilos (variáveis de tema definidas em common.js) */
:root {
  --bg: #14110f; --surface: #211c18; --text: #f3ead9; --muted: #a59a88; --accent: #e8a33d; --on-accent: #1a1209;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --surface2: color-mix(in srgb, var(--text) 7%, var(--surface));
  --v-bg: #000; --v-text: #fff; --v-accent: #e8a33d; --v-title-font: Georgia, serif; --v-artist-font: system-ui, sans-serif;
  --v-diameter: 100; --v-spin: 6s; --v-groove: .4;
  --ok: #4cc27a; --bad: #e5594f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
svg.i { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.fill { fill: currentColor; stroke: none; }
.hidden { display: none !important; }

/* ---------- estrutura ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: .6rem; padding: calc(env(safe-area-inset-top) + .7rem) 1rem .6rem; }
.top .logo { width: 2rem; height: 2rem; }
.top h1 { font-size: 1.25rem; margin: 0; letter-spacing: .02em; flex: 1; }
.top h1 small { display: block; font-size: .7rem; color: var(--muted); font-weight: 400; letter-spacing: .08em; text-transform: uppercase; }
main#view { flex: 1; overflow-y: auto; padding: .25rem 1rem 1.25rem; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; background: none; border: 0; padding: .6rem .2rem .5rem; display: flex; flex-direction: column; align-items: center; gap: .15rem; font-size: .68rem; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--accent); }
.tabs svg.i { width: 1.5rem; height: 1.5rem; }
h2 { font-size: 1.05rem; margin: 1.1rem 0 .6rem; display: flex; align-items: center; gap: .5rem; }
h2 .grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* ---------- botões e campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; background: var(--surface2); border: 1px solid var(--line); border-radius: 999px; padding: .55rem 1rem; cursor: pointer; min-height: 2.5rem; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { background: none; border: 0; border-radius: 50%; width: 2.5rem; height: 2.5rem; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); flex: none; }
.icon-btn:active { background: var(--surface2); }
.icon-btn.accent { color: var(--accent); }
.icon-btn.danger { color: var(--bad); }
.field { display: block; margin: .6rem 0; }
.field > span { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }
.field input[type=text], .field input[type=search], .field select { width: 100%; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: .65rem .8rem; outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: .9rem; margin-bottom: .7rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.empty svg.i { width: 2.6rem; height: 2.6rem; opacity: .6; }
.badge { display: inline-block; font-size: .68rem; padding: .12rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.warn { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

/* ---------- lista de músicas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: .7rem; padding: .5rem .2rem; border-bottom: 1px solid var(--line); background: var(--bg); }
.item .thumb, .thumb { width: 3rem; height: 3rem; border-radius: 8px; object-fit: cover; background: var(--surface2); flex: none; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.item .meta { flex: 1; min-width: 0; cursor: pointer; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.now .t { color: var(--accent); }
.item.dragging { position: relative; z-index: 5; box-shadow: 0 8px 24px #0009; background: var(--surface); border-radius: 10px; opacity: .97; }
.drag { touch-action: none; cursor: grab; color: var(--muted); width: 2.2rem; height: 2.5rem; display: flex; align-items: center; justify-content: center; flex: none; user-select: none; -webkit-user-select: none; }
.progress { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; margin-top: .6rem; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- mini player ---------- */
.mini { display: flex; align-items: center; gap: .6rem; padding: .45rem .8rem; background: var(--surface); border-top: 1px solid var(--line); }
.mini .thumb { width: 2.6rem; height: 2.6rem; border-radius: 50%; overflow: hidden; animation: vg-rot 6s linear infinite; animation-play-state: paused; }
.mini.playing .thumb { animation-play-state: running; }
.mini .thumb img { width: 100%; height: 100%; object-fit: cover; }
.mini .meta { flex: 1; min-width: 0; }
.mini .t { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini .s { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- sheets / diálogos / toast ---------- */
.overlay { position: fixed; inset: 0; background: #000a; z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--surface); width: 100%; max-width: 760px; max-height: 92dvh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; animation: up .2s; padding-bottom: env(safe-area-inset-bottom); }
.sheet.full { height: 96dvh; max-height: none; }
.sheet header { display: flex; align-items: center; gap: .4rem; padding: .7rem .8rem .5rem 1.1rem; border-bottom: 1px solid var(--line); }
.sheet header h3 { margin: 0; flex: 1; font-size: 1.05rem; }
.sheet .body { overflow-y: auto; padding: .4rem 1.1rem 1rem; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet footer { padding: .7rem 1.1rem; display: flex; gap: .6rem; border-top: 1px solid var(--line); }
.sheet footer .btn { flex: 1; }
.center-box { align-items: center; padding: 1rem; }
.center-box .sheet { border-radius: 20px; max-width: 420px; animation: fade .15s; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 9rem); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 999px; z-index: 99; font-size: .9rem; box-shadow: 0 6px 20px #0008; max-width: 90vw; animation: fade .2s; }
.toast.err { background: var(--bad); color: #fff; }
.check { display: flex; align-items: center; gap: .7rem; padding: .7rem .2rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
.check .grow { flex: 1; min-width: 0; }

/* ---------- equipamentos ---------- */
.dev .head { display: flex; align-items: center; gap: .75rem; }
.dev .ico { width: 2.8rem; height: 2.8rem; border-radius: 12px; background: var(--surface2); display: flex; align-items: center; justify-content: center; position: relative; flex: none; }
.dev .ico svg.i { width: 1.5rem; height: 1.5rem; }
.dev .ico::after { content: ""; position: absolute; right: -3px; top: -3px; width: .8rem; height: .8rem; border-radius: 50%; background: var(--muted); border: 2px solid var(--surface); }
.dev.online .ico { color: var(--ok); }
.dev.online .ico::after { background: var(--ok); }
.dev .name { font-weight: 700; font-size: 1.05rem; }
.dev .id { font-family: ui-monospace, Menlo, monospace; font-size: .72rem; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 600; }
.status.on { color: var(--ok); } .status.off { color: var(--muted); }
.dev .info { margin-top: .6rem; font-size: .85rem; display: grid; gap: .25rem; }
.dev .info b { color: var(--muted); font-weight: 500; }
.remote-disc { width: min(58vw, 240px); aspect-ratio: 1; margin: .5rem auto 1rem; position: relative; }
.remote-ctrl { display: flex; justify-content: center; gap: .6rem; margin: .4rem 0 1rem; }
.remote-ctrl .icon-btn { width: 3.4rem; height: 3.4rem; background: var(--surface2); }
.remote-ctrl .icon-btn.big { background: var(--accent); color: var(--on-accent); }
.spin { animation: vg-rot 1s linear infinite; }
/* disco em miniatura (controlo remoto e pré-visualização do aspeto) */
.remote-disc .vg-stage, .preview .vg-stage { position: relative; inset: auto; width: 100%; height: 100%; background: transparent; z-index: 0; display: block; }
.remote-disc .vg-disc { --vd: min(58vw, 240px); }
.preview.remote-disc { width: 190px; height: 190px; margin: .4rem auto 1rem; }
.preview .vg-disc { --vd: 190px; }
.remote-disc .vg-info, .preview .vg-info { padding: 0 14%; }

/* ---------- aspeto ---------- */
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.colors label { display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: var(--surface2); border-radius: 10px; padding: .45rem .7rem; font-size: .85rem; }
.colors input[type=color] { width: 2.4rem; height: 1.8rem; border: 0; background: none; padding: 0; }
.range { display: flex; align-items: center; gap: .7rem; margin: .5rem 0; font-size: .85rem; }
.range input { flex: 1; accent-color: var(--accent); }
.range output { width: 3.4rem; text-align: right; color: var(--muted); }
.presets { display: flex; gap: .5rem; flex-wrap: wrap; }
.preview { width: 190px; margin: .4rem auto 1rem; }

/* ---------- setup / PIN ---------- */
.setup { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 1.5rem 1.1rem; max-width: 520px; margin: 0 auto; }
.setup .brand { text-align: center; margin-bottom: 1.6rem; }
.setup .brand svg { width: 5rem; height: 5rem; animation: vg-rot 8s linear infinite; }
.setup .brand h1 { margin: .4rem 0 0; font-size: 2rem; letter-spacing: .03em; }
.choice { display: flex; align-items: center; gap: 1rem; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1rem; margin-bottom: .7rem; cursor: pointer; }
.choice:active { border-color: var(--accent); }
.choice .ico { width: 3rem; height: 3rem; border-radius: 14px; background: var(--surface2); color: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.choice b { display: block; font-size: 1.05rem; }
.choice span { font-size: .82rem; color: var(--muted); }
.pin-dots { display: flex; justify-content: center; gap: .8rem; margin: 1rem 0; }
.pin-dots i { width: .9rem; height: .9rem; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-dots.shake { animation: shake .4s; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; max-width: 300px; margin: 0 auto; }
.keypad button { background: var(--surface); border: 1px solid var(--line); border-radius: 50%; aspect-ratio: 1; font-size: 1.5rem; cursor: pointer; }
.keypad button:active { background: var(--accent); color: var(--on-accent); }
.err { color: var(--bad); text-align: center; min-height: 1.4em; font-size: .9rem; }

/* ---------- MODO VINIL ---------- */
body.vinyl-body { background: var(--v-bg); color: var(--v-text); overflow: hidden; }
.vg-stage { position: fixed; inset: 0; background: var(--v-bg); display: grid; place-items: center; color: var(--v-text); z-index: 20; }
.vg-disc { --vd: calc(min(100vw, 100dvh) * var(--v-diameter) / 100); width: var(--vd); height: var(--vd); position: relative; border-radius: 50%; overflow: hidden; background: #0b0b0b; box-shadow: 0 0 0 calc(var(--vd) * .004) #000, 0 calc(var(--vd) * .02) calc(var(--vd) * .08) #000c; }
.vg-spin { position: absolute; inset: 0; border-radius: 50%; animation: vg-rot var(--v-spin) linear infinite; animation-play-state: paused; }
.vg-playing .vg-spin { animation-play-state: running; }
.vg-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.vg-nocover { width: 100%; height: 100%; background: radial-gradient(circle, var(--v-accent) 0 24%, #111 24.5% 100%); }
.vg-grooves { position: absolute; inset: 0; border-radius: 50%; opacity: var(--v-groove); pointer-events: none;
  background: repeating-radial-gradient(circle at center, transparent 0 .9%, rgba(0,0,0,.55) 1% 1.15%, transparent 1.3% 2.2%),
              conic-gradient(from 20deg, transparent 0 20%, rgba(255,255,255,.18) 25%, transparent 30% 70%, rgba(255,255,255,.18) 75%, transparent 80%); }
.vg-hole { position: absolute; left: 50%; top: 50%; width: calc(var(--vd) * .045); height: calc(var(--vd) * .045); transform: translate(-50%, -50%); border-radius: 50%; background: var(--v-bg); box-shadow: 0 0 0 calc(var(--vd) * .008) rgba(255,255,255,.35); }
.vg-scrim { position: absolute; inset: 0; border-radius: 50%; background: linear-gradient(to bottom, transparent 42%, color-mix(in srgb, var(--v-bg) 62%, transparent) 66%, color-mix(in srgb, var(--v-bg) 84%, transparent) 100%); pointer-events: none; }
.vg-info { position: absolute; left: 0; right: 0; top: 56%; bottom: 7%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 17%; gap: calc(var(--vd) * .012); text-shadow: 0 1px 6px color-mix(in srgb, var(--v-bg) 80%, transparent); }
.vg-title { font-family: var(--v-title-font); font-size: calc(var(--vd) * .058); font-weight: 700; line-height: 1.1; margin: 0; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.vg-artist { font-family: var(--v-artist-font); font-size: calc(var(--vd) * .037); color: var(--v-accent); margin: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vg-bar { width: 46%; height: calc(var(--vd) * .006); min-height: 2px; background: color-mix(in srgb, var(--v-text) 25%, transparent); border-radius: 3px; overflow: hidden; margin-top: calc(var(--vd) * .008); }
.vg-bar > i { display: block; height: 100%; width: 0; background: var(--v-accent); }
.vg-ctrl { display: flex; align-items: center; justify-content: center; gap: calc(var(--vd) * .03); margin-top: calc(var(--vd) * .012); }
.vg-ctrl button { width: calc(var(--vd) * .105); height: calc(var(--vd) * .105); border-radius: 50%; border: calc(var(--vd) * .003) solid color-mix(in srgb, var(--v-text) 40%, transparent); background: color-mix(in srgb, var(--v-bg) 55%, transparent); color: var(--v-text); display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; backdrop-filter: blur(3px); }
.vg-ctrl button svg.i { width: 48%; height: 48%; }
.vg-ctrl button.main { width: calc(var(--vd) * .13); height: calc(var(--vd) * .13); background: var(--v-accent); border-color: transparent; color: var(--v-bg); }
.vg-ctrl button:active { transform: scale(.92); }
.vg-corner { position: fixed; top: calc(env(safe-area-inset-top) + 6px); right: 6px; width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 0; background: rgba(0,0,0,.4); color: #fff; opacity: .55; display: flex; align-items: center; justify-content: center; z-index: 25; cursor: pointer; }
.vg-hotzone { position: fixed; top: 0; left: 0; width: 72px; height: 72px; z-index: 25; }
.vg-idle { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; gap: .3rem; padding: 0 20%; }
.vg-blocked, .vg-flash { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 1rem; background: #000d; color: #fff; text-align: center; padding: 2rem; font-family: var(--v-title-font); }
.vg-flash { white-space: pre-line; background: var(--v-accent); color: #111; font-size: 9vmin; font-weight: 700; animation: fade .2s; }
.vg-panel { color: var(--text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; font-size: .88rem; margin: .5rem 0 1rem; }
.kv b { color: var(--muted); font-weight: 500; }
.kv code { font-family: ui-monospace, Menlo, monospace; word-break: break-all; }

@keyframes vg-rot { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@media (prefers-reduced-motion: reduce) { .setup .brand svg { animation: none; } }
